From b6830c1d49314719b5ddc290548f6f130999d0c5 Mon Sep 17 00:00:00 2001 From: Chris Kankiewicz Date: Sun, 22 Dec 2019 01:17:16 -0700 Subject: [PATCH] Implemented file info modal --- app/Controllers/FileInfoController.php | 20 +- app/config/app.php | 8 + app/themes/default/components/file.twig | 67 +- app/themes/default/index.twig | 18 +- app/themes/default/package-lock.json | 4635 +++++++++-------- app/themes/default/package.json | 11 +- app/themes/default/src/js/app.js | 21 + .../src/js/components/file-info-modal.vue | 86 + app/themes/default/tailwind.config.js | 14 +- 9 files changed, 2710 insertions(+), 2170 deletions(-) create mode 100644 app/themes/default/src/js/components/file-info-modal.vue diff --git a/app/Controllers/FileInfoController.php b/app/Controllers/FileInfoController.php index 1ecd785..1d75724 100644 --- a/app/Controllers/FileInfoController.php +++ b/app/Controllers/FileInfoController.php @@ -2,12 +2,25 @@ namespace App\Controllers; -use RuntimeException; +use PHLAK\Config\Config; use Slim\Psr7\Response; use SplFileInfo; class FileInfoController { + /** @var Config App configuration component */ + protected $config; + + /** + * Create a new FileInfoController object. + * + * @param \PHLAK\Config\Config $config + */ + public function __construct(Config $config) + { + $this->config = $config; + } + /** * Invoke the FileInfoController. * @@ -17,10 +30,13 @@ class FileInfoController public function __invoke(Response $response, string $path = '.') { if (! is_file($path)) { - throw new RuntimeException('Invalid file path', $path); + return $response->withStatus(404, 'File not found'); } $file = new SplFileInfo($path); + if ($file->getSize() >= $this->config->get('max_hash_size', 1000000000)) { + return $response->withStatus(500, 'File size too large'); + } $response->getBody()->write(json_encode([ 'hashes' => [ diff --git a/app/config/app.php b/app/config/app.php index c9d940b..7cb20fe 100644 --- a/app/config/app.php +++ b/app/config/app.php @@ -53,4 +53,12 @@ return [ * Default value: true */ 'ignore_vcs_files' => true, + + /** + * The maximum file size (in bytes) that can be hashed. This helps to + * prevent timeouts for excessively large files. + * + * Defualt value: 1000000000 + */ + 'max_hash_size' => 1000000000 ]; diff --git a/app/themes/default/components/file.twig b/app/themes/default/components/file.twig index 6e43096..5e4a5d7 100644 --- a/app/themes/default/components/file.twig +++ b/app/themes/default/components/file.twig @@ -1,36 +1,45 @@ -
- {% if parentDir %} - - {% else %} - {{ icon(file) | raw }} - {% endif %} -
+
+
+ {% if parentDir %} + + {% else %} + {{ icon(file) | raw }} + {% endif %} +
-
- {% if parentDir %} - .. - {% else %} - {{ file.getBasename }} - {% endif %} -
+
+
+
+ {{ parentDir ? '..' : file.getBasename }} +
- + {% if file.isFile %} +
+ +
+ {% endif %} +
+
-
diff --git a/app/themes/default/index.twig b/app/themes/default/index.twig index ad90627..f6f9f19 100644 --- a/app/themes/default/index.twig +++ b/app/themes/default/index.twig @@ -2,11 +2,13 @@ + Directory Lister -
+
+