1
0
Fork 0

Merge pull request #9527 from annando/fetch-object-by-url

Fix: Fetch object by URL
This commit is contained in:
Hypolite Petovan 2020-11-11 13:14:20 -05:00 committed by GitHub
commit 42db861759
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,6 +22,7 @@
namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\Logger;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
@ -31,6 +32,7 @@ use Friendica\Network\HTTPException;
use Friendica\Protocol\ActivityPub;
use Friendica\Util\HTTPSignature;
use Friendica\Util\Network;
use Friendica\Util\Strings;
/**
* ActivityPub Objects
@ -47,8 +49,27 @@ class Objects extends BaseModule
DI::baseUrl()->redirect(str_replace('objects/', 'display/', DI::args()->getQueryString()));
}
$itemuri = DBA::selectFirst('item-uri', ['id'], ['guid' => $parameters['guid']]);
if (DBA::isResult($itemuri)) {
Logger::info('Provided GUID found.', ['guid' => $parameters['guid'], 'uri-id' => $itemuri['id']]);
} else {
// The item URI does not always contain the GUID. This means that we have to search the URL instead
$url = DI::baseUrl()->get() . '/' . DI::args()->getQueryString();
$nurl = Strings::normaliseLink($url);
$ssl_url = str_replace('http://', 'https://', $nurl);
$itemuri = DBA::selectFirst('item-uri', ['guid', 'id'], ['uri' => [$url, $nurl, $ssl_url]]);
if (DBA::isResult($itemuri)) {
Logger::info('URL found.', ['url' => $url, 'guid' => $itemuri['guid'], 'uri-id' => $itemuri['id']]);
} else {
Logger::info('URL not found.', ['url' => $url]);
throw new HTTPException\NotFoundException();
}
}
$item = Item::selectFirst(['id', 'uid', 'origin', 'author-link', 'changed', 'private', 'psid', 'gravity'],
['guid' => $parameters['guid']], ['order' => ['origin' => true]]);
['uri-id' => $itemuri['id']], ['order' => ['origin' => true]]);
if (!DBA::isResult($item)) {
throw new HTTPException\NotFoundException();