1
0
Fork 0
mirror of synced 2024-10-02 02:07:04 +13:00

some fixes

This commit is contained in:
shimon 2022-08-15 15:16:32 +03:00
parent edecd8dc22
commit 67d12d3120
3 changed files with 24 additions and 17 deletions

View file

@ -355,8 +355,8 @@ App::post('/v1/storage/buckets/:bucketId/files')
->inject('mode') ->inject('mode')
->inject('deviceFiles') ->inject('deviceFiles')
->inject('deviceLocal') ->inject('deviceLocal')
->inject('project') ->inject('deletes')
->action(function (string $bucketId, string $fileId, mixed $file, ?array $read, ?array $write, Request $request, Response $response, Database $dbForProject, Document $user, Audit $audits, Stats $usage, Event $events, string $mode, Device $deviceFiles, Device $deviceLocal, Document $project) { ->action(function (string $bucketId, string $fileId, mixed $file, ?array $read, ?array $write, Request $request, Response $response, Database $dbForProject, Document $user, Audit $audits, Stats $usage, Event $events, string $mode, Device $deviceFiles, Device $deviceLocal, Delete $deletes) {
$bucket = Authorization::skip(fn () => $dbForProject->getDocument('buckets', $bucketId)); $bucket = Authorization::skip(fn () => $dbForProject->getDocument('buckets', $bucketId));
if ( if (
@ -655,6 +655,11 @@ App::post('/v1/storage/buckets/:bucketId/files')
->setContext('bucket', $bucket) ->setContext('bucket', $bucket)
; ;
$deletes
->setType(DELETE_TYPE_CACHE_BY_RESOURCE)
->setResource('file/' . $file->getId())
;
$metadata = null; // was causing leaks as it was passed by reference $metadata = null; // was causing leaks as it was passed by reference
$response->setStatusCode(Response::STATUS_CODE_CREATED); $response->setStatusCode(Response::STATUS_CODE_CREATED);
@ -1419,7 +1424,6 @@ App::delete('/v1/storage/buckets/:bucketId/files/:fileId')
if ($deviceDeleted) { if ($deviceDeleted) {
$deletes $deletes
->setType(DELETE_TYPE_CACHE_BY_RESOURCE)
->setType(DELETE_TYPE_CACHE_BY_RESOURCE) ->setType(DELETE_TYPE_CACHE_BY_RESOURCE)
->setResource('file/' . $fileId) ->setResource('file/' . $fileId)
; ;

View file

@ -133,7 +133,6 @@ App::init()
$cache = new Cache(new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $project->getId())); $cache = new Cache(new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $project->getId()));
$timestamp = 60 * 60 * 24 * 30; $timestamp = 60 * 60 * 24 * 30;
$data = $cache->load($key, $timestamp); $data = $cache->load($key, $timestamp);
if (!empty($data)) { if (!empty($data)) {
$cacheLog = Authorization::skip(fn() => $dbForProject->getDocument('cache', $key)); $cacheLog = Authorization::skip(fn() => $dbForProject->getDocument('cache', $key));
@ -366,10 +365,14 @@ App::shutdown()
Authorization::skip(fn () => $dbForProject->updateDocument('cache', $cacheLog->getId(), $cacheLog)); Authorization::skip(fn () => $dbForProject->updateDocument('cache', $cacheLog->getId(), $cacheLog));
} }
$cache = new Cache(new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $project->getId())); if ($signature !== $cacheLog->getAttribute('signature')) {
$cache = new Cache(
new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $project->getId())
);
$cache->save($key, $data); $cache->save($key, $data);
} }
} }
}
if ( if (
App::getEnv('_APP_USAGE_STATS', 'enabled') == 'enabled' App::getEnv('_APP_USAGE_STATS', 'enabled') == 'enabled'

View file

@ -490,7 +490,7 @@ trait StorageBase
$this->assertEquals(204, $file['headers']['status-code']); $this->assertEquals(204, $file['headers']['status-code']);
$this->assertEmpty($file['body']); $this->assertEmpty($file['body']);
sleep(10); sleep(1);
//upload again using the same ID //upload again using the same ID
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', array_merge([ $file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', array_merge([
'content-type' => 'multipart/form-data', 'content-type' => 'multipart/form-data',