Update FederationController

This commit is contained in:
Daniel Supernault 2022-04-26 20:36:08 -06:00
parent 3172cb59cd
commit cb2392f351
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
2 changed files with 34 additions and 9 deletions

View File

@ -121,6 +121,23 @@ class FederationController extends Controller
$obj = json_decode($payload, true, 8);
if(isset($obj['type']) && $obj['type'] === 'Delete') {
if(!isset($obj['id'])) {
return;
}
$lockKey = 'pf:ap:del-lock:' . hash('sha256', $obj['id']);
if( isset($obj['actor']) &&
isset($obj['object']) &&
isset($obj['id']) &&
is_string($obj['id']) &&
is_string($obj['actor']) &&
is_string($obj['object']) &&
$obj['actor'] == $obj['object']
) {
if(Cache::get($lockKey) !== null) {
return;
}
}
Cache::put($lockKey, 1, 3600);
dispatch(new DeleteWorker($headers, $payload))->onQueue('delete');
} else {
dispatch(new InboxValidator($username, $headers, $payload))->onQueue('high');
@ -138,6 +155,23 @@ class FederationController extends Controller
$obj = json_decode($payload, true, 8);
if(isset($obj['type']) && $obj['type'] === 'Delete') {
if(!isset($obj['id'])) {
return;
}
$lockKey = 'pf:ap:del-lock:' . hash('sha256', $obj['id']);
if( isset($obj['actor']) &&
isset($obj['object']) &&
isset($obj['id']) &&
is_string($obj['id']) &&
is_string($obj['actor']) &&
is_string($obj['object']) &&
$obj['actor'] == $obj['object']
) {
if(Cache::get($lockKey) !== null) {
return;
}
}
Cache::put($lockKey, 1, 3600);
dispatch(new DeleteWorker($headers, $payload))->onQueue('delete');
} else {
dispatch(new InboxWorker($headers, $payload))->onQueue('high');

View File

@ -49,15 +49,6 @@ class DeleteWorker implements ShouldQueue
$headers = $this->headers;
$payload = json_decode($this->payload, true, 8);
if(isset($payload['id'])) {
$lockKey = 'pf:ap:del-lock:' . hash('sha256', $payload['id']);
if(Cache::get($lockKey) !== null) {
// Job processed already
return 1;
}
Cache::put($lockKey, 1, 300);
}
if(!isset($headers['signature']) || !isset($headers['date'])) {
return;
}