Skip to content

Commit c75fba9

Browse files
committed
fix(core): Always try to generate some kind of preview
Signed-off-by: provokateurin <[email protected]>
1 parent 03f892c commit c75fba9

8 files changed

Lines changed: 49 additions & 143 deletions

File tree

apps/files/lib/Dashboard/FavoriteWidget.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ public function getItems(string $userId, int $limit = 7): array {
9595
'y' => 256,
9696
'fileId' => $node->getId(),
9797
'c' => $node->getEtag(),
98-
'mimeFallback' => true,
9998
]);
10099
} else {
101100
$icon = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'filetypes/folder.svg'));

apps/files/src/components/FileEntry/FileEntryPreview.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ export default defineComponent({
163163
// Request tiny previews
164164
url.searchParams.set('x', this.gridMode ? '128' : '32')
165165
url.searchParams.set('y', this.gridMode ? '128' : '32')
166-
url.searchParams.set('mimeFallback', 'true')
167166
168167
// Etag to force refresh preview on change
169168
const etag = this.source?.attributes?.etag || ''

apps/files_versions/src/utils/versions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function formatVersion(version: any, fileInfo: any): Version {
7878
let previewUrl = ''
7979

8080
if (mtime === fileInfo.mtime) { // Version is the current one
81-
previewUrl = generateUrl('/core/preview?fileId={fileId}&c={fileEtag}&x=250&y=250&forceIcon=0&a=0', {
81+
previewUrl = generateUrl('/core/preview?fileId={fileId}&c={fileEtag}&x=250&y=250&a=0', {
8282
fileId: fileInfo.id,
8383
fileEtag: fileInfo.etag,
8484
})

core/Controller/PreviewController.php

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use OCP\Files\Storage\ISharedStorage;
2626
use OCP\IPreview;
2727
use OCP\IRequest;
28+
use OCP\IURLGenerator;
2829
use OCP\Preview\IMimeIconProvider;
2930

3031
class PreviewController extends Controller {
@@ -35,6 +36,7 @@ public function __construct(
3536
private IRootFolder $root,
3637
private ?string $userId,
3738
private IMimeIconProvider $mimeIconProvider,
39+
private IURLGenerator $urlGenerator,
3840
) {
3941
parent::__construct($appName, $request);
4042
}
@@ -48,13 +50,11 @@ public function __construct(
4850
* @param int $x Width of the preview. A width of -1 will use the original image width.
4951
* @param int $y Height of the preview. A height of -1 will use the original image height.
5052
* @param bool $a Preserve the aspect ratio
51-
* @param bool $forceIcon Force returning an icon
5253
* @param 'fill'|'cover' $mode How to crop the image
53-
* @param bool $mimeFallback Whether to fallback to the mime icon if no preview is available
5454
* @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{}>
5555
*
5656
* 200: Preview returned
57-
* 303: Redirect to the mime icon url if mimeFallback is true
57+
* 303: Redirect to the mime icon url
5858
* 400: Getting preview is not possible
5959
* 403: Getting preview is not allowed
6060
* 404: Preview not found
@@ -68,9 +68,8 @@ public function getPreview(
6868
int $x = 32,
6969
int $y = 32,
7070
bool $a = false,
71-
bool $forceIcon = true,
7271
string $mode = 'fill',
73-
bool $mimeFallback = false): Http\Response {
72+
): Http\Response {
7473
if ($file === '' || $x === 0 || $y === 0) {
7574
return new DataResponse([], Http::STATUS_BAD_REQUEST);
7675
}
@@ -82,7 +81,7 @@ public function getPreview(
8281
return new DataResponse([], Http::STATUS_NOT_FOUND);
8382
}
8483

85-
return $this->fetchPreview($node, $x, $y, $a, $forceIcon, $mode, $mimeFallback);
84+
return $this->fetchPreview($node, $x, $y, $a, $mode);
8685
}
8786

8887
/**
@@ -92,13 +91,11 @@ public function getPreview(
9291
* @param int $x Width of the preview. A width of -1 will use the original image width.
9392
* @param int $y Height of the preview. A height of -1 will use the original image height.
9493
* @param bool $a Preserve the aspect ratio
95-
* @param bool $forceIcon Force returning an icon
9694
* @param 'fill'|'cover' $mode How to crop the image
97-
* @param bool $mimeFallback Whether to fallback to the mime icon if no preview is available
9895
* @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{}>
9996
*
10097
* 200: Preview returned
101-
* 303: Redirect to the mime icon url if mimeFallback is true
98+
* 303: Redirect to the mime icon url
10299
* 400: Getting preview is not possible
103100
* 403: Getting preview is not allowed
104101
* 404: Preview not found
@@ -112,9 +109,8 @@ public function getPreviewByFileId(
112109
int $x = 32,
113110
int $y = 32,
114111
bool $a = false,
115-
bool $forceIcon = true,
116112
string $mode = 'fill',
117-
bool $mimeFallback = false) {
113+
) {
118114
if ($fileId === -1 || $x === 0 || $y === 0) {
119115
return new DataResponse([], Http::STATUS_BAD_REQUEST);
120116
}
@@ -126,7 +122,7 @@ public function getPreviewByFileId(
126122
return new DataResponse([], Http::STATUS_NOT_FOUND);
127123
}
128124

129-
return $this->fetchPreview($node, $x, $y, $a, $forceIcon, $mode, $mimeFallback);
125+
return $this->fetchPreview($node, $x, $y, $a, $mode);
130126
}
131127

132128
/**
@@ -137,11 +133,10 @@ private function fetchPreview(
137133
int $x,
138134
int $y,
139135
bool $a,
140-
bool $forceIcon,
141136
string $mode,
142-
bool $mimeFallback = false) : Http\Response {
143-
if (!($node instanceof File) || (!$forceIcon && !$this->preview->isAvailable($node))) {
144-
return new DataResponse([], Http::STATUS_NOT_FOUND);
137+
) : Http\Response {
138+
if (!($node instanceof File)) {
139+
return new RedirectResponse($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'filetypes/folder.svg')));
145140
}
146141
if (!$node->isReadable()) {
147142
return new DataResponse([], Http::STATUS_FORBIDDEN);
@@ -175,13 +170,11 @@ private function fetchPreview(
175170
return $response;
176171
} catch (NotFoundException $e) {
177172
// If we have no preview enabled, we can redirect to the mime icon if any
178-
if ($mimeFallback) {
179-
if ($url = $this->mimeIconProvider->getMimeIconUrl($node->getMimeType())) {
180-
return new RedirectResponse($url);
181-
}
173+
if ($url = $this->mimeIconProvider->getMimeIconUrl($node->getMimeType())) {
174+
return new RedirectResponse($url);
182175
}
183176

184-
return new DataResponse([], Http::STATUS_NOT_FOUND);
177+
return new RedirectResponse($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'filetypes/file.svg')));
185178
} catch (\InvalidArgumentException $e) {
186179
return new DataResponse([], Http::STATUS_BAD_REQUEST);
187180
}

core/openapi-full.json

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8253,19 +8253,6 @@
82538253
]
82548254
}
82558255
},
8256-
{
8257-
"name": "forceIcon",
8258-
"in": "query",
8259-
"description": "Force returning an icon",
8260-
"schema": {
8261-
"type": "integer",
8262-
"default": 1,
8263-
"enum": [
8264-
0,
8265-
1
8266-
]
8267-
}
8268-
},
82698256
{
82708257
"name": "mode",
82718258
"in": "query",
@@ -8278,19 +8265,6 @@
82788265
"cover"
82798266
]
82808267
}
8281-
},
8282-
{
8283-
"name": "mimeFallback",
8284-
"in": "query",
8285-
"description": "Whether to fallback to the mime icon if no preview is available",
8286-
"schema": {
8287-
"type": "integer",
8288-
"default": 0,
8289-
"enum": [
8290-
0,
8291-
1
8292-
]
8293-
}
82948268
}
82958269
],
82968270
"responses": {
@@ -8330,7 +8304,7 @@
83308304
}
83318305
},
83328306
"303": {
8333-
"description": "Redirect to the mime icon url if mimeFallback is true",
8307+
"description": "Redirect to the mime icon url",
83348308
"headers": {
83358309
"Location": {
83368310
"schema": {
@@ -8401,19 +8375,6 @@
84018375
]
84028376
}
84038377
},
8404-
{
8405-
"name": "forceIcon",
8406-
"in": "query",
8407-
"description": "Force returning an icon",
8408-
"schema": {
8409-
"type": "integer",
8410-
"default": 1,
8411-
"enum": [
8412-
0,
8413-
1
8414-
]
8415-
}
8416-
},
84178378
{
84188379
"name": "mode",
84198380
"in": "query",
@@ -8426,19 +8387,6 @@
84268387
"cover"
84278388
]
84288389
}
8429-
},
8430-
{
8431-
"name": "mimeFallback",
8432-
"in": "query",
8433-
"description": "Whether to fallback to the mime icon if no preview is available",
8434-
"schema": {
8435-
"type": "integer",
8436-
"default": 0,
8437-
"enum": [
8438-
0,
8439-
1
8440-
]
8441-
}
84428390
}
84438391
],
84448392
"responses": {
@@ -8478,7 +8426,7 @@
84788426
}
84798427
},
84808428
"303": {
8481-
"description": "Redirect to the mime icon url if mimeFallback is true",
8429+
"description": "Redirect to the mime icon url",
84828430
"headers": {
84838431
"Location": {
84848432
"schema": {

core/openapi.json

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8253,19 +8253,6 @@
82538253
]
82548254
}
82558255
},
8256-
{
8257-
"name": "forceIcon",
8258-
"in": "query",
8259-
"description": "Force returning an icon",
8260-
"schema": {
8261-
"type": "integer",
8262-
"default": 1,
8263-
"enum": [
8264-
0,
8265-
1
8266-
]
8267-
}
8268-
},
82698256
{
82708257
"name": "mode",
82718258
"in": "query",
@@ -8278,19 +8265,6 @@
82788265
"cover"
82798266
]
82808267
}
8281-
},
8282-
{
8283-
"name": "mimeFallback",
8284-
"in": "query",
8285-
"description": "Whether to fallback to the mime icon if no preview is available",
8286-
"schema": {
8287-
"type": "integer",
8288-
"default": 0,
8289-
"enum": [
8290-
0,
8291-
1
8292-
]
8293-
}
82948268
}
82958269
],
82968270
"responses": {
@@ -8330,7 +8304,7 @@
83308304
}
83318305
},
83328306
"303": {
8333-
"description": "Redirect to the mime icon url if mimeFallback is true",
8307+
"description": "Redirect to the mime icon url",
83348308
"headers": {
83358309
"Location": {
83368310
"schema": {
@@ -8401,19 +8375,6 @@
84018375
]
84028376
}
84038377
},
8404-
{
8405-
"name": "forceIcon",
8406-
"in": "query",
8407-
"description": "Force returning an icon",
8408-
"schema": {
8409-
"type": "integer",
8410-
"default": 1,
8411-
"enum": [
8412-
0,
8413-
1
8414-
]
8415-
}
8416-
},
84178378
{
84188379
"name": "mode",
84198380
"in": "query",
@@ -8426,19 +8387,6 @@
84268387
"cover"
84278388
]
84288389
}
8429-
},
8430-
{
8431-
"name": "mimeFallback",
8432-
"in": "query",
8433-
"description": "Whether to fallback to the mime icon if no preview is available",
8434-
"schema": {
8435-
"type": "integer",
8436-
"default": 0,
8437-
"enum": [
8438-
0,
8439-
1
8440-
]
8441-
}
84428390
}
84438391
],
84448392
"responses": {
@@ -8478,7 +8426,7 @@
84788426
}
84798427
},
84808428
"303": {
8481-
"description": "Redirect to the mime icon url if mimeFallback is true",
8429+
"description": "Redirect to the mime icon url",
84828430
"headers": {
84838431
"Location": {
84848432
"schema": {

core/src/OC/dialogs.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ const Dialogs = {
345345
}
346346

347347
const dialog = builder.build()
348-
348+
349349
if (allowHtml) {
350350
dialog.setHTML(content)
351351
}
@@ -560,7 +560,6 @@ const Dialogs = {
560560
x: 96,
561561
y: 96,
562562
c: original.etag,
563-
forceIcon: 0
564563
}
565564
var previewpath = Files.generatePreviewUrl(urlSpec)
566565
// Escaping single quotes

0 commit comments

Comments
 (0)