returns 404 on non existant user/avatar

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/122/head
Maxence Lange 2018-12-04 09:02:13 -01:00
rodzic c45cfe6b49
commit 25550d5d4e
6 zmienionych plików z 35 dodań i 8 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": "36ea85a58ceb57a521c8f5a43effb4a7330e7b4c"
"reference": "523adb71b0e12fd678909aeef45ef2c0f612e02a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/36ea85a58ceb57a521c8f5a43effb4a7330e7b4c",
"reference": "36ea85a58ceb57a521c8f5a43effb4a7330e7b4c",
"url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/523adb71b0e12fd678909aeef45ef2c0f612e02a",
"reference": "523adb71b0e12fd678909aeef45ef2c0f612e02a",
"shasum": ""
},
"require": {
@ -40,7 +40,7 @@
}
],
"description": "My small PHP Tools",
"time": "2018-11-29T16:46:38+00:00"
"time": "2018-12-04T09:44:36+00:00"
}
],
"packages-dev": [],

Wyświetl plik

@ -43,6 +43,7 @@ use OCA\Social\Service\ActorService;
use OCA\Social\Service\ImportService;
use OCA\Social\Service\MiscService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Http\Response;
use OCP\IRequest;
@ -133,7 +134,8 @@ class ActivityPubController extends Controller {
return $this->directSuccess($actor);
} catch (Exception $e) {
return $this->fail($e);
http_response_code(404);
exit();
}
}

Wyświetl plik

@ -537,13 +537,14 @@ class LocalController extends Controller {
$response = new FileDisplayResponse($document);
$response->cacheFor(86400);
return $response;
}
return new NotFoundResponse();
} catch (Exception $e) {
return $this->fail($e);
}
http_response_code(404);
exit();
}

Wyświetl plik

@ -31,6 +31,7 @@ declare(strict_types=1);
namespace OCA\Social\Service\ActivityPub;
use daita\MySmallPhpTools\Exceptions\MalformedArrayException;
use daita\MySmallPhpTools\Traits\TArrayTools;
use Exception;
use OCA\Social\Db\CacheActorsRequest;
@ -140,6 +141,7 @@ class PersonService implements ICoreService {
* @throws SocialAppConfigException
* @throws UrlCloudException
* @throws Request410Exception
* @throws MalformedArrayException
*/
public function getFromId(string $id, bool $refresh = false): Person {
@ -182,6 +184,7 @@ class PersonService implements ICoreService {
* @throws SocialAppConfigException
* @throws UrlCloudException
* @throws Request410Exception
* @throws MalformedArrayException
*/
public function getFromAccount(string $account, bool $retrieve = true): Person {

Wyświetl plik

@ -31,6 +31,7 @@ namespace OCA\Social\Service;
use daita\MySmallPhpTools\Exceptions\ArrayNotFoundException;
use daita\MySmallPhpTools\Exceptions\MalformedArrayException;
use daita\MySmallPhpTools\Model\Request;
use daita\MySmallPhpTools\Traits\TArrayTools;
use daita\MySmallPhpTools\Traits\TPathTools;
@ -81,6 +82,7 @@ class InstanceService {
* @throws RequestException
* @throws InvalidResourceException
* @throws Request410Exception
* @throws MalformedArrayException
*/
public function retrieveAccount(string $account) {
$account = $this->withoutBeginAt($account);
@ -115,9 +117,11 @@ class InstanceService {
* @return mixed
* @throws RequestException
* @throws Request410Exception
* @throws MalformedArrayException
*/
public function retrieveObject($id) {
$url = parse_url($id);
$this->mustContains(['path', 'host'], $url);
$request = new Request($url['path'], Request::TYPE_GET);
$request->setAddress($url['host']);

Wyświetl plik

@ -28,8 +28,14 @@ declare(strict_types=1);
namespace OCA\Social;
use Exception;
use OCA\Social\Service\ActorService;
use OCP\AppFramework\QueryException;
require_once(__DIR__ . '/../appinfo/autoload.php');
if (!array_key_exists('resource', $_GET)) {
echo 'missing resource';
exit();
@ -47,6 +53,16 @@ if ($type !== 'acct') {
$username = substr($account, 0, strrpos($account, '@'));
/** @var ActorService $actorService */
try {
$actorService = \OC::$server->query(ActorService::class);
$actorService->getActor($username);
} catch (Exception $e) {
http_response_code(404);
exit;
}
$finger = [
'subject' => $subject,
'links' => [
@ -60,6 +76,7 @@ $finger = [
]
];
header('Content-type: application/json');
echo json_encode($finger);