aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/files/lib/Dashboard/FavoriteWidget.php1
-rw-r--r--apps/files/src/components/FileEntry/FileEntryPreview.vue1
-rw-r--r--apps/files_versions/src/utils/versions.ts2
-rw-r--r--core/Controller/PreviewController.php35
-rw-r--r--core/openapi-full.json56
-rw-r--r--core/openapi.json56
-rw-r--r--core/src/OC/dialogs.js3
-rw-r--r--tests/Core/Controller/PreviewControllerTest.php38
8 files changed, 49 insertions, 143 deletions
diff --git a/apps/files/lib/Dashboard/FavoriteWidget.php b/apps/files/lib/Dashboard/FavoriteWidget.php
index b68b8a56b2e..9174964d316 100644
--- a/apps/files/lib/Dashboard/FavoriteWidget.php
+++ b/apps/files/lib/Dashboard/FavoriteWidget.php
@@ -95,7 +95,6 @@ class FavoriteWidget implements IIconWidget, IAPIWidgetV2, IButtonWidget, IOptio
'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 2d5844f851f..e1c640ad005 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 b52f92ef462..ec1091def29 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 a4eaf193ea2..860d80c8af9 100644
--- a/core/Controller/PreviewController.php
+++ b/core/Controller/PreviewController.php
@@ -25,6 +25,7 @@ use OCP\Files\NotFoundException;
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 @@ class PreviewController extends Controller {
private IRootFolder $root,
private ?string $userId,
private IMimeIconProvider $mimeIconProvider,
+ private IURLGenerator $urlGenerator,
) {
parent::__construct($appName, $request);
}
@@ -48,13 +50,11 @@ class PreviewController extends Controller {
* @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<Http::STATUS_OK, array{Content-Type: string}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_NOT_FOUND, list<empty>, array{}>|RedirectResponse<Http::STATUS_SEE_OTHER, array{}>
*
* 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 @@ class PreviewController extends Controller {
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 @@ class PreviewController extends Controller {
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 @@ class PreviewController extends Controller {
* @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<Http::STATUS_OK, array{Content-Type: string}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_NOT_FOUND, list<empty>, array{}>|RedirectResponse<Http::STATUS_SEE_OTHER, array{}>
*
* 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 @@ class PreviewController extends Controller {
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 @@ class PreviewController extends Controller {
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 @@ class PreviewController extends Controller {
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 @@ class PreviewController extends Controller {
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 5918bab6eac..7ff668da5ed 100644
--- a/core/openapi-full.json
+++ b/core/openapi-full.json
@@ -8254,19 +8254,6 @@
}
},
{
- "name": "forceIcon",
- "in": "query",
- "description": "Force returning an icon",
- "schema": {
- "type": "integer",
- "default": 1,
- "enum": [
- 0,
- 1
- ]
- }
- },
- {
"name": "mode",
"in": "query",
"description": "How to crop the image",
@@ -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": {
@@ -8402,19 +8376,6 @@
}
},
{
- "name": "forceIcon",
- "in": "query",
- "description": "Force returning an icon",
- "schema": {
- "type": "integer",
- "default": 1,
- "enum": [
- 0,
- 1
- ]
- }
- },
- {
"name": "mode",
"in": "query",
"description": "How to crop the image",
@@ -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 25aee646121..506507d3978 100644
--- a/core/openapi.json
+++ b/core/openapi.json
@@ -8254,19 +8254,6 @@
}
},
{
- "name": "forceIcon",
- "in": "query",
- "description": "Force returning an icon",
- "schema": {
- "type": "integer",
- "default": 1,
- "enum": [
- 0,
- 1
- ]
- }
- },
- {
"name": "mode",
"in": "query",
"description": "How to crop the image",
@@ -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": {
@@ -8402,19 +8376,6 @@
}
},
{
- "name": "forceIcon",
- "in": "query",
- "description": "Force returning an icon",
- "schema": {
- "type": "integer",
- "default": 1,
- "enum": [
- 0,
- 1
- ]
- }
- },
- {
"name": "mode",
"in": "query",
"description": "How to crop the image",
@@ -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 c10f676701d..a60562191f0 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 e7ecba27064..acaf168b949 100644
--- a/tests/Core/Controller/PreviewControllerTest.php
+++ b/tests/Core/Controller/PreviewControllerTest.php
@@ -9,6 +9,7 @@ namespace Tests\Core\Controller;
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\ISharedStorage;
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 @@ class PreviewControllerTest extends \Test\TestCase {
$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 @@ class PreviewControllerTest extends \Test\TestCase {
$this->previewManager,
$this->rootFolder,
$this->userId,
- $this->createMock(IMimeIconProvider::class)
+ $this->createMock(IMimeIconProvider::class),
+ $this->urlGenerator,
);
}
@@ -88,6 +93,18 @@ class PreviewControllerTest extends \Test\TestCase {
}
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 @@ class PreviewControllerTest extends \Test\TestCase {
->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 @@ class PreviewControllerTest extends \Test\TestCase {
->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 @@ class PreviewControllerTest extends \Test\TestCase {
->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 @@ class PreviewControllerTest extends \Test\TestCase {
->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 @@ class PreviewControllerTest extends \Test\TestCase {
$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 @@ class PreviewControllerTest extends \Test\TestCase {
$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 @@ class PreviewControllerTest extends \Test\TestCase {
$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 @@ class PreviewControllerTest extends \Test\TestCase {
$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 @@ class PreviewControllerTest extends \Test\TestCase {
$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());