-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathListAuxData.php
More file actions
114 lines (105 loc) · 3.06 KB
/
Copy pathListAuxData.php
File metadata and controls
114 lines (105 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
declare(strict_types=1);
namespace FediE2EE\PKDServer\RequestHandlers\Api;
use DateMalformedStringException;
use FediE2EE\PKD\Crypto\Exceptions\{
CryptoException,
JsonException,
NotImplementedException
};
use FediE2EE\PKDServer\{
Exceptions\CacheException,
Exceptions\DependencyException,
Exceptions\TableException,
Meta\Route,
Redirect,
Traits\ReqTrait
};
use FediE2EE\PKDServer\Tables\{
Actors,
AuxData
};
use Override;
use ParagonIE\CipherSweet\Exception\{
ArrayKeyException,
BlindIndexNotFoundException,
CipherSweetException,
CryptoOperationException,
InvalidCiphertextException
};
use Psr\Http\Message\{
ResponseInterface,
ServerRequestInterface
};
use Psr\Http\Server\RequestHandlerInterface;
use SodiumException;
use Throwable;
use TypeError;
use function is_null;
class ListAuxData implements RequestHandlerInterface
{
use ReqTrait;
protected Actors $actorsTable;
protected AuxData $auxDataTable;
/**
* @throws CacheException
* @throws DependencyException
* @throws TableException
*/
public function __construct()
{
$actorsTable = $this->table('Actors');
if (!($actorsTable instanceof Actors)) {
throw new TypeError('Could not load Actors table at runtime');
}
$this->actorsTable = $actorsTable;
$dataTable = $this->table('AuxData');
if (!($dataTable instanceof AuxData)) {
throw new TypeError('Could not load AuxData table at runtime');
}
$this->auxDataTable = $dataTable;
}
/**
* @api
*
* @throws ArrayKeyException
* @throws BlindIndexNotFoundException
* @throws CipherSweetException
* @throws CryptoOperationException
* @throws DependencyException
* @throws InvalidCiphertextException
* @throws JsonException
* @throws NotImplementedException
* @throws SodiumException
* @throws TableException
* @throws DateMalformedStringException
* @throws CryptoException
*/
#[Route("api/actor/{actor_id}/auxiliary")]
#[Override]
public function handle(ServerRequestInterface $request): ResponseInterface
{
// If no Actor ID is given, redirect.
$actorID = $request->getAttribute('actor_id') ?? '';
if (empty($actorID)) {
return (new Redirect('/api'))->respond();
}
// Resolve canonical Actor ID
try {
$actorID = $this->webfinger()->canonicalize($actorID);
} catch (Throwable $ex) {
return $this->error('A WebFinger error occurred: ' . $ex->getMessage());
}
// Ensure actor exists
$actor = $this->actorsTable->searchForActor($actorID);
if (is_null($actor)) {
return $this->error('Actor not found', 404);
}
$auxData = $this->auxDataTable->getAuxDataForActor($actor->getPrimaryKey());
return $this->json([
'!pkd-context' => 'fedi-e2ee:v1/api/actor/aux-info',
'actor-id' => $actorID,
'auxiliary' => $auxData
]);
}
}