From 6d9404014d4b83e3750c8146188d005cea66b19e Mon Sep 17 00:00:00 2001 From: skjnldsv Date: Fri, 10 Jan 2025 11:57:08 +0100 Subject: [PATCH] feat(files): add mime icon endpoint Signed-off-by: skjnldsv --- core/Controller/PreviewController.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/core/Controller/PreviewController.php b/core/Controller/PreviewController.php index 9c9d49082bb60..20e02d0548356 100644 --- a/core/Controller/PreviewController.php +++ b/core/Controller/PreviewController.php @@ -14,6 +14,7 @@ use OCP\AppFramework\Http\Attribute\NoAdminRequired; use OCP\AppFramework\Http\Attribute\NoCSRFRequired; use OCP\AppFramework\Http\Attribute\OpenAPI; +use OCP\AppFramework\Http\Attribute\PublicPage; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\FileDisplayResponse; use OCP\AppFramework\Http\RedirectResponse; @@ -183,4 +184,24 @@ private function fetchPreview( return new DataResponse([], Http::STATUS_BAD_REQUEST); } } + + /** + * Get a preview by mime + * + * @return RedirectResponse + * + * 303: The mime icon url + */ + #[NoCSRFRequired] + #[PublicPage] + #[FrontpageRoute(verb: 'GET', url: '/core/mimeicon')] + #[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT)] + public function getMimeIconUrl(string $mime = 'application/octet-stream') { + $url = $this->mimeIconProvider->getMimeIconUrl($mime); + if ($url === null) { + $url = $this->mimeIconProvider->getMimeIconUrl('application/octet-stream'); + } + + return new RedirectResponse($url); + } }