mirror of
https://github.com/filegator/filegator.git
synced 2025-08-06 21:06:49 +02:00
show filesize and remaining time on download (#181)
* show filesize on download
This commit is contained in:
@@ -91,7 +91,12 @@ class DownloadController
|
||||
'Content-Transfer-Encoding',
|
||||
'binary'
|
||||
);
|
||||
|
||||
if (isset($file['filesize'])) {
|
||||
$streamedResponse->headers->set(
|
||||
'Content-Length',
|
||||
$file['filesize']
|
||||
);
|
||||
}
|
||||
// @codeCoverageIgnoreStart
|
||||
if (APP_ENV == 'development') {
|
||||
$streamedResponse->headers->set(
|
||||
@@ -137,11 +142,11 @@ class DownloadController
|
||||
public function batchDownloadStart(Request $request, StreamedResponse $streamedResponse, TmpfsInterface $tmpfs)
|
||||
{
|
||||
$uniqid = (string) preg_replace('/[^0-9a-zA-Z_]/', '', (string) $request->input('uniqid'));
|
||||
$file = $tmpfs->readStream($uniqid);
|
||||
|
||||
$streamedResponse->setCallback(function () use ($tmpfs, $uniqid) {
|
||||
$streamedResponse->setCallback(function () use ($file, $tmpfs, $uniqid) {
|
||||
// @codeCoverageIgnoreStart
|
||||
set_time_limit(0);
|
||||
$file = $tmpfs->readStream($uniqid);
|
||||
if ($file['stream']) {
|
||||
while (! feof($file['stream'])) {
|
||||
echo fread($file['stream'], 1024 * 8);
|
||||
@@ -170,7 +175,12 @@ class DownloadController
|
||||
'Content-Transfer-Encoding',
|
||||
'binary'
|
||||
);
|
||||
|
||||
if (isset($file['filesize'])) {
|
||||
$streamedResponse->headers->set(
|
||||
'Content-Length',
|
||||
$file['filesize']
|
||||
);
|
||||
}
|
||||
// close session so we can continue streaming, note: dev is single-threaded
|
||||
$this->session->save();
|
||||
|
||||
|
@@ -134,6 +134,7 @@ class Filesystem implements Service
|
||||
return [
|
||||
'filename' => $this->getBaseName($path),
|
||||
'stream' => $this->storage->readStream($path),
|
||||
'filesize' => $this->storage->getSize($path),
|
||||
];
|
||||
}
|
||||
|
||||
|
@@ -62,10 +62,12 @@ class Tmpfs implements Service, TmpfsInterface
|
||||
$filename = $this->sanitizeFilename($filename);
|
||||
|
||||
$stream = fopen($this->getPath().$filename, 'r');
|
||||
$filesize = filesize($this->getPath().$filename);
|
||||
|
||||
return [
|
||||
'filename' => $filename,
|
||||
'stream' => $stream,
|
||||
'filesize' => $filesize,
|
||||
];
|
||||
}
|
||||
|
||||
|
@@ -155,6 +155,7 @@ class FilesTest extends TestCase
|
||||
|
||||
mkdir(TEST_REPOSITORY.'/john');
|
||||
touch(TEST_REPOSITORY.'/john/john.txt', $this->timestamp);
|
||||
file_put_contents(TEST_REPOSITORY.'/john/john.txt', '123456');
|
||||
touch(TEST_REPOSITORY.'/john/image.jpg', $this->timestamp);
|
||||
touch(TEST_REPOSITORY.'/john/vector.svg', $this->timestamp);
|
||||
touch(TEST_REPOSITORY.'/john/inlinedoc.pdf', $this->timestamp);
|
||||
@@ -165,6 +166,7 @@ class FilesTest extends TestCase
|
||||
$this->assertEquals($headers->get('content-disposition'), "attachment; filename=file; filename*=utf-8''john.txt");
|
||||
$this->assertEquals($headers->get('content-type'), 'text/plain');
|
||||
$this->assertEquals($headers->get('content-transfer-encoding'), 'binary');
|
||||
$this->assertEquals($headers->get('content-length'), 6);
|
||||
$this->assertOk();
|
||||
|
||||
$path_encoded = base64_encode('image.jpg');
|
||||
@@ -173,6 +175,7 @@ class FilesTest extends TestCase
|
||||
$this->assertEquals($headers->get('content-disposition'), "attachment; filename=file; filename*=utf-8''image.jpg");
|
||||
$this->assertEquals($headers->get('content-type'), 'image/jpeg');
|
||||
$this->assertEquals($headers->get('content-transfer-encoding'), 'binary');
|
||||
$this->assertEquals($headers->get('content-length'), 0);
|
||||
$this->assertOk();
|
||||
|
||||
$path_encoded = base64_encode('vector.svg');
|
||||
@@ -181,6 +184,7 @@ class FilesTest extends TestCase
|
||||
$this->assertEquals($headers->get('content-disposition'), "attachment; filename=file; filename*=utf-8''vector.svg");
|
||||
$this->assertEquals($headers->get('content-type'), 'image/svg+xml');
|
||||
$this->assertEquals($headers->get('content-transfer-encoding'), 'binary');
|
||||
$this->assertEquals($headers->get('content-length'), 0);
|
||||
$this->assertOk();
|
||||
|
||||
$path_encoded = base64_encode('inlinedoc.pdf');
|
||||
@@ -189,6 +193,7 @@ class FilesTest extends TestCase
|
||||
$this->assertEquals($headers->get('content-disposition'), "inline; filename=file; filename*=utf-8''inlinedoc.pdf");
|
||||
$this->assertEquals($headers->get('content-type'), 'application/pdf');
|
||||
$this->assertEquals($headers->get('content-transfer-encoding'), 'binary');
|
||||
$this->assertEquals($headers->get('content-length'), 0);
|
||||
$this->assertOk();
|
||||
}
|
||||
|
||||
@@ -207,6 +212,7 @@ class FilesTest extends TestCase
|
||||
$this->assertEquals($headers->get('content-disposition'), "inline; filename=file; filename*=utf-8''john.pdf");
|
||||
$this->assertEquals($headers->get('content-type'), 'application/pdf');
|
||||
$this->assertEquals($headers->get('content-transfer-encoding'), 'binary');
|
||||
$this->assertEquals($headers->get('content-length'), 0);
|
||||
|
||||
$this->assertOk();
|
||||
}
|
||||
@@ -634,6 +640,14 @@ class FilesTest extends TestCase
|
||||
]);
|
||||
|
||||
$this->assertOk();
|
||||
|
||||
// test headers
|
||||
$this->response->getContent();
|
||||
$headers = $this->streamedResponse->headers;
|
||||
$this->assertEquals($headers->get('content-type'), 'application/octet-stream');
|
||||
$this->assertEquals($headers->get('content-disposition'), 'attachment; filename=archive.zip');
|
||||
$this->assertEquals($headers->get('content-transfer-encoding'), 'binary');
|
||||
$this->assertEquals($headers->get('content-length'), 414);
|
||||
}
|
||||
|
||||
public function testUpdateFileContent()
|
||||
|
Reference in New Issue
Block a user