From 3b93044062f23ce6953bf2289273f7462f0087d7 Mon Sep 17 00:00:00 2001 From: Chris Kankiewicz Date: Mon, 16 Dec 2019 21:23:48 -0700 Subject: [PATCH] Added /file-info path for retrieving file hashes and more in the future --- app/Controllers/FileInfoController.php | 35 ++++++++++++++++++++++++++ index.php | 1 + 2 files changed, 36 insertions(+) create mode 100644 app/Controllers/FileInfoController.php diff --git a/app/Controllers/FileInfoController.php b/app/Controllers/FileInfoController.php new file mode 100644 index 0000000..1ecd785 --- /dev/null +++ b/app/Controllers/FileInfoController.php @@ -0,0 +1,35 @@ +getBody()->write(json_encode([ + 'hashes' => [ + 'md5' => hash('md5', file_get_contents($file->getPathname())), + 'sha1' => hash('sha1', file_get_contents($file->getPathname())), + 'sha256' => hash('sha256', file_get_contents($file->getPathname())), + ] + ])); + + return $response->withHeader('Content-Type', 'application/json'); + } +} diff --git a/index.php b/index.php index 8fb0728..9cd22a9 100644 --- a/index.php +++ b/index.php @@ -27,6 +27,7 @@ $container->call(Bootstrap\ViewComposer::class); $app = Bridge::create($container); // Register routes +$app->get('/file-info/[{path:.*}]', Controllers\FileInfoController::class); $app->get('/[{path:.*}]', Controllers\DirectoryController::class); // Enagage!