Skip to content

Commit

Permalink
Merge pull request #9 from bedita/fix/remove-file-checksum-error
Browse files Browse the repository at this point in the history
Remove uploaded file after checksum error
  • Loading branch information
batopa authored Aug 2, 2023
2 parents df58358 + d3e415c commit 3d9ae7c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Http/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ class Server extends TusServer
*/
public const BEDITA_OBJECT_TYPE_HEADER = 'BEdita-Object-Type';

/**
* Checksum Mismatch status code
*
* @var int
*/
public const HTTP_CHECKSUM_MISMATCH = 460;

/**
* Update cache with info about bedita object created.
*
Expand Down Expand Up @@ -97,4 +104,21 @@ protected function handleHead(): HttpResponse

return parent::handleHead();
}

/**
* {@inheritDoc}
*
* Make sure file is removed if a checksum error response is sent.
*/
protected function handlePatch(): HttpResponse
{
$response = parent::handlePatch();
if ($response->getStatusCode() === static::HTTP_CHECKSUM_MISMATCH) {
$meta = $this->cache->get($this->request->key());
$resource = $meta['file_path'] ?? null;
unlink($resource);
}

return $response;
}
}

0 comments on commit 3d9ae7c

Please sign in to comment.