From 850c84b53824b068f733d856896e90a8dc6d6da3 Mon Sep 17 00:00:00 2001 From: ghost Date: Sun, 4 Feb 2024 10:30:19 +0200 Subject: [PATCH] add media content support --- src/server.php | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/server.php b/src/server.php index af45ab1..8f90471 100644 --- a/src/server.php +++ b/src/server.php @@ -128,7 +128,7 @@ foreach ($filesystem->getList() as $path) if ($uri = $filesystem->getPageUriByPath($path)) { - if ($data = $filesystem->getData($path)) + if ($data = $filesystem->getDataByPath($path)) { $gemini = $reader->toGemini( $data @@ -401,7 +401,7 @@ $server->setHandler( // Convert $gemini = $reader->toGemini( - $filesystem->getData( + $filesystem->getDataByPath( $path ) ); @@ -511,7 +511,7 @@ $server->setHandler( { $h1[] = $reader->getH1( $reader->toGemini( - $filesystem->getData( + $filesystem->getDataByPath( $file ) ) @@ -523,7 +523,7 @@ $server->setHandler( { $h1[] = $reader->getH1( $reader->toGemini( - $filesystem->getData( + $filesystem->getDataByPath( $file ) ) @@ -616,6 +616,29 @@ $server->setHandler( return $response; } + + // Media request + else if ($path = $filesystem->getMediaPathByUri($_uri)) + { + if ($mime = $filesystem->getMimeByPath($path)) + { + if ($data = $filesystem->getDataByPath($path)) + { + // Set MIME + $response->setMeta( + $mime + ); + + // Append data + $response->setContent( + $data + ); + + // Response + return $response; + } + } + } } // Route not found