aboutsummaryrefslogtreecommitdiffstats
path: root/core/Controller/PreviewController.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/Controller/PreviewController.php')
-rw-r--r--core/Controller/PreviewController.php37
1 files changed, 30 insertions, 7 deletions
diff --git a/core/Controller/PreviewController.php b/core/Controller/PreviewController.php
index 2720da671be..aac49c06d57 100644
--- a/core/Controller/PreviewController.php
+++ b/core/Controller/PreviewController.php
@@ -13,9 +13,12 @@ use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
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;
+use OCP\AppFramework\Http\Response;
use OCP\Files\File;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
@@ -58,6 +61,7 @@ class PreviewController extends Controller {
#[NoAdminRequired]
#[NoCSRFRequired]
#[FrontpageRoute(verb: 'GET', url: '/core/preview.png')]
+ #[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT)]
public function getPreview(
string $file = '',
int $x = 32,
@@ -65,7 +69,7 @@ class PreviewController extends Controller {
bool $a = false,
bool $forceIcon = true,
string $mode = 'fill',
- bool $mimeFallback = false): Http\Response {
+ bool $mimeFallback = false): Response {
if ($file === '' || $x === 0 || $y === 0) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
@@ -101,6 +105,7 @@ class PreviewController extends Controller {
#[NoAdminRequired]
#[NoCSRFRequired]
#[FrontpageRoute(verb: 'GET', url: '/core/preview')]
+ #[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT)]
public function getPreviewByFileId(
int $fileId = -1,
int $x = 32,
@@ -133,7 +138,7 @@ class PreviewController extends Controller {
bool $a,
bool $forceIcon,
string $mode,
- bool $mimeFallback = false) : Http\Response {
+ bool $mimeFallback = false) : Response {
if (!($node instanceof File) || (!$forceIcon && !$this->preview->isAvailable($node))) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
@@ -147,15 +152,12 @@ class PreviewController extends Controller {
// Is this header is set it means our UI is doing a preview for no-download shares
// we check a header so we at least prevent people from using the link directly (obfuscation)
- $isNextcloudPreview = $this->request->getHeader('X-NC-Preview') === 'true';
+ $isNextcloudPreview = $this->request->getHeader('x-nc-preview') === 'true';
$storage = $node->getStorage();
if ($isNextcloudPreview === false && $storage->instanceOfStorage(ISharedStorage::class)) {
/** @var ISharedStorage $storage */
$share = $storage->getShare();
- $attributes = $share->getAttributes();
- // No "allow preview" header set, so we must check if
- // the share has not explicitly disabled download permissions
- if ($attributes?->getAttribute('permissions', 'download') === false) {
+ if (!$share->canSeeContent()) {
return new DataResponse([], Http::STATUS_FORBIDDEN);
}
}
@@ -180,4 +182,25 @@ class PreviewController extends Controller {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
}
+
+ /**
+ * Get a preview by mime
+ *
+ * @param string $mime Mime type
+ * @return RedirectResponse<Http::STATUS_SEE_OTHER, array{}>
+ *
+ * 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);
+ }
}