Skip to content

Commit 264a0bb

Browse files
authored
Merge pull request #33347 from nextcloud/feature/use-viewer-for-singe-file-shares
feature: use the viewer to render single file shares
2 parents e69ad6f + b67aaf7 commit 264a0bb

11 files changed

+67
-45
lines changed

apps/files_sharing/css/mobile.css

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/files_sharing/css/mobile.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/files_sharing/css/mobile.scss

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ table td.filename .nametext {
2424
#imgframe {
2525
width: 100%;
2626
padding: 0;
27-
margin-bottom: 35px;
2827
}
2928
/* some margin for the file type icon */
3029
#imgframe .publicpreview {

apps/files_sharing/css/public.css

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/files_sharing/css/public.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/files_sharing/css/public.scss

+13
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
margin:0 auto;
2222
}
2323

24+
#imgframe #viewer {
25+
height: 100%;
26+
width: 100%;
27+
}
2428

2529
#imgframe img {
2630
max-height: 100% !important;
@@ -48,6 +52,15 @@
4852
font-size: 1.2em;
4953
}
5054

55+
#imgframe .viewer__file {
56+
height: 100%;
57+
width: 100%;
58+
}
59+
60+
#imgframe .plyr {
61+
max-height: 100%;
62+
}
63+
5164
/* fix multiselect bar offset on shared page */
5265
thead {
5366
left: 0 !important;

apps/files_sharing/css/publicView.css

+14-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/files_sharing/css/publicView.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/files_sharing/js/public.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ OCA.Sharing.PublicApp = {
129129
}
130130
}
131131

132-
133132
// dynamically load image previews
134133
var bottomMargin = 350;
135134
var previewWidth = $(window).width();
@@ -153,13 +152,10 @@ OCA.Sharing.PublicApp = {
153152
'max-height': previewHeight
154153
});
155154

156-
var fileSize = parseInt($('#filesize').val(), 10);
157-
var maxGifSize = parseInt($('#maxSizeAnimateGif').val(), 10);
158-
159-
if (mimetype === 'image/gif' &&
160-
(maxGifSize === -1 || fileSize <= (maxGifSize * 1024 * 1024))) {
161-
img.attr('src', $('#downloadURL').val());
162-
imgcontainer.appendTo('#imgframe');
155+
if (OCA.Viewer && OCA.Viewer.mimetypes.includes(mimetype)
156+
&& (mimetype.startsWith('image/') || mimetype.startsWith('video/'))) {
157+
OCA.Viewer.setRootElement('#imgframe')
158+
OCA.Viewer.open({ path: '/' })
163159
} else if (mimetype.substr(0, mimetype.indexOf('/')) === 'text' && window.btoa) {
164160
if (OC.appswebroots['files_texteditor'] !== undefined ||
165161
OC.appswebroots['text'] !== undefined) {
@@ -189,8 +185,7 @@ OCA.Sharing.PublicApp = {
189185
// the icon should appear before, so the container should be
190186
// prepended to the frame.
191187
imgcontainer.prependTo('#imgframe');
192-
}
193-
else if (previewSupported === 'true') {
188+
} else if (previewSupported === 'true') {
194189
$('#imgframe > video').attr('poster', OC.generateUrl('/apps/files_sharing/publicpreview/' + token + '?' + OC.buildQueryString(params)));
195190
}
196191

apps/files_sharing/lib/Controller/ShareController.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -523,13 +523,12 @@ public function showShare($path = ''): TemplateResponse {
523523
\OCP\Util::addScript('files', 'filelist');
524524
\OCP\Util::addScript('files', 'keyboardshortcuts');
525525
\OCP\Util::addScript('files', 'operationprogressbar');
526-
527-
// Load Viewer scripts
528-
if (class_exists(LoadViewer::class)) {
529-
$this->eventDispatcher->dispatchTyped(new LoadViewer());
530-
}
531526
}
532527

528+
// Load Viewer scripts
529+
if (class_exists(LoadViewer::class)) {
530+
$this->eventDispatcher->dispatchTyped(new LoadViewer());
531+
}
533532
// OpenGraph Support: http://ogp.me/
534533
\OCP\Util::addHeader('meta', ['property' => "og:title", 'content' => $shareTmpl['filename']]);
535534
\OCP\Util::addHeader('meta', ['property' => "og:description", 'content' => $this->defaults->getName() . ($this->defaults->getSlogan() !== '' ? ' - ' . $this->defaults->getSlogan() : '')]);

apps/files_sharing/templates/public.php

+14-24
Original file line numberDiff line numberDiff line change
@@ -60,31 +60,21 @@
6060
<?php if (isset($_['folder'])): ?>
6161
<?php print_unescaped($_['folder']); ?>
6262
<?php else: ?>
63-
<?php if ($_['previewEnabled'] && substr($_['mimetype'], 0, strpos($_['mimetype'], '/')) == 'audio'): ?>
64-
<div id="imgframe">
65-
<audio tabindex="0" controls="" preload="none" style="width: 100%; max-width: <?php p($_['previewMaxX']); ?>px; max-height: <?php p($_['previewMaxY']); ?>px"
66-
<?php // See https://github.com/nextcloud/server/pull/27674?>
67-
<?php if ($_['hideDownload']) { ?>controlsList="nodownload" <?php } ?>>
68-
<source src="<?php p($_['downloadURL']); ?>" type="<?php p($_['mimetype']); ?>" />
69-
</audio>
70-
</div>
71-
<?php else: ?>
72-
<!-- Preview frame is filled via JS to support SVG images for modern browsers -->
73-
<div id="imgframe"></div>
74-
<?php if (isset($_['mimetype']) && strpos($_['mimetype'], 'image') === 0) { ?>
75-
<div class="directDownload">
76-
<div>
77-
<?php p($_['filename'])?> (<?php p($_['fileSize']) ?>)
78-
</div>
79-
<?php if (!$_['hideDownload']) { ?>
80-
<a href="<?php p($_['downloadURL']); ?>" id="downloadFile" class="button">
81-
<span class="icon icon-download"></span>
82-
<?php p($l->t('Download'))?>
83-
</a>
84-
<?php } ?>
85-
</div>
63+
<!-- preview frame to open file in with viewer -->
64+
<div id="imgframe"></div>
65+
<?php if (isset($_['mimetype']) && strpos($_['mimetype'], 'image') === 0) { ?>
66+
<div class="directDownload">
67+
<div>
68+
<?php p($_['filename'])?> (<?php p($_['fileSize']) ?>)
69+
</div>
70+
<?php if (!$_['hideDownload']) { ?>
71+
<a href="<?php p($_['downloadURL']); ?>" id="downloadFile" class="button">
72+
<span class="icon icon-download"></span>
73+
<?php p($l->t('Download'))?>
74+
</a>
8675
<?php } ?>
87-
<?php endif; ?>
76+
</div>
77+
<?php } ?>
8878
<?php if ($_['previewURL'] === $_['downloadURL'] && !$_['hideDownload']): ?>
8979
<div class="directDownload">
9080
<div>

0 commit comments

Comments
 (0)