Skip to content

Commit d4e30d2

Browse files
committed
feat(files): add mime icon endpoint
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent 4dff3b7 commit d4e30d2

File tree

5 files changed

+583
-1
lines changed

5 files changed

+583
-1
lines changed

apps/files/openapi.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2330,11 +2330,16 @@
23302330
"data": {
23312331
"type": "object",
23322332
"required": [
2333-
"path"
2333+
"path",
2334+
"fileId"
23342335
],
23352336
"properties": {
23362337
"path": {
23372338
"type": "string"
2339+
},
2340+
"fileId": {
2341+
"type": "integer",
2342+
"format": "int64"
23382343
}
23392344
}
23402345
}

core/Controller/PreviewController.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
1515
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
1616
use OCP\AppFramework\Http\Attribute\OpenAPI;
17+
use OCP\AppFramework\Http\Attribute\PublicPage;
1718
use OCP\AppFramework\Http\DataResponse;
1819
use OCP\AppFramework\Http\FileDisplayResponse;
1920
use OCP\AppFramework\Http\RedirectResponse;
@@ -183,4 +184,25 @@ private function fetchPreview(
183184
return new DataResponse([], Http::STATUS_BAD_REQUEST);
184185
}
185186
}
187+
188+
/**
189+
* Get a preview by mime
190+
*
191+
* @param string $mime Mime type
192+
* @return RedirectResponse<Http::STATUS_SEE_OTHER, array{}>
193+
*
194+
* 303: The mime icon url
195+
*/
196+
#[NoCSRFRequired]
197+
#[PublicPage]
198+
#[FrontpageRoute(verb: 'GET', url: '/core/mimeicon')]
199+
#[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT)]
200+
public function getMimeIconUrl(string $mime = 'application/octet-stream') {
201+
$url = $this->mimeIconProvider->getMimeIconUrl($mime);
202+
if ($url === null) {
203+
$url = $this->mimeIconProvider->getMimeIconUrl('application/octet-stream');
204+
}
205+
206+
return new RedirectResponse($url);
207+
}
186208
}

0 commit comments

Comments
 (0)