[ActivityPub] Include recent actor type attribute in its creation
Improve debug logs
This commit is contained in:
parent
ed67da89dc
commit
1832397363
@ -63,7 +63,10 @@ class Inbox extends Controller
|
|||||||
*/
|
*/
|
||||||
public function handle(?int $gsactor_id = null): TypeResponse
|
public function handle(?int $gsactor_id = null): TypeResponse
|
||||||
{
|
{
|
||||||
$error = fn(string $m): TypeResponse => new TypeResponse(json_encode(['error' => $m]));
|
$error = function (string $m, ?Exception $e = null): TypeResponse {
|
||||||
|
Log::error('ActivityPub Error Answer: ' . ($json = json_encode(['error' => $m, 'exception' => var_export($e, true)])));
|
||||||
|
return new TypeResponse($json, 400);
|
||||||
|
};
|
||||||
$path = Router::url('activitypub_inbox', type: Router::ABSOLUTE_PATH);
|
$path = Router::url('activitypub_inbox', type: Router::ABSOLUTE_PATH);
|
||||||
|
|
||||||
if (!is_null($gsactor_id)) {
|
if (!is_null($gsactor_id)) {
|
||||||
@ -94,7 +97,7 @@ class Inbox extends Controller
|
|||||||
}
|
}
|
||||||
unset($resource_parts);
|
unset($resource_parts);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $error('Invalid actor: ' . $e->getMessage());
|
return $error('Invalid actor.', $e);
|
||||||
}
|
}
|
||||||
|
|
||||||
$activitypub_rsa = ActivitypubRsa::getByActor($actor);
|
$activitypub_rsa = ActivitypubRsa::getByActor($actor);
|
||||||
@ -108,7 +111,7 @@ class Inbox extends Controller
|
|||||||
|
|
||||||
if (!isset($headers['signature'])) {
|
if (!isset($headers['signature'])) {
|
||||||
Log::debug('ActivityPub Inbox: HTTP Signature: Missing Signature header.');
|
Log::debug('ActivityPub Inbox: HTTP Signature: Missing Signature header.');
|
||||||
return $error('Missing Signature header.', 400);
|
return $error('Missing Signature header.');
|
||||||
// TODO: support other methods beyond HTTP Signatures
|
// TODO: support other methods beyond HTTP Signatures
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +120,7 @@ class Inbox extends Controller
|
|||||||
Log::debug('ActivityPub Inbox: HTTP Signature Data: ' . print_r($signatureData, true));
|
Log::debug('ActivityPub Inbox: HTTP Signature Data: ' . print_r($signatureData, true));
|
||||||
if (isset($signatureData['error'])) {
|
if (isset($signatureData['error'])) {
|
||||||
Log::debug('ActivityPub Inbox: HTTP Signature: ' . json_encode($signatureData, JSON_PRETTY_PRINT));
|
Log::debug('ActivityPub Inbox: HTTP Signature: ' . json_encode($signatureData, JSON_PRETTY_PRINT));
|
||||||
return $error(json_encode($signatureData, JSON_PRETTY_PRINT), 400);
|
return $error(json_encode($signatureData, JSON_PRETTY_PRINT));
|
||||||
}
|
}
|
||||||
|
|
||||||
[$verified, /*$headers*/] = HTTPSignature::verify($actor_public_key, $signatureData, $headers, $path, $body);
|
[$verified, /*$headers*/] = HTTPSignature::verify($actor_public_key, $signatureData, $headers, $path, $body);
|
||||||
@ -127,15 +130,15 @@ class Inbox extends Controller
|
|||||||
try {
|
try {
|
||||||
$res = Explorer::get_remote_user_activity($ap_actor->getUri());
|
$res = Explorer::get_remote_user_activity($ap_actor->getUri());
|
||||||
if (is_null($res)) {
|
if (is_null($res)) {
|
||||||
return $error('Invalid remote actor.');
|
return $error('Invalid remote actor (null response).');
|
||||||
}
|
}
|
||||||
} catch (Exception) {
|
} catch (Exception $e) {
|
||||||
return $error('Invalid remote actor.');
|
return $error('Invalid remote actor.', $e);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
ActivitypubActor::update_profile($ap_actor, $actor, $activitypub_rsa, $res);
|
ActivitypubActor::update_profile($ap_actor, $actor, $activitypub_rsa, $res);
|
||||||
} catch (Exception) {
|
} catch (Exception $e) {
|
||||||
return $error('Failed to updated remote actor information.');
|
return $error('Failed to updated remote actor information.', $e);
|
||||||
}
|
}
|
||||||
|
|
||||||
[$verified, /*$headers*/] = HTTPSignature::verify($actor_public_key, $signatureData, $headers, $path, $body);
|
[$verified, /*$headers*/] = HTTPSignature::verify($actor_public_key, $signatureData, $headers, $path, $body);
|
||||||
|
@ -38,7 +38,7 @@ use App\Core\GSFile;
|
|||||||
use App\Core\HTTPClient;
|
use App\Core\HTTPClient;
|
||||||
use App\Core\Log;
|
use App\Core\Log;
|
||||||
use App\Core\Router\Router;
|
use App\Core\Router\Router;
|
||||||
use App\Core\Security;
|
use App\Core\UserRoles;
|
||||||
use App\Entity\Actor as GSActor;
|
use App\Entity\Actor as GSActor;
|
||||||
use App\Util\Exception\ServerException;
|
use App\Util\Exception\ServerException;
|
||||||
use App\Util\Formatting;
|
use App\Util\Formatting;
|
||||||
@ -79,8 +79,10 @@ class Actor extends Model
|
|||||||
'nickname' => $person->get('preferredUsername'),
|
'nickname' => $person->get('preferredUsername'),
|
||||||
'fullname' => !empty($person->get('name')) ? $person->get('name') : null,
|
'fullname' => !empty($person->get('name')) ? $person->get('name') : null,
|
||||||
'created' => new DateTime($person->get('published') ?? 'now'),
|
'created' => new DateTime($person->get('published') ?? 'now'),
|
||||||
'bio' => $person->has('summary') ? mb_substr(Security::sanitize($person->get('summary')), 0, 1000) : null,
|
'bio' => $person->get('summary'),
|
||||||
'is_local' => false,
|
'is_local' => false,
|
||||||
|
'type' => GSActor::PERSON,
|
||||||
|
'roles' => UserRoles::USER,
|
||||||
'modified' => new DateTime(),
|
'modified' => new DateTime(),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user