Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
UpdateUploadEndpoint | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
handle | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Olz\Api\Endpoints; |
4 | |
5 | use Olz\Api\OlzTypedEndpoint; |
6 | |
7 | /** |
8 | * @extends OlzTypedEndpoint< |
9 | * array{ |
10 | * id: non-empty-string, |
11 | * part: int<0, 1000>, |
12 | * content: non-empty-string, |
13 | * }, |
14 | * array{ |
15 | * status: 'OK'|'ERROR', |
16 | * } |
17 | * > |
18 | */ |
19 | class UpdateUploadEndpoint extends OlzTypedEndpoint { |
20 | protected function handle(mixed $input): mixed { |
21 | $this->checkPermission('any'); |
22 | |
23 | $data_path = $this->envUtils()->getDataPath(); |
24 | $upload_id = $input['id']; |
25 | $upload_path = "{$data_path}temp/{$upload_id}"; |
26 | if (!is_file($upload_path)) { |
27 | $this->log()->error("Could not update upload. Invalid ID: '{$upload_id}'."); |
28 | return ['status' => 'ERROR']; |
29 | } |
30 | |
31 | $part = $input['part']; |
32 | $part_path = "{$upload_path}_{$part}"; |
33 | |
34 | $content = $this->uploadUtils()->deobfuscateUpload($input['content']); |
35 | file_put_contents($part_path, $content); |
36 | |
37 | return ['status' => 'OK']; |
38 | } |
39 | } |