kopia lustrzana https://github.com/nextcloud/social
error on too big document
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/53/head
rodzic
ffd70a71a6
commit
22c6cde699
|
@ -434,6 +434,13 @@
|
|||
<notnull>true</notnull>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>error</name>
|
||||
<type>integer</type>
|
||||
<length>1</length>
|
||||
<notnull>true</notnull>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>creation</name>
|
||||
<type>timestamp</type>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<name>Social</name>
|
||||
<summary>🎉 Nextcloud becomes part of the federated social networks!</summary>
|
||||
<description><![CDATA[test]]></description>
|
||||
<version>0.0.42</version>
|
||||
<version>0.0.43</version>
|
||||
<licence>agpl</licence>
|
||||
<author mail="maxence@artificial-owl.com">Maxence Lange</author>
|
||||
<author mail="jus@bitgrid.net">Julius Härtl</author>
|
||||
|
|
|
@ -80,6 +80,7 @@ class CacheDocumentsRequest extends CacheDocumentsRequestBuilder {
|
|||
$qb = $this->getCacheDocumentsUpdateSql();
|
||||
$this->limitToIdString($qb, $document->getId());
|
||||
$qb->set('local_copy', $qb->createNamedParameter($document->getLocalCopy()));
|
||||
$qb->set('error', $qb->createNamedParameter($document->getError()));
|
||||
|
||||
$qb->execute();
|
||||
}
|
||||
|
|
|
@ -31,8 +31,6 @@ namespace OCA\Social\Db;
|
|||
|
||||
|
||||
use daita\MySmallPhpTools\Traits\TArrayTools;
|
||||
use OCA\Social\Exceptions\SocialAppConfigException;
|
||||
use OCA\Social\Exceptions\UrlCloudException;
|
||||
use OCA\Social\Model\ActivityPub\Document;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
|
||||
|
@ -79,7 +77,7 @@ class CacheDocumentsRequestBuilder extends CoreRequestBuilder {
|
|||
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
||||
$qb->select(
|
||||
'cd.id', 'cd.type', 'cd.media_type', 'cd.mime_type', 'cd.url', 'cd.local_copy',
|
||||
'cd.public', 'cd.creation', 'cd.caching'
|
||||
'cd.public', 'cd.error', 'cd.creation', 'cd.caching'
|
||||
)
|
||||
->from(self::TABLE_CACHE_DOCUMENTS, 'cd');
|
||||
|
||||
|
|
|
@ -155,7 +155,6 @@ class CoreRequestBuilder {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Limit the request to the ActorId
|
||||
*
|
||||
|
@ -477,6 +476,8 @@ class CoreRequestBuilder {
|
|||
->selectAlias('cd.url', 'cachedocument_url')
|
||||
->selectAlias('cd.local_copy', 'cachedocument_local_copy')
|
||||
->selectAlias('cd.caching', 'cachedocument_caching')
|
||||
->selectAlias('cd.public', 'cachedocument_public')
|
||||
->selectAlias('cd.error', 'cachedocument_error')
|
||||
->selectAlias('ca.creation', 'cachedocument_creation')
|
||||
->leftJoin(
|
||||
$this->defaultSelectAlias, CoreRequestBuilder::TABLE_CACHE_DOCUMENTS, 'cd',
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class CacheContentSizeException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -61,6 +61,9 @@ class Document extends ACore implements JsonSerializable {
|
|||
/** @var bool */
|
||||
private $public = false;
|
||||
|
||||
/** @var int */
|
||||
private $error = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Document constructor.
|
||||
|
@ -150,6 +153,25 @@ class Document extends ACore implements JsonSerializable {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getError(): int {
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $error
|
||||
*
|
||||
* @return Document
|
||||
*/
|
||||
public function setError(int $error): Document {
|
||||
$this->error = $error;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
@ -192,6 +214,7 @@ class Document extends ACore implements JsonSerializable {
|
|||
parent::importFromDatabase($data);
|
||||
|
||||
$this->setPublic(($this->getInt('public', $data, 0) === 1) ? true : false);
|
||||
$this->setError($this->getInt('error', $data, 0));
|
||||
$this->setLocalCopy($this->get('local_copy', $data, ''));
|
||||
$this->setMediaType($this->get('media_type', $data, ''));
|
||||
$this->setMimeType($this->get('mime_type', $data, ''));
|
||||
|
|
|
@ -33,6 +33,7 @@ namespace OCA\Social\Service\ActivityPub;
|
|||
|
||||
use OCA\Social\Db\CacheDocumentsRequest;
|
||||
use OCA\Social\Exceptions\CacheContentException;
|
||||
use OCA\Social\Exceptions\CacheContentSizeException;
|
||||
use OCA\Social\Exceptions\CacheDocumentDoesNotExistException;
|
||||
use OCA\Social\Model\ActivityPub\ACore;
|
||||
use OCA\Social\Model\ActivityPub\Document;
|
||||
|
@ -99,6 +100,8 @@ class DocumentService implements ICoreService {
|
|||
$document->setMimeType($mime);
|
||||
$document->setLocalCopy($localCopy);
|
||||
$this->cacheDocumentsRequest->endCaching($document);
|
||||
} catch (CacheContentSizeException $e) {
|
||||
$this->cacheDocumentsRequest->endCaching($document);
|
||||
} catch (CacheContentException $e) {
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ namespace OCA\Social\Service;
|
|||
|
||||
use Exception;
|
||||
use OCA\Social\Exceptions\CacheContentException;
|
||||
use OCA\Social\Exceptions\CacheContentSizeException;
|
||||
use OCP\Files\IAppData;
|
||||
use OCP\Files\NotFoundException;
|
||||
use OCP\Files\NotPermittedException;
|
||||
|
@ -41,9 +42,15 @@ use OCP\Files\SimpleFS\ISimpleFile;
|
|||
class CacheService {
|
||||
|
||||
|
||||
const ERROR_MAX_SIZE = 1;
|
||||
|
||||
|
||||
/** @var IAppData */
|
||||
private $appData;
|
||||
|
||||
/** @var ConfigService */
|
||||
private $configService;
|
||||
|
||||
/** @var MiscService */
|
||||
private $miscService;
|
||||
|
||||
|
@ -52,10 +59,14 @@ class CacheService {
|
|||
* CacheService constructor.
|
||||
*
|
||||
* @param IAppData $appData
|
||||
* @param ConfigService $configService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(IAppData $appData, MiscService $miscService) {
|
||||
public function __construct(
|
||||
IAppData $appData, ConfigService $configService, MiscService $miscService
|
||||
) {
|
||||
$this->appData = $appData;
|
||||
$this->configService = $configService;
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
||||
|
@ -68,6 +79,7 @@ class CacheService {
|
|||
* @return string
|
||||
* @throws CacheContentException
|
||||
* @throws NotPermittedException
|
||||
* @throws CacheContentSizeException
|
||||
*/
|
||||
public function saveRemoteFileToCache(string $url, &$mime = '') {
|
||||
|
||||
|
@ -131,13 +143,26 @@ class CacheService {
|
|||
*
|
||||
* @return string
|
||||
* @throws CacheContentException
|
||||
* @throws CacheContentSizeException
|
||||
*/
|
||||
public function retrieveContent(string $url) {
|
||||
$content = file_get_contents($url);
|
||||
if ($content === false) {
|
||||
$maxSize =
|
||||
$this->configService->getAppValueInt(ConfigService::SOCIAL_MAX_SIZE) * 1024 * 1024;
|
||||
|
||||
$fd = fopen($url, "r");
|
||||
if ($fd === false) {
|
||||
throw new CacheContentException();
|
||||
}
|
||||
|
||||
$content = '';
|
||||
while (!feof($fd)) {
|
||||
$content .= fread($fd, 4096);
|
||||
if (strlen($content) > $maxSize) {
|
||||
throw new CacheContentSizeException();
|
||||
}
|
||||
}
|
||||
fclose($fd);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,10 +52,12 @@ class ConfigService {
|
|||
|
||||
|
||||
const SOCIAL_ADDRESS = 'address';
|
||||
const SOCIAL_MAX_SIZE = 'max_size';
|
||||
|
||||
/** @var array */
|
||||
public $defaults = [
|
||||
self::SOCIAL_ADDRESS => ''
|
||||
self::SOCIAL_ADDRESS => '',
|
||||
self::SOCIAL_MAX_SIZE => 25
|
||||
];
|
||||
|
||||
/** @var string */
|
||||
|
@ -111,6 +113,22 @@ class ConfigService {
|
|||
return $this->config->getAppValue(Application::APP_NAME, $key, $defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a value by key
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getAppValueInt(string $key): int {
|
||||
$defaultValue = null;
|
||||
if (array_key_exists($key, $this->defaults)) {
|
||||
$defaultValue = $this->defaults[$key];
|
||||
}
|
||||
|
||||
return (int)$this->config->getAppValue(Application::APP_NAME, $key, $defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a value by key
|
||||
*
|
||||
|
@ -248,6 +266,7 @@ class ConfigService {
|
|||
|
||||
/**
|
||||
* // TODO - check the Apps folder
|
||||
*
|
||||
* @return string
|
||||
* @throws SocialAppConfigException
|
||||
*/
|
||||
|
|
Ładowanie…
Reference in New Issue