diff --git a/backend/Controllers/UploadController.php b/backend/Controllers/UploadController.php index 523af0f..c65bc5e 100644 --- a/backend/Controllers/UploadController.php +++ b/backend/Controllers/UploadController.php @@ -99,7 +99,7 @@ class UploadController if ($chunks_size >= $total_size) { for ($i = 1; $i <= $total_chunks; ++$i) { $part = $this->tmpfs->readStream($prefix.$file_name.'.part'.$i); - $this->tmpfs->write($file_name, $part['stream']); + $this->tmpfs->write($file_name, $part['stream'], true); } $final = $this->tmpfs->readStream($file_name); diff --git a/backend/Services/Tmpfs/Adapters/Tmpfs.php b/backend/Services/Tmpfs/Adapters/Tmpfs.php index 296666b..adceb0e 100644 --- a/backend/Services/Tmpfs/Adapters/Tmpfs.php +++ b/backend/Services/Tmpfs/Adapters/Tmpfs.php @@ -30,11 +30,17 @@ class Tmpfs implements Service, TmpfsInterface } } - public function write(string $filename, $data) + public function write(string $filename, $data, $append = false) { $filename = $this->sanitizeFilename($filename); - file_put_contents($this->getPath().$filename, $data); + $flags = 0; + + if ($append) { + $flags = FILE_APPEND; + } + + file_put_contents($this->getPath().$filename, $data, $flags); } public function getFileLocation(string $filename): string diff --git a/backend/Services/Tmpfs/TmpfsInterface.php b/backend/Services/Tmpfs/TmpfsInterface.php index d73a5d2..c021df3 100644 --- a/backend/Services/Tmpfs/TmpfsInterface.php +++ b/backend/Services/Tmpfs/TmpfsInterface.php @@ -16,7 +16,7 @@ interface TmpfsInterface public function findAll($pattern): array; - public function write(string $filename, $data); + public function write(string $filename, $data, $append); public function read(string $filename): string; diff --git a/tests/backend/Feature/UploadTest.php b/tests/backend/Feature/UploadTest.php index 9abdca2..36553ed 100644 --- a/tests/backend/Feature/UploadTest.php +++ b/tests/backend/Feature/UploadTest.php @@ -137,6 +137,23 @@ class UploadTest extends TestCase $this->sendRequest('POST', '/upload', $data, $files); $this->assertOk(); + + $this->sendRequest('POST', '/getdir', [ + 'dir' => '/', + ]); + + $this->assertResponseJsonHas([ + 'data' => [ + 'files' => [ + 0 => [ + 'type' => 'file', + 'name' => 'sample.txt', + 'path' => '/sample.txt', + 'size' => 1572864, + ], + ], + ], + ]); } public function testUploadFileBiggerThanAllowed()