mirror of
https://github.com/filegator/filegator.git
synced 2025-08-06 15:36:40 +02:00
@@ -20,6 +20,7 @@ use Filegator\Services\Session\SessionStorageInterface as Session;
|
|||||||
use Filegator\Services\Storage\Filesystem;
|
use Filegator\Services\Storage\Filesystem;
|
||||||
use Filegator\Services\Tmpfs\TmpfsInterface;
|
use Filegator\Services\Tmpfs\TmpfsInterface;
|
||||||
use Symfony\Component\HttpFoundation\HeaderUtils;
|
use Symfony\Component\HttpFoundation\HeaderUtils;
|
||||||
|
use Symfony\Component\Mime\MimeTypes;
|
||||||
|
|
||||||
class DownloadController
|
class DownloadController
|
||||||
{
|
{
|
||||||
@@ -65,14 +66,17 @@ class DownloadController
|
|||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
});
|
});
|
||||||
|
|
||||||
$contentDisposition = HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, $file['filename'], 'file');
|
$mimes = (new MimeTypes())->getMimeTypes(pathinfo($file['filename'], PATHINFO_EXTENSION));
|
||||||
$contentType = 'application/octet-stream';
|
$contentType = !empty($mimes) ? $mimes[0] : 'application/octet-stream';
|
||||||
|
|
||||||
if (pathinfo($file['filename'], PATHINFO_EXTENSION) == 'pdf') {
|
$disposition = HeaderUtils::DISPOSITION_ATTACHMENT;
|
||||||
$contentDisposition = HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_INLINE, $file['filename'], 'file');
|
|
||||||
$contentType = 'application/pdf';
|
if ($contentType == 'application/pdf') {
|
||||||
|
$disposition = HeaderUtils::DISPOSITION_INLINE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$contentDisposition = HeaderUtils::makeDisposition($disposition, $file['filename'], 'file');
|
||||||
|
|
||||||
$streamedResponse->headers->set(
|
$streamedResponse->headers->set(
|
||||||
'Content-Disposition',
|
'Content-Disposition',
|
||||||
$contentDisposition
|
$contentDisposition
|
||||||
|
@@ -135,7 +135,7 @@ const funcs = {
|
|||||||
return this.hasExtension(name, store.state.config.editable ? store.state.config.editable : ['.txt'])
|
return this.hasExtension(name, store.state.config.editable ? store.state.config.editable : ['.txt'])
|
||||||
},
|
},
|
||||||
isImage(name) {
|
isImage(name) {
|
||||||
return this.hasExtension(name, ['.jpg', '.jpeg', '.gif', '.png', '.bmp', '.tiff', '.tif'])
|
return this.hasExtension(name, ['.jpg', '.jpeg', '.gif', '.png', '.bmp', '.svg', '.tiff', '.tif'])
|
||||||
},
|
},
|
||||||
hasExtension(name, exts) {
|
hasExtension(name, exts) {
|
||||||
return (new RegExp('(' + exts.join('|').replace(/\./g, '\\.') + ')$', 'i')).test(name)
|
return (new RegExp('(' + exts.join('|').replace(/\./g, '\\.') + ')$', 'i')).test(name)
|
||||||
|
@@ -155,15 +155,40 @@ class FilesTest extends TestCase
|
|||||||
|
|
||||||
mkdir(TEST_REPOSITORY.'/john');
|
mkdir(TEST_REPOSITORY.'/john');
|
||||||
touch(TEST_REPOSITORY.'/john/john.txt', $this->timestamp);
|
touch(TEST_REPOSITORY.'/john/john.txt', $this->timestamp);
|
||||||
|
touch(TEST_REPOSITORY.'/john/image.jpg', $this->timestamp);
|
||||||
|
touch(TEST_REPOSITORY.'/john/vector.svg', $this->timestamp);
|
||||||
|
touch(TEST_REPOSITORY.'/john/inlinedoc.pdf', $this->timestamp);
|
||||||
|
|
||||||
$path_encoded = base64_encode('john.txt');
|
$path_encoded = base64_encode('john.txt');
|
||||||
$this->sendRequest('GET', '/download&path='.$path_encoded);
|
$this->sendRequest('GET', '/download&path='.$path_encoded);
|
||||||
|
|
||||||
$headers = $this->streamedResponse->headers;
|
$headers = $this->streamedResponse->headers;
|
||||||
$this->assertEquals($headers->get('content-disposition'), "attachment; filename=file; filename*=utf-8''john.txt");
|
$this->assertEquals($headers->get('content-disposition'), "attachment; filename=file; filename*=utf-8''john.txt");
|
||||||
$this->assertEquals($headers->get('content-type'), 'application/octet-stream');
|
$this->assertEquals($headers->get('content-type'), 'text/plain');
|
||||||
$this->assertEquals($headers->get('content-transfer-encoding'), 'binary');
|
$this->assertEquals($headers->get('content-transfer-encoding'), 'binary');
|
||||||
|
$this->assertOk();
|
||||||
|
|
||||||
|
$path_encoded = base64_encode('image.jpg');
|
||||||
|
$this->sendRequest('GET', '/download&path='.$path_encoded);
|
||||||
|
$headers = $this->streamedResponse->headers;
|
||||||
|
$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->assertOk();
|
||||||
|
|
||||||
|
$path_encoded = base64_encode('vector.svg');
|
||||||
|
$this->sendRequest('GET', '/download&path='.$path_encoded);
|
||||||
|
$headers = $this->streamedResponse->headers;
|
||||||
|
$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->assertOk();
|
||||||
|
|
||||||
|
$path_encoded = base64_encode('inlinedoc.pdf');
|
||||||
|
$this->sendRequest('GET', '/download&path='.$path_encoded);
|
||||||
|
$headers = $this->streamedResponse->headers;
|
||||||
|
$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->assertOk();
|
$this->assertOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user