Merge pull request #283 from nextcloud/code/noid/rewrite-exception-on-request

[huge] rewrite of the exceptions while requesting remote instance
alpha1
Julius Härtl 2019-01-02 23:31:23 +01:00 zatwierdzone przez GitHub
commit 6b74286bd0
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
45 zmienionych plików z 457 dodań i 293 usunięć

8
composer.lock wygenerowano
Wyświetl plik

@ -12,12 +12,12 @@
"source": {
"type": "git",
"url": "https://github.com/daita/my-small-php-tools.git",
"reference": "29754f18951856a22c0fd5fc388b6162ea98fe8a"
"reference": "0baac1f399b257b00fdc2eafb754396ffa1892f4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/29754f18951856a22c0fd5fc388b6162ea98fe8a",
"reference": "29754f18951856a22c0fd5fc388b6162ea98fe8a",
"url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/0baac1f399b257b00fdc2eafb754396ffa1892f4",
"reference": "0baac1f399b257b00fdc2eafb754396ffa1892f4",
"shasum": ""
},
"require": {
@ -40,7 +40,7 @@
}
],
"description": "My small PHP Tools",
"time": "2018-12-18T00:38:01+00:00"
"time": "2018-12-27T11:14:55+00:00"
},
{
"name": "digitalbazaar/json-ld",

Wyświetl plik

@ -34,7 +34,7 @@ namespace OCA\Social;
use daita\MySmallPhpTools\Traits\TArrayTools;
use OCA\Social\Exceptions\RedundancyLimitException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Interfaces\Activity\AcceptInterface;
use OCA\Social\Interfaces\Activity\AddInterface;
use OCA\Social\Interfaces\Activity\BlockInterface;
@ -174,7 +174,7 @@ class AP {
* @return ACore
* @throws RedundancyLimitException
* @throws SocialAppConfigException
* @throws UnknownItemException
* @throws ItemUnknownException
*/
public function getItemFromData(array $data, $parent = null, int $level = 0): ACore {
if (++$level > self::REDUNDANCY_LIMIT) {
@ -189,14 +189,14 @@ class AP {
try {
$object = $this->getItemFromData($this->getArray('object', $data, []), $item, $level);
$item->setObject($object);
} catch (UnknownItemException $e) {
} catch (ItemUnknownException $e) {
}
try {
/** @var Document $icon */
$icon = $this->getItemFromData($this->getArray('icon', $data, []), $item, $level);
$item->setIcon($icon);
} catch (UnknownItemException $e) {
} catch (ItemUnknownException $e) {
}
return $item;
@ -208,7 +208,7 @@ class AP {
*
* @return ACore
* @throws SocialAppConfigException
* @throws UnknownItemException
* @throws ItemUnknownException
*/
public function getSimpleItemFromData(array $data): Acore {
$item = $this->getItemFromType($this->get('type', $data, ''));
@ -223,7 +223,7 @@ class AP {
* @param string $type
*
* @return ACore
* @throws UnknownItemException
* @throws ItemUnknownException
*/
public function getItemFromType(string $type) {
switch ($type) {
@ -273,7 +273,7 @@ class AP {
return new Update();
default:
throw new UnknownItemException();
throw new ItemUnknownException();
}
}
@ -282,7 +282,7 @@ class AP {
* @param ACore $activity
*
* @return IActivityPubInterface
* @throws UnknownItemException
* @throws ItemUnknownException
*/
public function getInterfaceForItem(Acore $activity): IActivityPubInterface {
return $this->getInterfaceFromType($activity->getType());
@ -293,7 +293,7 @@ class AP {
* @param string $type
*
* @return IActivityPubInterface
* @throws UnknownItemException
* @throws ItemUnknownException
*/
public function getInterfaceFromType(string $type): IActivityPubInterface {
switch ($type) {
@ -350,7 +350,7 @@ class AP {
break;
default:
throw new UnknownItemException();
throw new ItemUnknownException();
}
return $service;

Wyświetl plik

@ -32,7 +32,6 @@ namespace OCA\Social\Command;
use OC\Core\Command\Base;
use OCA\Social\Exceptions\RequestException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Service\ActivityService;
use OCA\Social\Service\ConfigService;
@ -113,7 +112,6 @@ class QueueProcess extends Base {
$output->write('.');
try {
$this->activityService->manageRequest($request);
} catch (RequestException $e) {
} catch (SocialAppConfigException $e) {
}
}

Wyświetl plik

@ -35,7 +35,8 @@ use Exception;
use OC\AppFramework\Http;
use OCA\Social\AppInfo\Application;
use OCA\Social\Exceptions\SignatureIsGoneException;
use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Exceptions\UrlCloudException;
use OCA\Social\Service\CacheActorService;
use OCA\Social\Service\FollowService;
use OCA\Social\Service\ImportService;
@ -112,6 +113,7 @@ class ActivityPubController extends Controller {
* @param string $username
*
* @return Response
* @throws UrlCloudException
*/
public function actor(string $username): Response {
if (!$this->checkSourceActivityStreams()) {
@ -143,6 +145,7 @@ class ActivityPubController extends Controller {
* @param string $username
*
* @return Response
* @throws UrlCloudException
*/
public function actorAlias(string $username): Response {
return $this->actor($username);
@ -172,7 +175,7 @@ class ActivityPubController extends Controller {
try {
$this->importService->parseIncomingRequest($activity);
} catch (UnknownItemException $e) {
} catch (ItemUnknownException $e) {
}
return $this->success([]);
@ -213,7 +216,7 @@ class ActivityPubController extends Controller {
try {
$this->importService->parseIncomingRequest($activity);
} catch (UnknownItemException $e) {
} catch (ItemUnknownException $e) {
}
return $this->success([]);
@ -249,6 +252,7 @@ class ActivityPubController extends Controller {
* @param string $username
*
* @return Response
* @throws UrlCloudException
*/
public function followers(string $username): Response {
@ -278,6 +282,7 @@ class ActivityPubController extends Controller {
* @param string $username
*
* @return Response
* @throws UrlCloudException
*/
public function following(string $username): Response {
if (!$this->checkSourceActivityStreams()) {

Wyświetl plik

@ -32,7 +32,6 @@ namespace OCA\Social\Controller;
use daita\MySmallPhpTools\Traits\TAsync;
use OCA\Social\AppInfo\Application;
use OCA\Social\Exceptions\RequestException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Model\RequestQueue;
use OCA\Social\Service\ActivityService;
@ -99,7 +98,6 @@ class QueueController extends Controller {
$request->setTimeout(ActivityService::TIMEOUT_ASYNC);
try {
$this->activityService->manageRequest($request);
} catch (RequestException $e) {
} catch (SocialAppConfigException $e) {
}
}

Wyświetl plik

@ -34,6 +34,7 @@ use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse;
use OCA\Social\AppInfo\Application;
use OCA\Social\Exceptions\CacheActorDoesNotExistException;
use OCA\Social\Exceptions\UrlCloudException;
use OCA\Social\Service\AccountService;
use OCA\Social\Service\CacheActorService;
use OCA\Social\Service\FollowService;
@ -117,6 +118,7 @@ class SocialPubController extends Controller {
$page = new PublicTemplateResponse(Application::APP_NAME, 'main', $data);
$page->setStatus($status);
$page->setHeaderTitle($this->l10n->t('Social'));
return $page;
}
@ -131,6 +133,7 @@ class SocialPubController extends Controller {
* @param string $username
*
* @return Response
* @throws UrlCloudException
*/
public function actor(string $username): Response {
return $this->renderPage($username);
@ -147,6 +150,7 @@ class SocialPubController extends Controller {
* @param string $username
*
* @return TemplateResponse
* @throws UrlCloudException
*/
public function followers(string $username): Response {
return $this->renderPage($username);
@ -163,6 +167,7 @@ class SocialPubController extends Controller {
* @param string $username
*
* @return TemplateResponse
* @throws UrlCloudException
*/
public function following(string $username): Response {
return $this->renderPage($username);

Wyświetl plik

@ -33,7 +33,6 @@ namespace OCA\Social\Cron;
use OC\BackgroundJob\TimedJob;
use OCA\Social\AppInfo\Application;
use OCA\Social\Exceptions\RequestException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Service\ActivityService;
use OCA\Social\Service\MiscService;
@ -94,7 +93,6 @@ class Queue extends TimedJob {
$request->setTimeout(ActivityService::TIMEOUT_SERVICE);
try {
$this->activityService->manageRequest($request);
} catch (RequestException $e) {
} catch (SocialAppConfigException $e) {
}
}

Wyświetl plik

@ -173,5 +173,16 @@ class CacheDocumentsRequest extends CacheDocumentsRequestBuilder {
$qb->execute();
}
/**
* @param string $id
*/
public function deleteById(string $id) {
$qb = $this->getCacheDocumentsDeleteSql();
$this->limitToIdString($qb, $id);
$qb->execute();
}
}

Wyświetl plik

@ -32,7 +32,6 @@ namespace OCA\Social\Db;
use DateTime;
use Exception;
use OCA\Social\Exceptions\QueueStatusException;
use OCA\Social\Model\RequestQueue;
use OCP\DB\QueryBuilder\IQueryBuilder;
@ -50,8 +49,6 @@ class RequestQueueRequest extends RequestQueueRequestBuilder {
* create a new Queue in the database.
*
* @param RequestQueue[] $queues
*
* @throws Exception
*/
public function multiple(array $queues) {
foreach ($queues as $queue) {
@ -64,8 +61,6 @@ class RequestQueueRequest extends RequestQueueRequestBuilder {
* create a new Queue in the database.
*
* @param RequestQueue $queue
*
* @throws Exception
*/
public function create(RequestQueue $queue) {
$qb = $this->getQueueInsertSql();

Wyświetl plik

@ -1,8 +0,0 @@
<?php
namespace OCA\Social\Exceptions;
class CacheContentSizeException extends \Exception {
}

Wyświetl plik

@ -0,0 +1,8 @@
<?php
namespace OCA\Social\Exceptions;
class ItemUnknownException extends \Exception {
}

Wyświetl plik

@ -1,8 +0,0 @@
<?php
namespace OCA\Social\Exceptions;
class Request410Exception extends \Exception {
}

Wyświetl plik

@ -0,0 +1,8 @@
<?php
namespace OCA\Social\Exceptions;
class RequestContentException extends \Exception {
}

Wyświetl plik

@ -1,8 +0,0 @@
<?php
namespace OCA\Social\Exceptions;
class RequestException extends \Exception {
}

Wyświetl plik

@ -0,0 +1,8 @@
<?php
namespace OCA\Social\Exceptions;
class RequestNetworkException extends \Exception {
}

Wyświetl plik

@ -0,0 +1,8 @@
<?php
namespace OCA\Social\Exceptions;
class RequestResultSizeException extends \Exception {
}

Wyświetl plik

@ -0,0 +1,8 @@
<?php
namespace OCA\Social\Exceptions;
class RequestServerException extends \Exception {
}

Wyświetl plik

@ -0,0 +1,8 @@
<?php
namespace OCA\Social\Exceptions;
class RetrieveAccountFormatException extends \Exception {
}

Wyświetl plik

@ -1,8 +0,0 @@
<?php
namespace OCA\Social\Exceptions;
class ServiceAccountAlreadyExistException extends \Exception {
}

Wyświetl plik

@ -1,8 +0,0 @@
<?php
namespace OCA\Social\Exceptions;
class UnknownItemException extends \Exception {
}

Wyświetl plik

@ -1,8 +0,0 @@
<?php
namespace OCA\Social\Exceptions;
class WebfingerException extends \Exception {
}

Wyświetl plik

@ -33,7 +33,7 @@ namespace OCA\Social\Interfaces\Activity;
use OCA\Social\AP;
use OCA\Social\Exceptions\ItemNotFoundException;
use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Interfaces\IActivityPubInterface;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Service\MiscService;
@ -68,7 +68,7 @@ class AcceptInterface implements IActivityPubInterface {
try {
$service = AP::$activityPub->getInterfaceForItem($item->getObject());
$service->activity($item, $object);
} catch (UnknownItemException $e) {
} catch (ItemUnknownException $e) {
}
}

Wyświetl plik

@ -33,7 +33,7 @@ namespace OCA\Social\Interfaces\Activity;
use OCA\Social\AP;
use OCA\Social\Exceptions\ItemNotFoundException;
use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Interfaces\IActivityPubInterface;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Service\MiscService;
@ -68,7 +68,7 @@ class AddInterface implements IActivityPubInterface {
try {
$service = AP::$activityPub->getInterfaceForItem($item->getObject());
$service->activity($item, $object);
} catch (UnknownItemException $e) {
} catch (ItemUnknownException $e) {
}
}

Wyświetl plik

@ -33,7 +33,7 @@ namespace OCA\Social\Interfaces\Activity;
use OCA\Social\AP;
use OCA\Social\Exceptions\ItemNotFoundException;
use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Interfaces\IActivityPubInterface;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Service\MiscService;
@ -68,7 +68,7 @@ class BlockInterface implements IActivityPubInterface {
try {
$service = AP::$activityPub->getInterfaceForItem($item->getObject());
$service->activity($item, $object);
} catch (UnknownItemException $e) {
} catch (ItemUnknownException $e) {
}
}

Wyświetl plik

@ -33,7 +33,7 @@ namespace OCA\Social\Interfaces\Activity;
use OCA\Social\AP;
use OCA\Social\Exceptions\ItemNotFoundException;
use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Interfaces\IActivityPubInterface;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Service\MiscService;
@ -68,7 +68,7 @@ class CreateInterface implements IActivityPubInterface {
try {
$service = AP::$activityPub->getInterfaceForItem($item->getObject());
$service->activity($item, $object);
} catch (UnknownItemException $e) {
} catch (ItemUnknownException $e) {
}
}

Wyświetl plik

@ -34,7 +34,7 @@ namespace OCA\Social\Interfaces\Activity;
use OCA\Social\AP;
use OCA\Social\Exceptions\InvalidOriginException;
use OCA\Social\Exceptions\ItemNotFoundException;
use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Interfaces\IActivityPubInterface;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Service\MiscService;
@ -90,7 +90,7 @@ class DeleteInterface implements IActivityPubInterface {
try {
$interface = AP::$activityPub->getInterfaceForItem($object);
$interface->delete($object);
} catch (UnknownItemException $e) {
} catch (ItemUnknownException $e) {
}
}

Wyświetl plik

@ -39,10 +39,12 @@ use OCA\Social\Exceptions\InvalidOriginException;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\ItemNotFoundException;
use OCA\Social\Exceptions\RedundancyLimitException;
use OCA\Social\Exceptions\Request410Exception;
use OCA\Social\Exceptions\RequestException;
use OCA\Social\Exceptions\RequestContentException;
use OCA\Social\Exceptions\RequestNetworkException;
use OCA\Social\Exceptions\RequestResultSizeException;
use OCA\Social\Exceptions\RequestServerException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Interfaces\IActivityPubInterface;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Activity\Accept;
@ -138,11 +140,13 @@ class FollowInterface implements IActivityPubInterface {
* @throws InvalidOriginException
* @throws InvalidResourceException
* @throws MalformedArrayException
* @throws Request410Exception
* @throws RequestException
* @throws SocialAppConfigException
* @throws RedundancyLimitException
* @throws UnknownItemException
* @throws SocialAppConfigException
* @throws ItemUnknownException
* @throws RequestContentException
* @throws RequestNetworkException
* @throws RequestResultSizeException
* @throws RequestServerException
*/
public function processIncomingRequest(ACore $follow) {
/** @var Follow $follow */

Wyświetl plik

@ -33,7 +33,7 @@ namespace OCA\Social\Interfaces\Activity;
use OCA\Social\AP;
use OCA\Social\Exceptions\ItemNotFoundException;
use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Interfaces\IActivityPubInterface;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Service\MiscService;
@ -68,7 +68,7 @@ class LikeInterface implements IActivityPubInterface {
try {
$service = AP::$activityPub->getInterfaceForItem($item->getObject());
$service->activity($item, $object);
} catch (UnknownItemException $e) {
} catch (ItemUnknownException $e) {
}
}

Wyświetl plik

@ -33,7 +33,7 @@ namespace OCA\Social\Interfaces\Activity;
use OCA\Social\AP;
use OCA\Social\Exceptions\ItemNotFoundException;
use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Interfaces\IActivityPubInterface;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Service\MiscService;
@ -68,7 +68,7 @@ class RejectInterface implements IActivityPubInterface {
try {
$service = AP::$activityPub->getInterfaceForItem($item->getObject());
$service->activity($item, $object);
} catch (UnknownItemException $e) {
} catch (ItemUnknownException $e) {
}
}

Wyświetl plik

@ -33,7 +33,7 @@ namespace OCA\Social\Interfaces\Activity;
use OCA\Social\AP;
use OCA\Social\Exceptions\ItemNotFoundException;
use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Interfaces\IActivityPubInterface;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Service\MiscService;
@ -68,7 +68,7 @@ class RemoveInterface implements IActivityPubInterface {
try {
$service = AP::$activityPub->getInterfaceForItem($item->getObject());
$service->activity($item, $object);
} catch (UnknownItemException $e) {
} catch (ItemUnknownException $e) {
}
}

Wyświetl plik

@ -33,7 +33,7 @@ namespace OCA\Social\Interfaces\Activity;
use OCA\Social\AP;
use OCA\Social\Exceptions\ItemNotFoundException;
use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Interfaces\IActivityPubInterface;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Service\MiscService;
@ -69,7 +69,7 @@ class UndoInterface implements IActivityPubInterface {
try {
$interface = AP::$activityPub->getInterfaceForItem($item->getObject());
$interface->activity($item, $object);
} catch (UnknownItemException $e) {
} catch (ItemUnknownException $e) {
}
}

Wyświetl plik

@ -33,7 +33,7 @@ namespace OCA\Social\Interfaces\Activity;
use OCA\Social\AP;
use OCA\Social\Exceptions\ItemNotFoundException;
use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Interfaces\IActivityPubInterface;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Service\MiscService;
@ -68,7 +68,7 @@ class UpdateInterface implements IActivityPubInterface {
try {
$service = AP::$activityPub->getInterfaceForItem($item->getObject());
$service->activity($item, $object);
} catch (UnknownItemException $e) {
} catch (ItemUnknownException $e) {
}
}

Wyświetl plik

@ -32,7 +32,6 @@ namespace OCA\Social\Model\ActivityPub\Actor;
use JsonSerializable;
use OCA\Social\Exceptions\InvalidResourceEntryException;
use OCA\Social\Exceptions\UrlCloudException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Object\Image;

Wyświetl plik

@ -32,7 +32,6 @@ namespace OCA\Social\Model\ActivityPub\Object;
use JsonSerializable;
use OCA\Social\Exceptions\InvalidResourceEntryException;
use OCA\Social\Exceptions\UrlCloudException;
use OCA\Social\Model\ActivityPub\ACore;

Wyświetl plik

@ -41,10 +41,12 @@ use OCA\Social\Exceptions\EmptyQueueException;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\NoHighPriorityRequestException;
use OCA\Social\Exceptions\QueueStatusException;
use OCA\Social\Exceptions\Request410Exception;
use OCA\Social\Exceptions\RequestException;
use OCA\Social\Exceptions\RequestContentException;
use OCA\Social\Exceptions\RequestNetworkException;
use OCA\Social\Exceptions\RequestResultSizeException;
use OCA\Social\Exceptions\RequestServerException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Activity\Create;
use OCA\Social\Model\ActivityPub\Activity\Delete;
@ -207,7 +209,7 @@ class ActivityService {
* @param ACore $activity
*
* @return string
* @throws Exception
* @throws SocialAppConfigException
*/
public function request(ACore $activity): string {
$this->saveActivity($activity);
@ -221,7 +223,6 @@ class ActivityService {
$directRequest = $this->queueService->getPriorityRequest($token);
$directRequest->setTimeout(self::TIMEOUT_LIVE);
$this->manageRequest($directRequest);
} catch (RequestException $e) {
} catch (NoHighPriorityRequestException $e) {
} catch (EmptyQueueException $e) {
return '';
@ -244,14 +245,13 @@ class ActivityService {
/**
* @param RequestQueue $queue
*
* @throws RequestException
* @throws SocialAppConfigException
*/
public function manageRequest(RequestQueue $queue) {
$host = $queue->getInstance()
->getAddress();
if (in_array($host, $this->failInstances)) {
throw new RequestException();
return;
}
try {
@ -260,27 +260,40 @@ class ActivityService {
return;
}
$request = $this->generateRequestFromQueue($queue);
try {
$result = $this->generateRequestFromQueue($queue);
$this->signatureService->signRequest($request, $queue);
$this->curlService->request($request);
$this->queueService->endRequest($queue, true);
} catch (ActorDoesNotExistException $e) {
$this->miscService->log(
'Error while managing request: ' . json_encode($request) . ' ' . json_encode($e), 1
);
$this->queueService->deleteRequest($queue);
return;
} catch (Request410Exception $e) {
} catch (RequestContentException $e) {
$this->miscService->log(
'Error while managing request: ' . json_encode($request) . ' ' . json_encode($e), 1
);
$this->queueService->deleteRequest($queue);
return;
}
try {
$accepted = [200, 202];
if (in_array($this->getint('_code', $result, 500), $accepted)) {
$this->queueService->endRequest($queue, true);
} else {
$this->queueService->endRequest($queue, false);
$this->failInstances[] = $host;
}
} catch (QueueStatusException $e) {
} catch (RequestResultSizeException $e) {
$this->miscService->log(
'Error while managing request: ' . json_encode($request) . ' ' . json_encode($e), 1
);
$this->queueService->deleteRequest($queue);
} catch (RequestServerException $e) {
$this->miscService->log(
'Temporary error while managing request: ' . json_encode($request) . ' '
. json_encode($e), 1
);
$this->queueService->endRequest($queue, false);
$this->failInstances[] = $host;
} catch (RequestNetworkException $e) {
$this->miscService->log(
'Temporary error while managing request: ' . json_encode($e), 1
);
$this->queueService->endRequest($queue, false);
$this->failInstances[] = $host;
}
}
@ -345,13 +358,9 @@ class ActivityService {
/**
* @param RequestQueue $queue
*
* @return Request[]
* @throws ActorDoesNotExistException
* @throws Request410Exception
* @throws RequestException
* @throws SocialAppConfigException
* @return Request
*/
public function generateRequestFromQueue(RequestQueue $queue): array {
private function generateRequestFromQueue(RequestQueue $queue): Request {
$path = $queue->getInstance();
$requestType = Request::TYPE_GET;
@ -366,9 +375,7 @@ class ActivityService {
$request->setDataJson($queue->getActivity());
$request->setAddress($path->getAddress());
$this->signatureService->signRequest($request, $queue);
return $this->curlService->request($request);
return $request;
}
@ -412,7 +419,7 @@ class ActivityService {
$service = AP::$activityPub->getInterfaceForItem($activity);
$service->save($activity);
} catch (UnknownItemException $e) {
} catch (ItemUnknownException $e) {
}
}

Wyświetl plik

@ -39,10 +39,13 @@ use OCA\Social\Exceptions\CacheActorDoesNotExistException;
use OCA\Social\Exceptions\InvalidOriginException;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\RedundancyLimitException;
use OCA\Social\Exceptions\Request410Exception;
use OCA\Social\Exceptions\RequestException;
use OCA\Social\Exceptions\RequestContentException;
use OCA\Social\Exceptions\RetrieveAccountFormatException;
use OCA\Social\Exceptions\RequestNetworkException;
use OCA\Social\Exceptions\RequestResultSizeException;
use OCA\Social\Exceptions\RequestServerException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Model\ActivityPub\Actor\Person;
@ -107,14 +110,16 @@ class CacheActorService {
* @param bool $refresh
*
* @return Person
* @throws InvalidOriginException
* @throws InvalidResourceException
* @throws MalformedArrayException
* @throws Request410Exception
* @throws RequestException
* @throws SocialAppConfigException
* @throws RedundancyLimitException
* @throws UnknownItemException
* @throws InvalidOriginException
* @throws RequestContentException
* @throws RequestNetworkException
* @throws RequestResultSizeException
* @throws RequestServerException
* @throws SocialAppConfigException
* @throws ItemUnknownException
*/
public function getFromId(string $id, bool $refresh = false): Person {
@ -173,14 +178,17 @@ class CacheActorService {
*
* @return Person
* @throws CacheActorDoesNotExistException
* @throws InvalidOriginException
* @throws InvalidResourceException
* @throws MalformedArrayException
* @throws RedundancyLimitException
* @throws Request410Exception
* @throws RequestException
* @throws RequestContentException
* @throws RetrieveAccountFormatException
* @throws RequestNetworkException
* @throws RequestResultSizeException
* @throws RequestServerException
* @throws SocialAppConfigException
* @throws UnknownItemException
* @throws InvalidOriginException
* @throws ItemUnknownException
*/
public function getFromAccount(string $account, bool $retrieve = true): Person {
@ -258,7 +266,7 @@ class CacheActorService {
try {
$interface = AP::$activityPub->getInterfaceFromType(Person::TYPE);
$interface->save($actor);
} catch (UnknownItemException $e) {
} catch (ItemUnknownException $e) {
}
}
}

Wyświetl plik

@ -30,11 +30,17 @@ declare(strict_types=1);
namespace OCA\Social\Service;
use daita\MySmallPhpTools\Exceptions\MalformedArrayException;
use daita\MySmallPhpTools\Model\Request;
use daita\MySmallPhpTools\Traits\TArrayTools;
use Exception;
use OCA\Social\Exceptions\CacheContentException;
use OCA\Social\Exceptions\CacheContentMimeTypeException;
use OCA\Social\Exceptions\CacheContentSizeException;
use OCA\Social\Exceptions\CacheDocumentDoesNotExistException;
use OCA\Social\Exceptions\RequestContentException;
use OCA\Social\Exceptions\RequestNetworkException;
use OCA\Social\Exceptions\RequestResultSizeException;
use OCA\Social\Exceptions\RequestServerException;
use OCP\Files\IAppData;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
@ -44,12 +50,15 @@ use OCP\Files\SimpleFS\ISimpleFile;
class CacheDocumentService {
const ERROR_MAX_SIZE = 1;
use TArrayTools;
/** @var IAppData */
private $appData;
/** @var CurlService */
private $curlService;
/** @var ConfigService */
private $configService;
@ -61,13 +70,16 @@ class CacheDocumentService {
* CacheService constructor.
*
* @param IAppData $appData
* @param CurlService $curlService
* @param ConfigService $configService
* @param MiscService $miscService
*/
public function __construct(
IAppData $appData, ConfigService $configService, MiscService $miscService
IAppData $appData, CurlService $curlService, ConfigService $configService,
MiscService $miscService
) {
$this->appData = $appData;
$this->curlService = $curlService;
$this->configService = $configService;
$this->miscService = $miscService;
}
@ -79,10 +91,13 @@ class CacheDocumentService {
* @param string $mime
*
* @return string
* @throws CacheContentException
* @throws NotPermittedException
* @throws CacheContentSizeException
* @throws CacheContentMimeTypeException
* @throws MalformedArrayException
* @throws NotPermittedException
* @throws RequestContentException
* @throws RequestNetworkException
* @throws RequestServerException
* @throws RequestResultSizeException
*/
public function saveRemoteFileToCache(string $url, &$mime = '') {
@ -171,29 +186,22 @@ class CacheDocumentService {
* @param string $url
*
* @return string
* @throws CacheContentException
* @throws CacheContentSizeException
* @throws MalformedArrayException
* @throws RequestContentException
* @throws RequestNetworkException
* @throws RequestServerException
* @throws RequestResultSizeException
*/
public function retrieveContent(string $url) {
$maxSize =
$this->configService->getAppValueInt(ConfigService::SOCIAL_MAX_SIZE) * 1024 * 1024;
$url = parse_url($url);
$this->mustContains(['path', 'host'], $url);
$request = new Request($url['path'], Request::TYPE_GET, true);
$request->setAddress($url['host']);
$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);
$content = $this->curlService->request($request);
return $content;
}
}

Wyświetl plik

@ -64,7 +64,7 @@ class ConfigService {
public $defaults = [
self::SOCIAL_ADDRESS => '',
self::SOCIAL_SERVICE => 1,
self::SOCIAL_MAX_SIZE => 25
self::SOCIAL_MAX_SIZE => 10
];
/** @var string */

Wyświetl plik

@ -40,10 +40,13 @@ use OCA\Social\AP;
use OCA\Social\Exceptions\InvalidOriginException;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\RedundancyLimitException;
use OCA\Social\Exceptions\Request410Exception;
use OCA\Social\Exceptions\RequestException;
use OCA\Social\Exceptions\RequestContentException;
use OCA\Social\Exceptions\RetrieveAccountFormatException;
use OCA\Social\Exceptions\RequestNetworkException;
use OCA\Social\Exceptions\RequestResultSizeException;
use OCA\Social\Exceptions\RequestServerException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Model\ActivityPub\Actor\Person;
class CurlService {
@ -64,6 +67,13 @@ class CurlService {
private $miscService;
/** @var int */
private $maxDownloadSize = 0;
/** @var bool */
private $maxDownloadSizeReached = false;
/**
* CurlService constructor.
*
@ -80,14 +90,17 @@ class CurlService {
* @param string $account
*
* @return Person
* @throws InvalidOriginException
* @throws InvalidResourceException
* @throws MalformedArrayException
* @throws Request410Exception
* @throws RequestException
* @throws SocialAppConfigException
* @throws RedundancyLimitException
* @throws UnknownItemException
* @throws InvalidOriginException
* @throws RequestContentException
* @throws RetrieveAccountFormatException
* @throws RequestNetworkException
* @throws RequestResultSizeException
* @throws RequestServerException
* @throws SocialAppConfigException
* @throws ItemUnknownException
*/
public function retrieveAccount(string $account): Person {
$account = $this->withoutBeginAt($account);
@ -110,7 +123,7 @@ class CurlService {
try {
$link = $this->extractArray('rel', 'self', $this->getArray('links', $result));
} catch (ArrayNotFoundException $e) {
throw new RequestException();
throw new RetrieveAccountFormatException();
}
$id = $this->get('href', $link, '');
@ -119,7 +132,7 @@ class CurlService {
/** @var Person $actor */
$actor = AP::$activityPub->getItemFromData($data);
if ($actor->getType() !== Person::TYPE) {
throw new UnknownItemException();
throw new ItemUnknownException();
}
if (strtolower($actor->getId()) !== strtolower($id)) {
@ -135,8 +148,10 @@ class CurlService {
*
* @return array
* @throws MalformedArrayException
* @throws Request410Exception
* @throws RequestException
* @throws RequestContentException
* @throws RequestNetworkException
* @throws RequestServerException
* @throws RequestResultSizeException
*/
public function retrieveObject($id): array {
@ -147,7 +162,7 @@ class CurlService {
$result = $this->request($request);
if (is_array($result)) {
$result['_host'] = $url['host'];
$result['_host'] = $request->getAddress();
}
return $result;
@ -157,12 +172,15 @@ class CurlService {
/**
* @param Request $request
*
* @return array
* @throws RequestException
* @throws Request410Exception
* @return mixed
* @throws RequestContentException
* @throws RequestNetworkException
* @throws RequestResultSizeException
* @throws RequestServerException
*/
public function request(Request $request): array {
public function request(Request $request) {
$this->maxDownloadSizeReached = false;
$curl = $this->initRequest($request);
$this->initRequestPost($curl, $request);
@ -170,33 +188,23 @@ class CurlService {
$this->initRequestDelete($curl, $request);
$result = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$this->parseRequestResultCode301($code);
// $this->parseRequestResultCode401($code);
$this->parseRequestResultCode404($code, $request);
$this->parseRequestResultCode410($code);
// $this->parseRequestResultCode503($code);
// $this->parseRequestResultCode500($code);
// $this->parseRequestResult($result);
if ($this->maxDownloadSizeReached === true) {
throw new RequestResultSizeException();
}
$this->parseRequestResult($curl, $request);
$ret = json_decode((string)$result, true);
// if ($ret === null) {
// throw new RequestException('500 Internal server error - could not parse JSON response');
// }
if (!is_array($ret)) {
$ret = ['_result' => $result];
if ($request->isBinary()) {
$this->miscService->log('[>>] request (binary): ' . json_encode($request), 1);
return $result;
}
$ret['_address'] = $request->getAddress();
$ret['_path'] = $request->getUrl();
$ret['_code'] = $code;
$this->miscService->log(
'[>>] request: ' . json_encode($request) . ' - result: ' . json_encode($ret), 1
'[>>] request: ' . json_encode($request) . ' - result: ' . $result, 1
);
return $ret;
return json_decode((string)$result, true);
}
@ -229,6 +237,10 @@ class CurlService {
try {
$this->request($request);
} catch (Exception $e) {
$this->miscService->log(
'Cannot initiate AsyncWithToken ' . json_encode($token) . ' ' . json_encode($e), 1
);
}
}
@ -250,8 +262,34 @@ class CurlService {
curl_setopt($curl, CURLOPT_TIMEOUT, $request->getTimeout());
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, $request->isBinary());
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$this->maxDownloadSize =
$this->configService->getAppValue(ConfigService::SOCIAL_MAX_SIZE) * (1024 * 1024);
curl_setopt($curl, CURLOPT_BUFFERSIZE, 128);
curl_setopt($curl, CURLOPT_NOPROGRESS, false);
curl_setopt(
/**
* @param $downloadSize
* @param int $downloaded
* @param $uploadSize
* @param int $uploaded
*
* @return int
*/
$curl, CURLOPT_PROGRESSFUNCTION,
function($downloadSize, int $downloaded, $uploadSize, int $uploaded) {
if ($downloaded > $this->maxDownloadSize) {
$this->maxDownloadSizeReached = true;
return 1;
}
return 0;
}
);
return $curl;
}
@ -316,40 +354,85 @@ class CurlService {
/**
* @param int $code
*
* @throws RequestException
*/
private function parseRequestResultCode301($code) {
if ($code === 301) {
throw new RequestException('301 Moved Permanently');
}
}
/**
* @param int $code
*
* @param resource $curl
* @param Request $request
*
* @throws Request410Exception
* @throws RequestContentException
* @throws RequestServerException
* @throws RequestNetworkException
*/
private function parseRequestResultCode404(int $code, Request $request) {
if ($code === 404) {
throw new Request410Exception('404 Not Found - ' . json_encode($request));
private function parseRequestResult($curl, Request &$request) {
$this->parseRequestResultCurl($curl, $request);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$request->setResultCode($code);
$this->parseRequestResultCode301($code, $request);
$this->parseRequestResultCode4xx($code, $request);
$this->parseRequestResultCode5xx($code, $request);
}
/**
* @param resource $curl
* @param Request $request
*
* @throws RequestNetworkException
*/
private function parseRequestResultCurl($curl, Request $request) {
$errno = curl_errno($curl);
if ($errno > 0) {
throw new RequestNetworkException(
$errno . ' - ' . curl_error($curl) . ' - ' . json_encode(
$request, JSON_UNESCAPED_SLASHES
)
);
}
}
/**
* @param int $code
* @param Request $request
*
* @throws Request410Exception
* @throws RequestContentException
*/
private function parseRequestResultCode410(int $code) {
if ($code === 410) {
throw new Request410Exception();
private function parseRequestResultCode301($code, Request $request) {
if ($code === 301) {
throw new RequestContentException(
'301 - ' . json_encode($request, JSON_UNESCAPED_SLASHES)
);
}
}
/**
* @param int $code
* @param Request $request
*
* @throws RequestContentException
*/
private function parseRequestResultCode4xx(int $code, Request $request) {
if ($code === 404 || $code === 410) {
throw new RequestContentException(
$code . ' - ' . json_encode($request, JSON_UNESCAPED_SLASHES)
);
}
}
/**
* @param int $code
* @param Request $request
*
* @throws RequestServerException
*/
private function parseRequestResultCode5xx(int $code, Request $request) {
if ($code === 500) {
throw new RequestServerException(
$code . ' - ' . json_encode($request, JSON_UNESCAPED_SLASHES)
);
}
}
}

Wyświetl plik

@ -31,13 +31,17 @@ declare(strict_types=1);
namespace OCA\Social\Service;
use daita\MySmallPhpTools\Exceptions\MalformedArrayException;
use Exception;
use OCA\Social\Db\ActorsRequest;
use OCA\Social\Db\CacheDocumentsRequest;
use OCA\Social\Exceptions\CacheContentException;
use OCA\Social\Exceptions\CacheContentMimeTypeException;
use OCA\Social\Exceptions\CacheContentSizeException;
use OCA\Social\Exceptions\CacheDocumentDoesNotExistException;
use OCA\Social\Exceptions\RequestContentException;
use OCA\Social\Exceptions\RequestNetworkException;
use OCA\Social\Exceptions\RequestResultSizeException;
use OCA\Social\Exceptions\RequestServerException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\UrlCloudException;
use OCA\Social\Model\ActivityPub\Actor\Person;
@ -53,6 +57,7 @@ class DocumentService {
const ERROR_SIZE = 1;
const ERROR_MIMETYPE = 2;
const ERROR_PERMISSION = 3;
/** @var IURLGenerator */
@ -106,7 +111,7 @@ class DocumentService {
*
* @return Document
* @throws CacheDocumentDoesNotExistException
* @throws NotPermittedException
* @throws MalformedArrayException
*/
public function cacheRemoteDocument(string $id, bool $public = false) {
$document = $this->cacheDocumentsRequest->getById($id, $public);
@ -133,13 +138,30 @@ class DocumentService {
return $document;
} catch (CacheContentMimeTypeException $e) {
$this->miscService->log(
'Not allowed mime type ' . json_encode($document) . ' ' . json_encode($e), 1
);
$document->setMimeType($mime);
$document->setError(self::ERROR_MIMETYPE);
$this->cacheDocumentsRequest->endCaching($document);
} catch (CacheContentSizeException $e) {
} catch (NotPermittedException $e) {
$this->miscService->log(
'Cannot save cache file ' . json_encode($document) . ' ' . json_encode($e), 1
);
$document->setError(self::ERROR_PERMISSION);
$this->cacheDocumentsRequest->endCaching($document);
} catch (RequestResultSizeException $e) {
$this->miscService->log(
'Downloaded file is too big ' . json_encode($document) . ' ' . json_encode($e), 1
);
$document->setError(self::ERROR_SIZE);
$this->cacheDocumentsRequest->endCaching($document);
} catch (CacheContentException $e) {
} catch (RequestContentException $e) {
$this->cacheDocumentsRequest->deleteById($id);
} catch (RequestNetworkException $e) {
$this->cacheDocumentsRequest->endCaching($document);
} catch (RequestServerException $e) {
$this->cacheDocumentsRequest->endCaching($document);
}
throw new CacheDocumentDoesNotExistException();
@ -154,7 +176,7 @@ class DocumentService {
* @return ISimpleFile
* @throws CacheContentException
* @throws CacheDocumentDoesNotExistException
* @throws NotPermittedException
* @throws MalformedArrayException
*/
public function getFromCache(string $id, bool $public = false) {
$document = $this->cacheRemoteDocument($id, $public);

Wyświetl plik

@ -39,10 +39,13 @@ use OCA\Social\Exceptions\FollowSameAccountException;
use OCA\Social\Exceptions\InvalidOriginException;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\RedundancyLimitException;
use OCA\Social\Exceptions\Request410Exception;
use OCA\Social\Exceptions\RequestException;
use OCA\Social\Exceptions\RequestContentException;
use OCA\Social\Exceptions\RetrieveAccountFormatException;
use OCA\Social\Exceptions\RequestNetworkException;
use OCA\Social\Exceptions\RequestResultSizeException;
use OCA\Social\Exceptions\RequestServerException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Exceptions\UrlCloudException;
use OCA\Social\Model\ActivityPub\Activity\Follow;
use OCA\Social\Model\ActivityPub\Activity\Undo;
@ -117,16 +120,18 @@ class FollowService {
*
* @throws CacheActorDoesNotExistException
* @throws FollowSameAccountException
* @throws InvalidOriginException
* @throws InvalidResourceException
* @throws MalformedArrayException
* @throws RedundancyLimitException
* @throws Request410Exception
* @throws RequestException
* @throws RetrieveAccountFormatException
* @throws SocialAppConfigException
* @throws ItemUnknownException
* @throws UrlCloudException
* @throws UnknownItemException
* @throws InvalidOriginException
* @throws \Exception
* @throws RequestContentException
* @throws RequestNetworkException
* @throws RequestResultSizeException
* @throws RequestServerException
*/
public function followAccount(Person $actor, string $account) {
$remoteActor = $this->cacheActorService->getFromAccount($account);
@ -163,14 +168,17 @@ class FollowService {
* @param string $account
*
* @throws CacheActorDoesNotExistException
* @throws InvalidOriginException
* @throws InvalidResourceException
* @throws MalformedArrayException
* @throws RedundancyLimitException
* @throws Request410Exception
* @throws RequestException
* @throws RequestContentException
* @throws RetrieveAccountFormatException
* @throws RequestNetworkException
* @throws RequestResultSizeException
* @throws RequestServerException
* @throws SocialAppConfigException
* @throws UnknownItemException
* @throws \Exception
* @throws ItemUnknownException
*/
public function unfollowAccount(Person $actor, string $account) {
$remoteActor = $this->cacheActorService->getFromAccount($account);

Wyświetl plik

@ -38,7 +38,7 @@ use OCA\Social\Exceptions\ActivityPubFormatException;
use OCA\Social\Exceptions\InvalidOriginException;
use OCA\Social\Exceptions\RedundancyLimitException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Model\ActivityPub\ACore;
@ -74,7 +74,7 @@ class ImportService {
* @throws ActivityPubFormatException
* @throws RedundancyLimitException
* @throws SocialAppConfigException
* @throws UnknownItemException
* @throws ItemUnknownException
*/
public function importFromJson(string $json): ACore {
$data = json_decode($json, true);
@ -85,10 +85,11 @@ class ImportService {
return AP::$activityPub->getItemFromData($data);
}
/**
* @param ACore $activity
*
* @throws UnknownItemException
* @throws ItemUnknownException
* @throws InvalidOriginException
*/
public function parseIncomingRequest(ACore $activity) {

Wyświetl plik

@ -37,14 +37,16 @@ use OCA\Social\Db\NotesRequest;
use OCA\Social\Exceptions\AccountAlreadyExistsException;
use OCA\Social\Exceptions\ActorDoesNotExistException;
use OCA\Social\Exceptions\InvalidOriginException;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Exceptions\NoteNotFoundException;
use OCA\Social\Exceptions\RedundancyLimitException;
use OCA\Social\Exceptions\RequestContentException;
use OCA\Social\Exceptions\RequestNetworkException;
use OCA\Social\Exceptions\RequestResultSizeException;
use OCA\Social\Exceptions\RequestServerException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Exceptions\UrlCloudException;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\Request410Exception;
use OCA\Social\Exceptions\RequestException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Object\Note;
@ -252,10 +254,12 @@ class NoteService {
* @throws MalformedArrayException
* @throws NoteNotFoundException
* @throws RedundancyLimitException
* @throws Request410Exception
* @throws RequestException
* @throws RequestContentException
* @throws RequestNetworkException
* @throws RequestResultSizeException
* @throws RequestServerException
* @throws SocialAppConfigException
* @throws UnknownItemException
* @throws ItemUnknownException
*/
public function replyTo(Note $note, string $replyTo) {
if ($replyTo === '') {
@ -386,15 +390,17 @@ class NoteService {
* @param $noteId
*
* @return Person
* @throws InvalidOriginException
* @throws InvalidResourceException
* @throws MalformedArrayException
* @throws NoteNotFoundException
* @throws Request410Exception
* @throws RequestException
* @throws SocialAppConfigException
* @throws InvalidOriginException
* @throws RedundancyLimitException
* @throws UnknownItemException
* @throws SocialAppConfigException
* @throws ItemUnknownException
* @throws RequestContentException
* @throws RequestNetworkException
* @throws RequestResultSizeException
* @throws RequestServerException
*/
public function getAuthorFromPostId($noteId) {
$note = $this->notesRequest->getNoteById($noteId);

Wyświetl plik

@ -32,7 +32,6 @@ namespace OCA\Social\Service;
use daita\MySmallPhpTools\Traits\TArrayTools;
use Exception;
use OCA\Social\Db\RequestQueueRequest;
use OCA\Social\Exceptions\EmptyQueueException;
use OCA\Social\Exceptions\NoHighPriorityRequestException;
@ -81,7 +80,6 @@ class QueueService {
* @param string $author
*
* @return string
* @throws Exception
*/
public function generateRequestQueue(array $instancePaths, ACore $item, string $author
): string {
@ -197,14 +195,15 @@ class QueueService {
/**
* @param RequestQueue $queue
* @param bool $success
*
* @throws QueueStatusException
*/
public function endRequest(RequestQueue $queue, bool $success) {
if ($success === true) {
$this->requestQueueRequest->setAsSuccess($queue);
} else {
$this->requestQueueRequest->setAsFailure($queue);
try {
if ($success === true) {
$this->requestQueueRequest->setAsSuccess($queue);
} else {
$this->requestQueueRequest->setAsFailure($queue);
}
} catch (QueueStatusException $e) {
}
}

Wyświetl plik

@ -41,12 +41,14 @@ use OCA\Social\Exceptions\InvalidOriginException;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\LinkedDataSignatureMissingException;
use OCA\Social\Exceptions\RedundancyLimitException;
use OCA\Social\Exceptions\Request410Exception;
use OCA\Social\Exceptions\RequestException;
use OCA\Social\Exceptions\RequestContentException;
use OCA\Social\Exceptions\RequestNetworkException;
use OCA\Social\Exceptions\RequestResultSizeException;
use OCA\Social\Exceptions\RequestServerException;
use OCA\Social\Exceptions\SignatureException;
use OCA\Social\Exceptions\SignatureIsGoneException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\LinkedDataSignature;
@ -164,11 +166,13 @@ class SignatureService {
* @throws InvalidResourceException
* @throws MalformedArrayException
* @throws RedundancyLimitException
* @throws RequestException
* @throws RequestNetworkException
* @throws RequestResultSizeException
* @throws RequestServerException
* @throws SignatureException
* @throws SignatureIsGoneException
* @throws SocialAppConfigException
* @throws UnknownItemException
* @throws ItemUnknownException
*/
public function checkRequest(IRequest $request): string {
$dTime = new DateTime($request->getHeader('date'));
@ -180,7 +184,7 @@ class SignatureService {
try {
$origin = $this->checkRequestSignature($request);
} catch (Request410Exception $e) {
} catch (RequestContentException $e) {
throw new SignatureIsGoneException();
}
@ -196,10 +200,12 @@ class SignatureService {
* @throws InvalidResourceException
* @throws MalformedArrayException
* @throws RedundancyLimitException
* @throws Request410Exception
* @throws RequestException
* @throws RequestContentException
* @throws RequestNetworkException
* @throws RequestResultSizeException
* @throws RequestServerException
* @throws SocialAppConfigException
* @throws UnknownItemException
* @throws ItemUnknownException
*/
public function checkObject(ACore $object): bool {
try {
@ -250,11 +256,13 @@ class SignatureService {
* @throws InvalidResourceException
* @throws MalformedArrayException
* @throws RedundancyLimitException
* @throws Request410Exception
* @throws RequestException
* @throws RequestNetworkException
* @throws RequestServerException
* @throws SignatureException
* @throws SocialAppConfigException
* @throws UnknownItemException
* @throws ItemUnknownException
* @throws RequestContentException
* @throws RequestResultSizeException
*/
private function checkRequestSignature(IRequest $request): string {
$signatureHeader = $request->getHeader('Signature');
@ -340,14 +348,16 @@ class SignatureService {
* @param $keyId
*
* @return string
* @throws InvalidOriginException
* @throws InvalidResourceException
* @throws MalformedArrayException
* @throws Request410Exception
* @throws RequestException
* @throws SocialAppConfigException
* @throws UnknownItemException
* @throws RedundancyLimitException
* @throws InvalidOriginException
* @throws RequestContentException
* @throws RequestNetworkException
* @throws RequestResultSizeException
* @throws RequestServerException
* @throws SocialAppConfigException
* @throws ItemUnknownException
*/
private function retrieveKey($keyId): string {
$actor = $this->cacheActorService->getFromId($keyId);