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