From d93565fec80b36e8b67a02429d3610175188ba03 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Mon, 28 Aug 2023 22:06:35 +0000 Subject: [PATCH] update --- Controller/ApiController.php | 23 +++++++++++++------ Controller/BackendController.php | 2 +- Models/Media.php | 4 ++-- .../Components/Media/audio_raw.tpl.php | 1 + .../Components/Media/collection_raw.tpl.php | 11 +++++++++ .../Components/Media/image_raw.tpl.php | 1 + .../Backend/Components/Media/json_raw.tpl.php | 6 +++++ .../Components/Media/markdown_raw.tpl.php | 1 + .../Backend/Components/Media/pdf_raw.tpl.php | 1 + .../Backend/Components/Media/text_raw.tpl.php | 3 ++- .../Components/Media/video_raw.tpl.php | 1 + .../Components/Upload/upload-list.tpl.php | 9 +++++++- Views/MediaView.php | 4 ++-- tests/Autoloader.php | 4 +--- 14 files changed, 54 insertions(+), 17 deletions(-) create mode 100644 Theme/Backend/Components/Media/collection_raw.tpl.php create mode 100644 Theme/Backend/Components/Media/json_raw.tpl.php diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 4f56ceb..a9ec43a 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -44,11 +44,9 @@ use phpOMS\Localization\BaseStringL11n; use phpOMS\Message\Http\HttpRequest; use phpOMS\Message\Http\HttpResponse; use phpOMS\Message\Http\RequestStatusCode; -use phpOMS\Message\NotificationLevel; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; use phpOMS\Model\Html\Head; -use phpOMS\Model\Message\FormValidation; use phpOMS\Security\Guard; use phpOMS\System\File\FileUtils; use phpOMS\System\File\Local\Directory; @@ -531,6 +529,8 @@ final class ApiController extends Controller * * @return string * + * @throws \Exception + * * @since 1.0.0 */ public static function normalizeDbPath(string $path) : string @@ -957,6 +957,8 @@ final class ApiController extends Controller * * @api * + * @throws \Exception + * * @since 1.0.0 */ public function apiMediaCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void @@ -1072,8 +1074,8 @@ final class ApiController extends Controller $media->id ) ) { - $this->fillJsonResponse($request, $response, NotificationLevel::HIDDEN, '', '', []); $response->header->status = RequestStatusCode::R_403; + $this->createInvalidReturnResponse($request, $response, $media); return; } @@ -1087,8 +1089,8 @@ final class ApiController extends Controller } } else { if (empty($data) || !isset($data['guard'])) { - $this->fillJsonResponse($request, $response, NotificationLevel::HIDDEN, '', '', []); $response->header->status = RequestStatusCode::R_403; + $this->createInvalidReturnResponse($request, $response, $media); } } @@ -1111,16 +1113,16 @@ final class ApiController extends Controller $media = $this->prepareEncryptedMedia($media, $request); if ($media->id === 0) { - $this->fillJsonResponse($request, $response, NotificationLevel::ERROR, 'Media', 'Media could not be exported. Please try again.', []); $response->header->status = RequestStatusCode::R_500; + $this->createInvalidReturnResponse($request, $response, $media); return; } } - if (!\is_file($media->getAbsolutePath())) { - $this->fillJsonResponse($request, $response, NotificationLevel::ERROR, 'Media', 'Media could not be exported. Please try again.', []); + if ($media->extension !== 'collection' && !\is_file($media->getAbsolutePath())) { $response->header->status = RequestStatusCode::R_500; + $this->createInvalidReturnResponse($request, $response, $media); return; } @@ -1227,11 +1229,15 @@ final class ApiController extends Controller case 'php': case 'js': case 'css': + case 'csv': case 'rs': case 'py': case 'r': $view->setTemplate('/Modules/Media/Theme/Backend/Components/Media/text_raw'); break; + case 'json': + $view->setTemplate('/Modules/Media/Theme/Backend/Components/Media/json_raw'); + break; case 'txt': case 'cfg': case 'log': @@ -1255,6 +1261,9 @@ final class ApiController extends Controller case 'mpeg': $view->setTemplate('/Modules/Media/Theme/Backend/Components/Media/video_raw'); break; + case 'collection': + $view->setTemplate('/Modules/Media/Theme/Backend/Components/Media/collection_raw'); + break; default: $view->setTemplate('/Modules/Media/Theme/Backend/Components/Media/default'); } diff --git a/Controller/BackendController.php b/Controller/BackendController.php index b13849c..971fcbc 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -66,7 +66,7 @@ final class BackendController extends Controller $view = new View($this->app->l11nManager, $request, $response); $view->setTemplate('/Modules/Media/Theme/Backend/media-list'); - $path = \str_replace('+', ' ', (string) ($request->getData('path') ?? '/')); + $path = \str_replace('+', ' ', $request->getDataString('path') ?? '/'); $hasPermission = $this->app->accountManager->get($request->header->account) ->hasPermission( diff --git a/Models/Media.php b/Models/Media.php index 09db6be..0b0837d 100755 --- a/Models/Media.php +++ b/Models/Media.php @@ -380,7 +380,7 @@ class Media implements \JsonSerializable */ public function setPath(string $path) : void { - $this->path = \str_replace('\\', '/', $path); + $this->path = \strtr($path, '\\', '/'); } /** @@ -392,7 +392,7 @@ class Media implements \JsonSerializable */ public function setVirtualPath(string $path) : void { - $this->virtualPath = \str_replace('\\', '/', $path); + $this->virtualPath = \strtr($path, '\\', '/'); } /** diff --git a/Theme/Backend/Components/Media/audio_raw.tpl.php b/Theme/Backend/Components/Media/audio_raw.tpl.php index 6e6c27f..5870bfd 100755 --- a/Theme/Backend/Components/Media/audio_raw.tpl.php +++ b/Theme/Backend/Components/Media/audio_raw.tpl.php @@ -15,6 +15,7 @@ declare(strict_types=1); use phpOMS\Uri\UriFactory; ?> +