kopia lustrzana https://github.com/nextcloud/social
using TNC20Request
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/1146/head
rodzic
da20d59013
commit
6866088431
|
@ -23,7 +23,7 @@
|
|||
}
|
||||
},
|
||||
"require": {
|
||||
"daita/my-small-php-tools": "dev-master#ca9c257dd640576c072cb50282e15ae51147cfc2",
|
||||
"daita/my-small-php-tools": "dev-master",
|
||||
"gumlet/php-image-resize": "2.0.*",
|
||||
"friendica/json-ld": "^1.0"
|
||||
},
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "a5fe26ce64e01c6e8e2687e75ff674fb",
|
||||
"content-hash": "773474981fdf7ef0b2f1bcf58cf1b2ec",
|
||||
"packages": [
|
||||
{
|
||||
"name": "daita/my-small-php-tools",
|
||||
|
@ -12,12 +12,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/daita/my-small-php-tools.git",
|
||||
"reference": "ca9c257dd640576c072cb50282e15ae51147cfc2"
|
||||
"reference": "aeed155a9c0cf79153bc9703d1792b0361162dd3"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/ca9c257dd640576c072cb50282e15ae51147cfc2",
|
||||
"reference": "ca9c257dd640576c072cb50282e15ae51147cfc2",
|
||||
"url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/aeed155a9c0cf79153bc9703d1792b0361162dd3",
|
||||
"reference": "aeed155a9c0cf79153bc9703d1792b0361162dd3",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -40,7 +40,7 @@
|
|||
}
|
||||
],
|
||||
"description": "My small PHP Tools",
|
||||
"time": "2020-09-29T15:30:16+00:00"
|
||||
"time": "2020-12-01T00:47:38+00:00"
|
||||
},
|
||||
{
|
||||
"name": "friendica/json-ld",
|
||||
|
@ -1003,23 +1003,23 @@
|
|||
},
|
||||
{
|
||||
"name": "sebastian/code-unit-reverse-lookup",
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git",
|
||||
"reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18"
|
||||
"reference": "1de8cd5c010cb153fcd68b8d0f64606f523f7619"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18",
|
||||
"reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/1de8cd5c010cb153fcd68b8d0f64606f523f7619",
|
||||
"reference": "1de8cd5c010cb153fcd68b8d0f64606f523f7619",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^5.6 || ^7.0"
|
||||
"php": ">=5.6"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^5.7 || ^6.0"
|
||||
"phpunit/phpunit": "^8.5"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
|
@ -1044,7 +1044,13 @@
|
|||
],
|
||||
"description": "Looks up which function or method a line of code belongs to",
|
||||
"homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/",
|
||||
"time": "2017-03-04T06:30:41+00:00"
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/sebastianbergmann",
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2020-11-30T08:15:22+00:00"
|
||||
},
|
||||
{
|
||||
"name": "sebastian/comparator",
|
||||
|
@ -1214,20 +1220,20 @@
|
|||
},
|
||||
{
|
||||
"name": "sebastian/exporter",
|
||||
"version": "3.1.2",
|
||||
"version": "3.1.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sebastianbergmann/exporter.git",
|
||||
"reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e"
|
||||
"reference": "6b853149eab67d4da22291d36f5b0631c0fd856e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/68609e1261d215ea5b21b7987539cbfbe156ec3e",
|
||||
"reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/6b853149eab67d4da22291d36f5b0631c0fd856e",
|
||||
"reference": "6b853149eab67d4da22291d36f5b0631c0fd856e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.0",
|
||||
"php": ">=7.0",
|
||||
"sebastian/recursion-context": "^3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
|
@ -1277,7 +1283,13 @@
|
|||
"export",
|
||||
"exporter"
|
||||
],
|
||||
"time": "2019-09-14T09:02:43+00:00"
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/sebastianbergmann",
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2020-11-30T07:47:53+00:00"
|
||||
},
|
||||
{
|
||||
"name": "sebastian/global-state",
|
||||
|
@ -1332,20 +1344,20 @@
|
|||
},
|
||||
{
|
||||
"name": "sebastian/object-enumerator",
|
||||
"version": "3.0.3",
|
||||
"version": "3.0.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sebastianbergmann/object-enumerator.git",
|
||||
"reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5"
|
||||
"reference": "e67f6d32ebd0c749cf9d1dbd9f226c727043cdf2"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/7cfd9e65d11ffb5af41198476395774d4c8a84c5",
|
||||
"reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/e67f6d32ebd0c749cf9d1dbd9f226c727043cdf2",
|
||||
"reference": "e67f6d32ebd0c749cf9d1dbd9f226c727043cdf2",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.0",
|
||||
"php": ">=7.0",
|
||||
"sebastian/object-reflector": "^1.1.1",
|
||||
"sebastian/recursion-context": "^3.0"
|
||||
},
|
||||
|
@ -1375,24 +1387,30 @@
|
|||
],
|
||||
"description": "Traverses array structures and object graphs to enumerate all referenced objects",
|
||||
"homepage": "https://github.com/sebastianbergmann/object-enumerator/",
|
||||
"time": "2017-08-03T12:35:26+00:00"
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/sebastianbergmann",
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2020-11-30T07:40:27+00:00"
|
||||
},
|
||||
{
|
||||
"name": "sebastian/object-reflector",
|
||||
"version": "1.1.1",
|
||||
"version": "1.1.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sebastianbergmann/object-reflector.git",
|
||||
"reference": "773f97c67f28de00d397be301821b06708fca0be"
|
||||
"reference": "9b8772b9cbd456ab45d4a598d2dd1a1bced6363d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/773f97c67f28de00d397be301821b06708fca0be",
|
||||
"reference": "773f97c67f28de00d397be301821b06708fca0be",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/9b8772b9cbd456ab45d4a598d2dd1a1bced6363d",
|
||||
"reference": "9b8772b9cbd456ab45d4a598d2dd1a1bced6363d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.0"
|
||||
"php": ">=7.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^6.0"
|
||||
|
@ -1420,24 +1438,30 @@
|
|||
],
|
||||
"description": "Allows reflection of object attributes, including inherited and non-public ones",
|
||||
"homepage": "https://github.com/sebastianbergmann/object-reflector/",
|
||||
"time": "2017-03-29T09:07:27+00:00"
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/sebastianbergmann",
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2020-11-30T07:37:18+00:00"
|
||||
},
|
||||
{
|
||||
"name": "sebastian/recursion-context",
|
||||
"version": "3.0.0",
|
||||
"version": "3.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sebastianbergmann/recursion-context.git",
|
||||
"reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8"
|
||||
"reference": "367dcba38d6e1977be014dc4b22f47a484dac7fb"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8",
|
||||
"reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/367dcba38d6e1977be014dc4b22f47a484dac7fb",
|
||||
"reference": "367dcba38d6e1977be014dc4b22f47a484dac7fb",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.0"
|
||||
"php": ">=7.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^6.0"
|
||||
|
@ -1458,14 +1482,14 @@
|
|||
"BSD-3-Clause"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jeff Welch",
|
||||
"email": "whatthejeff@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Sebastian Bergmann",
|
||||
"email": "sebastian@phpunit.de"
|
||||
},
|
||||
{
|
||||
"name": "Jeff Welch",
|
||||
"email": "whatthejeff@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Adam Harvey",
|
||||
"email": "aharvey@php.net"
|
||||
|
@ -1473,7 +1497,13 @@
|
|||
],
|
||||
"description": "Provides functionality to recursively process PHP variables",
|
||||
"homepage": "http://www.github.com/sebastianbergmann/recursion-context",
|
||||
"time": "2017-03-03T06:23:57+00:00"
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/sebastianbergmann",
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2020-11-30T07:34:24+00:00"
|
||||
},
|
||||
{
|
||||
"name": "sebastian/resource-operations",
|
||||
|
@ -1562,16 +1592,16 @@
|
|||
},
|
||||
{
|
||||
"name": "symfony/polyfill-ctype",
|
||||
"version": "v1.18.1",
|
||||
"version": "v1.19.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-ctype.git",
|
||||
"reference": "1c302646f6efc070cd46856e600e5e0684d6b454"
|
||||
"reference": "aed596913b70fae57be53d86faa2e9ef85a2297b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/1c302646f6efc070cd46856e600e5e0684d6b454",
|
||||
"reference": "1c302646f6efc070cd46856e600e5e0684d6b454",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/aed596913b70fae57be53d86faa2e9ef85a2297b",
|
||||
"reference": "aed596913b70fae57be53d86faa2e9ef85a2297b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1583,7 +1613,7 @@
|
|||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.18-dev"
|
||||
"dev-main": "1.19-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/polyfill",
|
||||
|
@ -1634,7 +1664,7 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2020-07-14T12:35:20+00:00"
|
||||
"time": "2020-10-23T09:01:57+00:00"
|
||||
},
|
||||
{
|
||||
"name": "theseer/tokenizer",
|
||||
|
|
|
@ -30,6 +30,7 @@ declare(strict_types=1);
|
|||
namespace OCA\Social\Controller;
|
||||
|
||||
|
||||
use daita\MySmallPhpTools\Traits\Nextcloud\nc20\TNC20Logger;
|
||||
use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse;
|
||||
use daita\MySmallPhpTools\Traits\TAsync;
|
||||
use daita\MySmallPhpTools\Traits\TStringTools;
|
||||
|
@ -65,6 +66,7 @@ class ActivityPubController extends Controller {
|
|||
use TNCDataResponse;
|
||||
use TStringTools;
|
||||
use TAsync;
|
||||
use TNC20Logger;
|
||||
|
||||
|
||||
/** @var SocialPubController */
|
||||
|
@ -246,10 +248,9 @@ class ActivityPubController extends Controller {
|
|||
* @return Response
|
||||
*/
|
||||
public function inbox(string $username): Response {
|
||||
|
||||
try {
|
||||
$body = file_get_contents('php://input');
|
||||
$this->miscService->log('[<<] inbox: ' . $body, 1);
|
||||
$this->debug('[<<] inbox', ['body' => $body]);
|
||||
|
||||
$requestTime = 0;
|
||||
$origin = $this->signatureService->checkRequest($this->request, $body, $requestTime);
|
||||
|
|
|
@ -268,6 +268,7 @@ class OAuthController extends Controller {
|
|||
], Http::STATUS_OK
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
$this->miscService->log($e->getMessage() . ' ' . get_class($e));
|
||||
return new DataResponse(['error' => $e->getMessage()], Http::STATUS_UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ declare(strict_types=1);
|
|||
namespace OCA\Social\Search;
|
||||
|
||||
|
||||
use daita\MySmallPhpTools\Traits\Nextcloud\nc20\TNC20Logger;
|
||||
use daita\MySmallPhpTools\Traits\TArrayTools;
|
||||
use Exception;
|
||||
use OCA\Social\Exceptions\AccountDoesNotExistException;
|
||||
|
@ -62,6 +63,7 @@ class UnifiedSearchProvider implements IProvider {
|
|||
|
||||
|
||||
use TArrayTools;
|
||||
use TNC20Logger;
|
||||
|
||||
|
||||
/** @var IL10N */
|
||||
|
@ -217,7 +219,8 @@ class UnifiedSearchProvider implements IProvider {
|
|||
private function convertAccounts(array $accounts): array {
|
||||
$result = [];
|
||||
foreach ($accounts as $account) {
|
||||
$icon = ($account->hasIcon()) ? $account->getIcon()->getUrl() : '';
|
||||
$icon = ($account->hasIcon()) ? $account->getIcon()
|
||||
->getUrl() : '';
|
||||
$result[] = new UnifiedSearchResult(
|
||||
$icon,
|
||||
$account->getPreferredUsername(),
|
||||
|
|
|
@ -35,6 +35,7 @@ use daita\MySmallPhpTools\Exceptions\RequestNetworkException;
|
|||
use daita\MySmallPhpTools\Exceptions\RequestResultNotJsonException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestResultSizeException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestServerException;
|
||||
use daita\MySmallPhpTools\Model\Nextcloud\nc20\NC20Request;
|
||||
use daita\MySmallPhpTools\Model\Request;
|
||||
use daita\MySmallPhpTools\Traits\TArrayTools;
|
||||
use Exception;
|
||||
|
@ -365,9 +366,9 @@ class ActivityService {
|
|||
/**
|
||||
* @param RequestQueue $queue
|
||||
*
|
||||
* @return Request
|
||||
* @return NC20Request
|
||||
*/
|
||||
private function generateRequestFromQueue(RequestQueue $queue): Request {
|
||||
private function generateRequestFromQueue(RequestQueue $queue): NC20Request {
|
||||
$path = $queue->getInstance();
|
||||
|
||||
$requestType = Request::TYPE_GET;
|
||||
|
@ -377,10 +378,10 @@ class ActivityService {
|
|||
$requestType = Request::TYPE_POST;
|
||||
}
|
||||
|
||||
$request = new Request($path->getPath(), $requestType);
|
||||
$request = new NC20Request($path->getPath(), $requestType);
|
||||
$request->setTimeout($queue->getTimeout());
|
||||
$request->setDataJson($queue->getActivity());
|
||||
$request->setAddress($path->getAddress());
|
||||
$request->setHost($path->getAddress());
|
||||
$request->setProtocol($path->getProtocol());
|
||||
|
||||
return $request;
|
||||
|
|
|
@ -36,6 +36,7 @@ use daita\MySmallPhpTools\Exceptions\RequestNetworkException;
|
|||
use daita\MySmallPhpTools\Exceptions\RequestResultNotJsonException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestResultSizeException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestServerException;
|
||||
use daita\MySmallPhpTools\Traits\Nextcloud\nc20\TNC20Logger;
|
||||
use daita\MySmallPhpTools\Traits\TArrayTools;
|
||||
use Exception;
|
||||
use OCA\Social\AP;
|
||||
|
@ -53,10 +54,16 @@ use OCA\Social\Model\ActivityPub\Actor\Person;
|
|||
use OCP\IURLGenerator;
|
||||
|
||||
|
||||
/**
|
||||
* Class CacheActorService
|
||||
*
|
||||
* @package OCA\Social\Service
|
||||
*/
|
||||
class CacheActorService {
|
||||
|
||||
|
||||
use TArrayTools;
|
||||
use TNC20Logger;
|
||||
|
||||
|
||||
/** @var IURLGenerator */
|
||||
|
@ -129,7 +136,6 @@ class CacheActorService {
|
|||
* @throws UnauthorizedFediverseException
|
||||
*/
|
||||
public function getFromId(string $id, bool $refresh = false): Person {
|
||||
|
||||
$posAnchor = strpos($id, '#');
|
||||
if ($posAnchor !== false) {
|
||||
$id = substr($id, 0, $posAnchor);
|
||||
|
@ -144,6 +150,8 @@ class CacheActorService {
|
|||
} catch (CacheActorDoesNotExistException $e) {
|
||||
$object = $this->curlService->retrieveObject($id);
|
||||
|
||||
$this->debug('object retrieved', ['id' => $id, 'object' => $object]);
|
||||
|
||||
/** @var Person $actor */
|
||||
$actor = AP::$activityPub->getItemFromData($object);
|
||||
if (!AP::$activityPub->isActor($actor)) {
|
||||
|
@ -220,9 +228,15 @@ class CacheActorService {
|
|||
} catch (CacheActorDoesNotExistException $e) {
|
||||
}
|
||||
|
||||
$this->debug('getFromAccount', ['account' => $account, 'retrieve' => $retrieve]);
|
||||
|
||||
try {
|
||||
$actor = $this->cacheActorsRequest->getFromAccount($account);
|
||||
|
||||
$this->debug('Found Actor', ['account' => $account, 'actor' => $actor]);
|
||||
} catch (CacheActorDoesNotExistException $e) {
|
||||
$this->debug('Actor not found', ['account' => $account]);
|
||||
|
||||
if (!$retrieve) {
|
||||
throw new CacheActorDoesNotExistException();
|
||||
}
|
||||
|
@ -230,6 +244,8 @@ class CacheActorService {
|
|||
$actor = $this->curlService->retrieveAccount($account);
|
||||
$actor->setAccount($account);
|
||||
try {
|
||||
$this->warning('Saving Actor', false, ['actor' => $actor]);
|
||||
|
||||
$this->save($actor);
|
||||
} catch (Exception $e) {
|
||||
throw new InvalidResourceException($e->getMessage());
|
||||
|
|
|
@ -35,6 +35,7 @@ use daita\MySmallPhpTools\Exceptions\RequestContentException;
|
|||
use daita\MySmallPhpTools\Exceptions\RequestNetworkException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestResultSizeException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestServerException;
|
||||
use daita\MySmallPhpTools\Model\Nextcloud\nc20\NC20Request;
|
||||
use daita\MySmallPhpTools\Model\Request;
|
||||
use daita\MySmallPhpTools\Traits\TArrayTools;
|
||||
use daita\MySmallPhpTools\Traits\TStringTools;
|
||||
|
@ -270,16 +271,14 @@ class CacheDocumentService {
|
|||
* @throws SocialAppConfigException
|
||||
* @throws UnauthorizedFediverseException
|
||||
*/
|
||||
public function retrieveContent(string $url) {
|
||||
public function retrieveContent(string $url): string {
|
||||
$url = parse_url($url);
|
||||
$this->mustContains(['path', 'host', 'scheme'], $url);
|
||||
$request = new Request($url['path'], Request::TYPE_GET, true);
|
||||
$request->setAddress($url['host']);
|
||||
$request = new NC20Request($url['path'], Request::TYPE_GET, true);
|
||||
$request->setHost($url['host']);
|
||||
$request->setProtocol($url['scheme']);
|
||||
|
||||
$content = $this->curlService->doRequest($request);
|
||||
|
||||
return $content;
|
||||
return $this->curlService->doRequest($request);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace OCA\Social\Service;
|
||||
|
||||
use daita\MySmallPhpTools\Model\Nextcloud\nc20\NC20Request;
|
||||
use daita\MySmallPhpTools\Model\Request;
|
||||
use daita\MySmallPhpTools\Traits\TArrayTools;
|
||||
use daita\MySmallPhpTools\Traits\TPathTools;
|
||||
|
@ -436,10 +437,25 @@ class ConfigService {
|
|||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param NC20Request $request
|
||||
*/
|
||||
public function configureRequest(Request $request) {
|
||||
public function configureRequest(NC20Request $request) {
|
||||
$request->setVerifyPeer($this->getAppValue(ConfigService::SOCIAL_SELF_SIGNED) !== '1');
|
||||
|
||||
if ($request->getType() === Request::TYPE_GET) {
|
||||
$request->addHeader(
|
||||
'Accept', 'application/json; profile="https://www.w3.org/ns/activitystreams"'
|
||||
);
|
||||
}
|
||||
|
||||
if ($request->getType() === Request::TYPE_POST) {
|
||||
$request->addHeader(
|
||||
'Content-Type', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
|
||||
);
|
||||
}
|
||||
|
||||
$request->setLocalAddressAllowed(true);
|
||||
$request->setFollowLocation(true);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -37,10 +37,11 @@ use daita\MySmallPhpTools\Exceptions\RequestNetworkException;
|
|||
use daita\MySmallPhpTools\Exceptions\RequestResultNotJsonException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestResultSizeException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestServerException;
|
||||
use daita\MySmallPhpTools\Model\Nextcloud\nc20\NC20Request;
|
||||
use daita\MySmallPhpTools\Model\Request;
|
||||
use daita\MySmallPhpTools\Traits\Nextcloud\nc20\TNC20Request;
|
||||
use daita\MySmallPhpTools\Traits\TArrayTools;
|
||||
use daita\MySmallPhpTools\Traits\TPathTools;
|
||||
use daita\MySmallPhpTools\Traits\TRequest;
|
||||
use Exception;
|
||||
use OCA\Social\AP;
|
||||
use OCA\Social\Exceptions\HostMetaException;
|
||||
|
@ -58,14 +59,11 @@ class CurlService {
|
|||
|
||||
use TArrayTools;
|
||||
use TPathTools;
|
||||
use TRequest {
|
||||
initRequestPost as initRequestPostOrig;
|
||||
initRequestGet as initRequestGetOrig;
|
||||
use TNC20Request {
|
||||
retrieveJson as retrieveJsonOrig;
|
||||
doRequest as doRequestOrig;
|
||||
}
|
||||
|
||||
|
||||
const ASYNC_REQUEST_TOKEN = '/async/request/{token}';
|
||||
const USER_AGENT = 'Nextcloud Social';
|
||||
|
||||
|
@ -96,6 +94,7 @@ class CurlService {
|
|||
|
||||
$maxDlSize = $this->configService->getAppValue(ConfigService::SOCIAL_MAX_SIZE) * (1024 * 1024);
|
||||
$this->setMaxDownloadSize($maxDlSize);
|
||||
$this->setup('app', 'social');
|
||||
}
|
||||
|
||||
|
||||
|
@ -113,6 +112,7 @@ class CurlService {
|
|||
* @throws UnauthorizedFediverseException
|
||||
*/
|
||||
public function webfingerAccount(string &$account): array {
|
||||
$this->debug('webfingerAccount', ['account' => $account]);
|
||||
$account = $this->withoutBeginAt($account);
|
||||
|
||||
// we consider an account is like an email
|
||||
|
@ -132,12 +132,14 @@ class CurlService {
|
|||
$path = '/.well-known/webfinger';
|
||||
}
|
||||
|
||||
$request = new Request($path);
|
||||
$request->addData('resource', 'acct:' . $account);
|
||||
$request->setAddress($host);
|
||||
$request = new NC20Request($path);
|
||||
$request->addParam('resource', 'acct:' . $account);
|
||||
$request->setHost($host);
|
||||
$request->setProtocols($protocols);
|
||||
$result = $this->retrieveJson($request);
|
||||
|
||||
$this->notice('webfingerAccount, request result', false, ['request' => $request]);
|
||||
|
||||
$subject = $this->get('subject', $result, '');
|
||||
list($type, $temp) = explode(':', $subject, 2);
|
||||
if ($type === 'acct') {
|
||||
|
@ -156,14 +158,17 @@ class CurlService {
|
|||
* @throws HostMetaException
|
||||
*/
|
||||
public function hostMeta(string &$host, array &$protocols): string {
|
||||
$request = new Request('/.well-known/host-meta');
|
||||
$request->setAddress($host);
|
||||
$request = new NC20Request('/.well-known/host-meta');
|
||||
$request->setHost($host);
|
||||
$request->setProtocols($protocols);
|
||||
|
||||
$this->debug('hostMeta', ['host' => $host, 'protocols' => $protocols]);
|
||||
|
||||
try {
|
||||
$result = $this->retrieveJson($request);
|
||||
} catch (Exception $e) {
|
||||
$this->miscService->log('hostMeta Exception - ' . get_class($e) . ' - ' . $e->getMessage(), 0);
|
||||
$this->exception($e, self::$NOTICE, ['request' => $request]);
|
||||
|
||||
throw new HostMetaException(get_class($e) . ' - ' . $e->getMessage());
|
||||
}
|
||||
|
||||
|
@ -194,6 +199,7 @@ class CurlService {
|
|||
* @throws UnauthorizedFediverseException
|
||||
*/
|
||||
public function retrieveAccount(string &$account): Person {
|
||||
$this->debug('retrieveAccount', ['account' => $account]);
|
||||
$result = $this->webfingerAccount($account);
|
||||
|
||||
try {
|
||||
|
@ -205,10 +211,12 @@ class CurlService {
|
|||
$id = $this->get('href', $link, '');
|
||||
$data = $this->retrieveObject($id);
|
||||
|
||||
$this->debug('retrieveAccount, details', ['link' => $link, 'data' => $data, 'account' => $account]);
|
||||
|
||||
/** @var Person $actor */
|
||||
$actor = AP::$activityPub->getItemFromData($data);
|
||||
if (!AP::$activityPub->isActor($actor)) {
|
||||
throw new ItemUnknownException();
|
||||
throw new ItemUnknownException(json_encode($actor) . ' is not an Actor');
|
||||
}
|
||||
|
||||
if (strtolower($actor->getId()) !== strtolower($id)) {
|
||||
|
@ -235,15 +243,20 @@ class CurlService {
|
|||
* @throws UnauthorizedFediverseException
|
||||
*/
|
||||
public function retrieveObject($id): array {
|
||||
$this->debug('retrieveObject', ['id' => $id]);
|
||||
$url = parse_url($id);
|
||||
$this->mustContains(['path', 'host', 'scheme'], $url);
|
||||
$request = new Request($url['path'], Request::TYPE_GET);
|
||||
$request->setAddress($url['host']);
|
||||
$request = new NC20Request($url['path'], Request::TYPE_GET);
|
||||
$request->setHost($url['host']);
|
||||
$request->setProtocol($url['scheme']);
|
||||
|
||||
$this->debug('retrieveObject', ['request' => $request]);
|
||||
|
||||
$result = $this->retrieveJson($request);
|
||||
$this->notice('retrieveObject, request result', false, ['request' => $request]);
|
||||
|
||||
if (is_array($result)) {
|
||||
$result['_host'] = $request->getAddress();
|
||||
$result['_host'] = $request->getHost();
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
@ -251,35 +264,24 @@ class CurlService {
|
|||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param NC20Request $request
|
||||
*
|
||||
* @return array
|
||||
* @throws RequestContentException
|
||||
* @throws RequestNetworkException
|
||||
* @throws RequestResultNotJsonException
|
||||
* @throws RequestResultSizeException
|
||||
* @throws RequestServerException
|
||||
*/
|
||||
public function retrieveJson(Request $request): array {
|
||||
$this->configService->configureRequest($request);
|
||||
$this->assignUserAgent($request);
|
||||
|
||||
public function retrieveJson(NC20Request $request): array {
|
||||
try {
|
||||
$result = $this->retrieveJsonOrig($request);
|
||||
} catch (RequestResultSizeException | RequestResultNotJsonException $e) {
|
||||
$this->miscService->log(
|
||||
'[!!] request: ' . json_encode($request) . ' - content-type: '
|
||||
. $request->getContentType() . ' - ' . $e->getMessage(), 1
|
||||
);
|
||||
return $this->retrieveJsonOrig($request);
|
||||
} catch (RequestNetworkException | RequestContentException $e) {
|
||||
$this->exception($e, self::$NOTICE, ['request' => $request]);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param NC20Request $request
|
||||
*
|
||||
* @return mixed
|
||||
* @throws SocialAppConfigException
|
||||
|
@ -289,7 +291,8 @@ class CurlService {
|
|||
* @throws RequestResultSizeException
|
||||
* @throws RequestServerException
|
||||
*/
|
||||
public function doRequest(Request $request) {
|
||||
// migration ?
|
||||
public function doRequest(NC20Request $request) {
|
||||
$this->fediverseService->authorized($request->getAddress());
|
||||
$this->configService->configureRequest($request);
|
||||
$this->assignUserAgent($request);
|
||||
|
@ -299,9 +302,9 @@ class CurlService {
|
|||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param NC20Request $request
|
||||
*/
|
||||
public function assignUserAgent(Request $request) {
|
||||
public function assignUserAgent(NC20Request $request) {
|
||||
$request->setUserAgent(
|
||||
self::USER_AGENT . ' ' . $this->configService->getAppValue('installed_version')
|
||||
);
|
||||
|
@ -320,8 +323,8 @@ class CurlService {
|
|||
$path .= $this->withoutBeginSlash(self::ASYNC_REQUEST_TOKEN);
|
||||
$path = str_replace('{token}', $token, $path);
|
||||
|
||||
$request = new Request($path, Request::TYPE_POST);
|
||||
$request->setAddress($this->configService->getCloudHost());
|
||||
$request = new NC20Request($path, Request::TYPE_POST);
|
||||
$request->setHost($this->configService->getCloudHost());
|
||||
$request->setProtocol(parse_url($address, PHP_URL_SCHEME));
|
||||
|
||||
try {
|
||||
|
@ -336,40 +339,5 @@ class CurlService {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
*/
|
||||
protected function initRequestGet(Request $request) {
|
||||
if ($request->getType() !== Request::TYPE_GET) {
|
||||
return;
|
||||
}
|
||||
|
||||
$request->addHeader(
|
||||
'Accept: application/json; profile="https://www.w3.org/ns/activitystreams"'
|
||||
);
|
||||
$request->addHeader(
|
||||
'Accept: application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
|
||||
);
|
||||
|
||||
$this->initRequestGetOrig($request);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param resource $curl
|
||||
* @param Request $request
|
||||
*/
|
||||
protected function initRequestPost($curl, Request $request) {
|
||||
if ($request->getType() !== Request::TYPE_POST) {
|
||||
return;
|
||||
}
|
||||
|
||||
$request->addHeader(
|
||||
'Content-Type: application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
|
||||
);
|
||||
|
||||
$this->initRequestPostOrig($curl, $request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -31,15 +31,22 @@ declare(strict_types=1);
|
|||
namespace OCA\Social\Service;
|
||||
|
||||
|
||||
use daita\MySmallPhpTools\Traits\Nextcloud\nc20\TNC20Logger;
|
||||
use daita\MySmallPhpTools\Traits\TArrayTools;
|
||||
use Exception;
|
||||
use OCA\Social\Model\ActivityPub\Actor\Person;
|
||||
|
||||
|
||||
/**
|
||||
* Class SearchService
|
||||
*
|
||||
* @package OCA\Social\Service
|
||||
*/
|
||||
class SearchService {
|
||||
|
||||
|
||||
use TArrayTools;
|
||||
use TNC20Logger;
|
||||
|
||||
|
||||
const SEARCH_ACCOUNTS = 1;
|
||||
|
@ -88,6 +95,7 @@ class SearchService {
|
|||
public function searchAccounts(string $search): array {
|
||||
$result = [];
|
||||
$type = $this->getTypeFromSearch($search);
|
||||
|
||||
if ($search === '' || !$type & self::SEARCH_ACCOUNTS) {
|
||||
return $result;
|
||||
}
|
||||
|
@ -99,6 +107,7 @@ class SearchService {
|
|||
try {
|
||||
$this->cacheActorService->getFromAccount($search);
|
||||
} catch (Exception $e) {
|
||||
$this->exception($e, self::$NOTICE, ['search' => $search]);
|
||||
}
|
||||
|
||||
return $this->cacheActorService->searchCachedAccounts($search);
|
||||
|
|
|
@ -32,7 +32,12 @@ namespace OCA\Social\Service;
|
|||
|
||||
use daita\MySmallPhpTools\Exceptions\DateTimeException;
|
||||
use daita\MySmallPhpTools\Exceptions\MalformedArrayException;
|
||||
use daita\MySmallPhpTools\Model\Request;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestContentException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestNetworkException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestResultNotJsonException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestResultSizeException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestServerException;
|
||||
use daita\MySmallPhpTools\Model\Nextcloud\nc20\NC20Request;
|
||||
use daita\MySmallPhpTools\Traits\TArrayTools;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
|
@ -46,11 +51,6 @@ use OCA\Social\Exceptions\InvalidResourceException;
|
|||
use OCA\Social\Exceptions\ItemUnknownException;
|
||||
use OCA\Social\Exceptions\LinkedDataSignatureMissingException;
|
||||
use OCA\Social\Exceptions\RedundancyLimitException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestContentException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestNetworkException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestResultNotJsonException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestResultSizeException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestServerException;
|
||||
use OCA\Social\Exceptions\SignatureException;
|
||||
use OCA\Social\Exceptions\SignatureIsGoneException;
|
||||
use OCA\Social\Exceptions\SocialAppConfigException;
|
||||
|
@ -142,13 +142,13 @@ class SignatureService {
|
|||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param NC20Request $request
|
||||
* @param RequestQueue $queue
|
||||
*
|
||||
* @throws ActorDoesNotExistException
|
||||
* @throws SocialAppConfigException
|
||||
* @throws SocialAppConfigException // TODO: implement in TNC20Request ?
|
||||
*/
|
||||
public function signRequest(Request $request, RequestQueue $queue) {
|
||||
public function signRequest(NC20Request $request, RequestQueue $queue) {
|
||||
$date = gmdate(self::DATE_HEADER);
|
||||
$path = $queue->getInstance();
|
||||
|
||||
|
@ -169,22 +169,22 @@ class SignatureService {
|
|||
$signed = base64_encode($signed);
|
||||
$signature = $this->generateSignature($headersElements, $localActor->getId(), $signed);
|
||||
|
||||
$request->addHeader('Signature: ' . $signature);
|
||||
$request->addHeader('Signature', $signature);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $elements
|
||||
* @param array $data
|
||||
* @param Request $request
|
||||
* @param NC20Request $request
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateHeaders(array $elements, array $data, Request $request): string {
|
||||
private function generateHeaders(array $elements, array $data, NC20Request $request): string {
|
||||
$signingElements = [];
|
||||
foreach ($elements as $element) {
|
||||
$signingElements[] = $element . ': ' . $data[$element];
|
||||
$request->addHeader($element . ': ' . $data[$element]);
|
||||
$request->addHeader($element, $data[$element]);
|
||||
}
|
||||
|
||||
return implode("\n", $signingElements);
|
||||
|
@ -196,7 +196,7 @@ class SignatureService {
|
|||
* @param string $actorId
|
||||
* @param string $signed
|
||||
*
|
||||
* @return array
|
||||
* @return string
|
||||
*/
|
||||
private function generateSignature(array $elements, string $actorId, string $signed): string {
|
||||
$signatureElements[] = 'keyId="' . $actorId . '#main-key"';
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace OCA\Social\Service;
|
|||
|
||||
|
||||
use daita\MySmallPhpTools\Exceptions\ArrayNotFoundException;
|
||||
use daita\MySmallPhpTools\Model\Request;
|
||||
use daita\MySmallPhpTools\Model\Nextcloud\nc20\NC20Request;
|
||||
use daita\MySmallPhpTools\Model\SimpleDataStore;
|
||||
use daita\MySmallPhpTools\Traits\TArrayTools;
|
||||
use Exception;
|
||||
|
@ -108,9 +108,9 @@ class TestService {
|
|||
$tests->aObj('tests', $testHostMeta);
|
||||
|
||||
|
||||
$request = new Request($path);
|
||||
$request->addData('resource', 'acct:' . $account);
|
||||
$request->setAddress($host);
|
||||
$request = new NC20Request($path);
|
||||
$request->addParam('resource', 'acct:' . $account);
|
||||
$request->setHost($host);
|
||||
$request->setProtocols($protocols);
|
||||
|
||||
$testWebfinger = new Test('webfinger', Test::SEVERITY_MANDATORY);
|
||||
|
|
Ładowanie…
Reference in New Issue