diff options
author | Max <max@nextcloud.com> | 2022-08-11 11:30:16 +0200 |
---|---|---|
committer | Vincent Petry (Rebase PR Action) <PVince81@users.noreply.github.com> | 2022-08-25 21:59:20 +0000 |
commit | b67aaf7ab0fb2e2b7c727290e6b1321557126380 (patch) | |
tree | dc0563930e8d8a8a6e0cb12401a208a86af6c26e /apps/files_sharing | |
parent | 8c9470320aa153980cd2c95687a721eb9655c60a (diff) | |
download | nextcloud-server-b67aaf7ab0fb2e2b7c727290e6b1321557126380.tar.gz nextcloud-server-b67aaf7ab0fb2e2b7c727290e6b1321557126380.zip |
fix: use old singe file share rendering as fallback
Only render images and videos with the viewer.
Text has its own way of handling single file shares for now.
In case viewer does not support the file format
fall back to the old way of handling single file shares.
Signed-off-by: Max <max@nextcloud.com>
Diffstat (limited to 'apps/files_sharing')
-rw-r--r-- | apps/files_sharing/js/public.js | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js index 5ae62939dc1..a0a57c41e9d 100644 --- a/apps/files_sharing/js/public.js +++ b/apps/files_sharing/js/public.js @@ -129,10 +129,39 @@ OCA.Sharing.PublicApp = { } } - if (OCA.Viewer.mimetypes.includes(mimetype)) { + // dynamically load image previews + var bottomMargin = 350; + var previewWidth = $(window).width(); + var previewHeight = $(window).height() - bottomMargin; + previewHeight = Math.max(200, previewHeight); + var params = { + x: Math.ceil(previewWidth * window.devicePixelRatio), + y: Math.ceil(previewHeight * window.devicePixelRatio), + a: 'true', + file: encodeURIComponent(this.initialDir + $('#filename').val()), + scalingup: 0 + }; + + var imgcontainer = $('<img class="publicpreview" alt="">'); + if (hideDownload === 'false') { + imgcontainer = $('<a href="' + $('#previewURL').val() + '" target="_blank"></a>').append(imgcontainer); + } + var img = imgcontainer.hasClass('publicpreview')? imgcontainer: imgcontainer.find('.publicpreview'); + img.css({ + 'max-width': previewWidth, + 'max-height': previewHeight + }); + + if (OCA.Viewer && OCA.Viewer.mimetypes.includes(mimetype) + && (mimetype.startsWith('image/') || mimetype.startsWith('video/'))) { OCA.Viewer.setRootElement('#imgframe') OCA.Viewer.open({ path: '/' }) } else if (mimetype.substr(0, mimetype.indexOf('/')) === 'text' && window.btoa) { + if (OC.appswebroots['files_texteditor'] !== undefined || + OC.appswebroots['text'] !== undefined) { + // the text editor handles the previewing + return; + } // Undocumented Url to public WebDAV endpoint var url = parent.location.protocol + '//' + location.host + OC.linkTo('', 'public.php/webdav'); $.ajax({ @@ -144,6 +173,20 @@ OCA.Sharing.PublicApp = { }).then(function (data) { self._showTextPreview(data, previewHeight); }); + } else if ((previewSupported === 'true' && mimetype.substr(0, mimetype.indexOf('/')) !== 'video') || + mimetype.substr(0, mimetype.indexOf('/')) === 'image' && + mimetype !== 'image/svg+xml') { + img.attr('src', OC.generateUrl('/apps/files_sharing/publicpreview/' + token + '?' + OC.buildQueryString(params))); + imgcontainer.appendTo('#imgframe'); + } else if (mimetype.substr(0, mimetype.indexOf('/')) !== 'video') { + img.attr('src', mimetypeIcon); + img.attr('width', 128); + // "#imgframe" is either empty or it contains an audio preview that + // the icon should appear before, so the container should be + // prepended to the frame. + imgcontainer.prependTo('#imgframe'); + } else if (previewSupported === 'true') { + $('#imgframe > video').attr('poster', OC.generateUrl('/apps/files_sharing/publicpreview/' + token + '?' + OC.buildQueryString(params))); } if (this.fileList) { |