diff --git a/apps/files/lib/Dashboard/FavoriteWidget.php b/apps/files/lib/Dashboard/FavoriteWidget.php index b68b8a56b2eaf..9174964d316fd 100644 --- a/apps/files/lib/Dashboard/FavoriteWidget.php +++ b/apps/files/lib/Dashboard/FavoriteWidget.php @@ -95,7 +95,6 @@ public function getItems(string $userId, int $limit = 7): array { 'y' => 256, 'fileId' => $node->getId(), 'c' => $node->getEtag(), - 'mimeFallback' => true, ]); } else { $icon = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'filetypes/folder.svg')); diff --git a/apps/files/src/components/FileEntry/FileEntryPreview.vue b/apps/files/src/components/FileEntry/FileEntryPreview.vue index 2d5844f851f71..e1c640ad005a1 100644 --- a/apps/files/src/components/FileEntry/FileEntryPreview.vue +++ b/apps/files/src/components/FileEntry/FileEntryPreview.vue @@ -163,7 +163,6 @@ export default defineComponent({ // Request tiny previews url.searchParams.set('x', this.gridMode ? '128' : '32') url.searchParams.set('y', this.gridMode ? '128' : '32') - url.searchParams.set('mimeFallback', 'true') // Etag to force refresh preview on change const etag = this.source?.attributes?.etag || '' diff --git a/apps/files_versions/src/utils/versions.ts b/apps/files_versions/src/utils/versions.ts index b52f92ef4621c..ec1091def29d5 100644 --- a/apps/files_versions/src/utils/versions.ts +++ b/apps/files_versions/src/utils/versions.ts @@ -78,7 +78,7 @@ function formatVersion(version: any, fileInfo: any): Version { let previewUrl = '' if (mtime === fileInfo.mtime) { // Version is the current one - previewUrl = generateUrl('/core/preview?fileId={fileId}&c={fileEtag}&x=250&y=250&forceIcon=0&a=0', { + previewUrl = generateUrl('/core/preview?fileId={fileId}&c={fileEtag}&x=250&y=250&a=0', { fileId: fileInfo.id, fileEtag: fileInfo.etag, }) diff --git a/core/Controller/PreviewController.php b/core/Controller/PreviewController.php index a4eaf193ea2eb..860d80c8af944 100644 --- a/core/Controller/PreviewController.php +++ b/core/Controller/PreviewController.php @@ -25,6 +25,7 @@ use OCP\Files\Storage\ISharedStorage; use OCP\IPreview; use OCP\IRequest; +use OCP\IURLGenerator; use OCP\Preview\IMimeIconProvider; class PreviewController extends Controller { @@ -35,6 +36,7 @@ public function __construct( private IRootFolder $root, private ?string $userId, private IMimeIconProvider $mimeIconProvider, + private IURLGenerator $urlGenerator, ) { parent::__construct($appName, $request); } @@ -48,13 +50,11 @@ public function __construct( * @param int $x Width of the preview. A width of -1 will use the original image width. * @param int $y Height of the preview. A height of -1 will use the original image height. * @param bool $a Preserve the aspect ratio - * @param bool $forceIcon Force returning an icon * @param 'fill'|'cover' $mode How to crop the image - * @param bool $mimeFallback Whether to fallback to the mime icon if no preview is available * @return FileDisplayResponse|DataResponse, array{}>|RedirectResponse * * 200: Preview returned - * 303: Redirect to the mime icon url if mimeFallback is true + * 303: Redirect to the mime icon url * 400: Getting preview is not possible * 403: Getting preview is not allowed * 404: Preview not found @@ -68,9 +68,8 @@ public function getPreview( int $x = 32, int $y = 32, bool $a = false, - bool $forceIcon = true, string $mode = 'fill', - bool $mimeFallback = false): Http\Response { + ): Http\Response { if ($file === '' || $x === 0 || $y === 0) { return new DataResponse([], Http::STATUS_BAD_REQUEST); } @@ -82,7 +81,7 @@ public function getPreview( return new DataResponse([], Http::STATUS_NOT_FOUND); } - return $this->fetchPreview($node, $x, $y, $a, $forceIcon, $mode, $mimeFallback); + return $this->fetchPreview($node, $x, $y, $a, $mode); } /** @@ -92,13 +91,11 @@ public function getPreview( * @param int $x Width of the preview. A width of -1 will use the original image width. * @param int $y Height of the preview. A height of -1 will use the original image height. * @param bool $a Preserve the aspect ratio - * @param bool $forceIcon Force returning an icon * @param 'fill'|'cover' $mode How to crop the image - * @param bool $mimeFallback Whether to fallback to the mime icon if no preview is available * @return FileDisplayResponse|DataResponse, array{}>|RedirectResponse * * 200: Preview returned - * 303: Redirect to the mime icon url if mimeFallback is true + * 303: Redirect to the mime icon url * 400: Getting preview is not possible * 403: Getting preview is not allowed * 404: Preview not found @@ -112,9 +109,8 @@ public function getPreviewByFileId( int $x = 32, int $y = 32, bool $a = false, - bool $forceIcon = true, string $mode = 'fill', - bool $mimeFallback = false) { + ) { if ($fileId === -1 || $x === 0 || $y === 0) { return new DataResponse([], Http::STATUS_BAD_REQUEST); } @@ -126,7 +122,7 @@ public function getPreviewByFileId( return new DataResponse([], Http::STATUS_NOT_FOUND); } - return $this->fetchPreview($node, $x, $y, $a, $forceIcon, $mode, $mimeFallback); + return $this->fetchPreview($node, $x, $y, $a, $mode); } /** @@ -137,11 +133,10 @@ private function fetchPreview( int $x, int $y, bool $a, - bool $forceIcon, string $mode, - bool $mimeFallback = false) : Http\Response { - if (!($node instanceof File) || (!$forceIcon && !$this->preview->isAvailable($node))) { - return new DataResponse([], Http::STATUS_NOT_FOUND); + ) : Http\Response { + if (!($node instanceof File)) { + return new RedirectResponse($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'filetypes/folder.svg'))); } if (!$node->isReadable()) { return new DataResponse([], Http::STATUS_FORBIDDEN); @@ -175,13 +170,11 @@ private function fetchPreview( return $response; } catch (NotFoundException $e) { // If we have no preview enabled, we can redirect to the mime icon if any - if ($mimeFallback) { - if ($url = $this->mimeIconProvider->getMimeIconUrl($node->getMimeType())) { - return new RedirectResponse($url); - } + if ($url = $this->mimeIconProvider->getMimeIconUrl($node->getMimeType())) { + return new RedirectResponse($url); } - return new DataResponse([], Http::STATUS_NOT_FOUND); + return new RedirectResponse($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'filetypes/file.svg'))); } catch (\InvalidArgumentException $e) { return new DataResponse([], Http::STATUS_BAD_REQUEST); } diff --git a/core/openapi-full.json b/core/openapi-full.json index 5918bab6eacca..7ff668da5ed0a 100644 --- a/core/openapi-full.json +++ b/core/openapi-full.json @@ -8253,19 +8253,6 @@ ] } }, - { - "name": "forceIcon", - "in": "query", - "description": "Force returning an icon", - "schema": { - "type": "integer", - "default": 1, - "enum": [ - 0, - 1 - ] - } - }, { "name": "mode", "in": "query", @@ -8278,19 +8265,6 @@ "cover" ] } - }, - { - "name": "mimeFallback", - "in": "query", - "description": "Whether to fallback to the mime icon if no preview is available", - "schema": { - "type": "integer", - "default": 0, - "enum": [ - 0, - 1 - ] - } } ], "responses": { @@ -8330,7 +8304,7 @@ } }, "303": { - "description": "Redirect to the mime icon url if mimeFallback is true", + "description": "Redirect to the mime icon url", "headers": { "Location": { "schema": { @@ -8401,19 +8375,6 @@ ] } }, - { - "name": "forceIcon", - "in": "query", - "description": "Force returning an icon", - "schema": { - "type": "integer", - "default": 1, - "enum": [ - 0, - 1 - ] - } - }, { "name": "mode", "in": "query", @@ -8426,19 +8387,6 @@ "cover" ] } - }, - { - "name": "mimeFallback", - "in": "query", - "description": "Whether to fallback to the mime icon if no preview is available", - "schema": { - "type": "integer", - "default": 0, - "enum": [ - 0, - 1 - ] - } } ], "responses": { @@ -8478,7 +8426,7 @@ } }, "303": { - "description": "Redirect to the mime icon url if mimeFallback is true", + "description": "Redirect to the mime icon url", "headers": { "Location": { "schema": { diff --git a/core/openapi.json b/core/openapi.json index 25aee646121db..506507d39785b 100644 --- a/core/openapi.json +++ b/core/openapi.json @@ -8253,19 +8253,6 @@ ] } }, - { - "name": "forceIcon", - "in": "query", - "description": "Force returning an icon", - "schema": { - "type": "integer", - "default": 1, - "enum": [ - 0, - 1 - ] - } - }, { "name": "mode", "in": "query", @@ -8278,19 +8265,6 @@ "cover" ] } - }, - { - "name": "mimeFallback", - "in": "query", - "description": "Whether to fallback to the mime icon if no preview is available", - "schema": { - "type": "integer", - "default": 0, - "enum": [ - 0, - 1 - ] - } } ], "responses": { @@ -8330,7 +8304,7 @@ } }, "303": { - "description": "Redirect to the mime icon url if mimeFallback is true", + "description": "Redirect to the mime icon url", "headers": { "Location": { "schema": { @@ -8401,19 +8375,6 @@ ] } }, - { - "name": "forceIcon", - "in": "query", - "description": "Force returning an icon", - "schema": { - "type": "integer", - "default": 1, - "enum": [ - 0, - 1 - ] - } - }, { "name": "mode", "in": "query", @@ -8426,19 +8387,6 @@ "cover" ] } - }, - { - "name": "mimeFallback", - "in": "query", - "description": "Whether to fallback to the mime icon if no preview is available", - "schema": { - "type": "integer", - "default": 0, - "enum": [ - 0, - 1 - ] - } } ], "responses": { @@ -8478,7 +8426,7 @@ } }, "303": { - "description": "Redirect to the mime icon url if mimeFallback is true", + "description": "Redirect to the mime icon url", "headers": { "Location": { "schema": { diff --git a/core/src/OC/dialogs.js b/core/src/OC/dialogs.js index c10f676701d57..a60562191f020 100644 --- a/core/src/OC/dialogs.js +++ b/core/src/OC/dialogs.js @@ -345,7 +345,7 @@ const Dialogs = { } const dialog = builder.build() - + if (allowHtml) { dialog.setHTML(content) } @@ -560,7 +560,6 @@ const Dialogs = { x: 96, y: 96, c: original.etag, - forceIcon: 0 } var previewpath = Files.generatePreviewUrl(urlSpec) // Escaping single quotes diff --git a/tests/Core/Controller/PreviewControllerTest.php b/tests/Core/Controller/PreviewControllerTest.php index e7ecba27064db..acaf168b949ae 100644 --- a/tests/Core/Controller/PreviewControllerTest.php +++ b/tests/Core/Controller/PreviewControllerTest.php @@ -9,6 +9,7 @@ use OC\Core\Controller\PreviewController; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\Http\RedirectResponse; use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; @@ -18,6 +19,7 @@ use OCP\Files\Storage\IStorage; use OCP\IPreview; use OCP\IRequest; +use OCP\IURLGenerator; use OCP\Preview\IMimeIconProvider; use OCP\Share\IAttributes; use OCP\Share\IShare; @@ -31,6 +33,7 @@ class PreviewControllerTest extends \Test\TestCase { private IRootFolder&MockObject $rootFolder; private IPreview&MockObject $previewManager; private IRequest&MockObject $request; + private IURLGenerator&MockObject $urlGenerator; protected function setUp(): void { parent::setUp(); @@ -39,6 +42,7 @@ protected function setUp(): void { $this->rootFolder = $this->createMock(IRootFolder::class); $this->previewManager = $this->createMock(IPreview::class); $this->request = $this->createMock(IRequest::class); + $this->urlGenerator = $this->createMock(IURLGenerator::class); $this->controller = new PreviewController( 'core', @@ -46,7 +50,8 @@ protected function setUp(): void { $this->previewManager, $this->rootFolder, $this->userId, - $this->createMock(IMimeIconProvider::class) + $this->createMock(IMimeIconProvider::class), + $this->urlGenerator, ); } @@ -88,6 +93,18 @@ public function testFileNotFound(): void { } public function testNotAFile(): void { + $this->urlGenerator + ->expects($this->once()) + ->method('imagePath') + ->with('core', 'filetypes/folder.svg') + ->willReturn('core/filetypes/folder.svg'); + + $this->urlGenerator + ->expects($this->once()) + ->method('getAbsoluteURL') + ->with('core/filetypes/folder.svg') + ->willReturn('http://localhost/core/filetypes/folder.svg'); + $userFolder = $this->createMock(Folder::class); $this->rootFolder->method('getUserFolder') ->with($this->equalTo($this->userId)) @@ -99,7 +116,7 @@ public function testNotAFile(): void { ->willReturn($folder); $res = $this->controller->getPreview('file'); - $expected = new DataResponse([], Http::STATUS_NOT_FOUND); + $expected = new RedirectResponse('http://localhost/core/filetypes/folder.svg'); $this->assertEquals($expected, $res); } @@ -111,6 +128,9 @@ public function testNoPreviewAndNoIcon(): void { ->willReturn($userFolder); $file = $this->createMock(File::class); + $file->method('isReadable') + ->willReturn(true); + $userFolder->method('get') ->with($this->equalTo('file')) ->willReturn($file); @@ -119,7 +139,7 @@ public function testNoPreviewAndNoIcon(): void { ->with($this->equalTo($file)) ->willReturn(false); - $res = $this->controller->getPreview('file', 10, 10, true, false); + $res = $this->controller->getPreview('file', 10, 10, true); $expected = new DataResponse([], Http::STATUS_NOT_FOUND); $this->assertEquals($expected, $res); @@ -151,7 +171,7 @@ public function testNoPreview() { ->with($this->equalTo($file), 10, 10, false, $this->equalTo('myMode')) ->willThrowException(new NotFoundException()); - $res = $this->controller->getPreview('file', 10, 10, true, true, 'myMode'); + $res = $this->controller->getPreview('file', 10, 10, true, 'myMode'); $expected = new DataResponse([], Http::STATUS_NOT_FOUND); $this->assertEquals($expected, $res); @@ -174,7 +194,7 @@ public function testFileWithoutReadPermission() { $file->method('isReadable') ->willReturn(false); - $res = $this->controller->getPreview('file', 10, 10, true, true); + $res = $this->controller->getPreview('file', 10, 10, true); $expected = new DataResponse([], Http::STATUS_FORBIDDEN); $this->assertEquals($expected, $res); @@ -220,7 +240,7 @@ public function testFileWithoutDownloadPermission() { $this->request->method('getHeader')->willReturn(''); - $res = $this->controller->getPreview('file', 10, 10, true, true); + $res = $this->controller->getPreview('file', 10, 10, true); $expected = new DataResponse([], Http::STATUS_FORBIDDEN); $this->assertEquals($expected, $res); @@ -277,7 +297,7 @@ public function testFileWithoutDownloadPermissionButHeader() { $preview->method('getMimeType') ->willReturn('myMime'); - $res = $this->controller->getPreview('file', 10, 10, true, true, 'myMode'); + $res = $this->controller->getPreview('file', 10, 10, true, 'myMode'); $this->assertEquals('myMime', $res->getHeaders()['Content-Type']); $this->assertEquals(Http::STATUS_OK, $res->getStatus()); @@ -316,7 +336,7 @@ public function testValidPreview(): void { $preview->method('getMimeType') ->willReturn('myMime'); - $res = $this->controller->getPreview('file', 10, 10, true, true, 'myMode'); + $res = $this->controller->getPreview('file', 10, 10, true, 'myMode'); $this->assertEquals('myMime', $res->getHeaders()['Content-Type']); $this->assertEquals(Http::STATUS_OK, $res->getStatus()); @@ -369,7 +389,7 @@ public function testValidPreviewOfShare() { $preview->method('getMimeType') ->willReturn('myMime'); - $res = $this->controller->getPreview('file', 10, 10, true, true, 'myMode'); + $res = $this->controller->getPreview('file', 10, 10, true, 'myMode'); $this->assertEquals('myMime', $res->getHeaders()['Content-Type']); $this->assertEquals(Http::STATUS_OK, $res->getStatus());