Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Lukas Bestle <[email protected]>
  • Loading branch information
distantnative and lukasbestle authored May 25, 2024
1 parent 0f08613 commit 2ba1711
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion config/api/routes/files.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
// move_uploaded_file() not working with unit test
// @codeCoverageIgnoreStart
return $this->upload(function ($source, $filename) use ($path) {
// check if upload is sent in chunks and handle them
// check if upload is sent in chunks and handle them
$source = Upload::chunk($this, $source, $filename);

// complete files return an absolute path;
Expand Down
15 changes: 9 additions & 6 deletions src/Api/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function chunk(
$offset = (int)$api->requestHeaders('Upload-Offset');

// validate various aspects of the request
// to ensure the chunk isn't try to do malicious actions
// to ensure the chunk isn't trying to do malicious actions
static::validateChunk(
source: $source,
tmp: $tmpWithId,
Expand Down Expand Up @@ -193,15 +193,18 @@ protected static function validateChunk(
if ($offset !== F::size($tmp)) {
throw new Exception('Chunk offset ' . $offset . ' does not match the existing tmp upload file size of ' . F::size($tmp));
}
} elseif ($offset > 0) {
// sent chunk is not expected to be the first part,
// but no tmp file to continue exists yet
throw new NotFoundException('Chunk offset ' . $offset . ' for non-existing tmp file: ' . $name);
} elseif ($offset === 0) {

// existing file is valid, done validating
return;
}

if ($offset === 0) {
// validate file (extension, name) for first chunk;
// will also be validate again by `$model->createFile()`
// when completely uploaded
FileRules::validFile($file, false);
}

throw new NotFoundException('Chunk offset ' . $offset . ' for non-existing tmp file: ' . $name);
}
}

0 comments on commit 2ba1711

Please sign in to comment.