Skip to content

Commit f292125

Browse files
committed
feature: first take on using the viewer to render single file shares
Signed-off-by: Max <[email protected]>
1 parent bbe15b4 commit f292125

File tree

10 files changed

+67
-98
lines changed

10 files changed

+67
-98
lines changed

apps/files_sharing/css/mobile.css

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/files_sharing/css/mobile.scss

Lines changed: 0 additions & 1 deletion
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

Lines changed: 15 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/files_sharing/css/public.scss

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@
1414
}
1515

1616
#imgframe {
17-
height:75%;
17+
height: calc(100vh - 240px);
1818
padding-bottom:32px;
1919
padding-top:32px;
2020
width:80%;
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

Lines changed: 16 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/files_sharing/js/public.js

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -128,70 +128,11 @@ OCA.Sharing.PublicApp = {
128128
}
129129
}
130130

131-
132-
// dynamically load image previews
133131
var bottomMargin = 350;
134132
var previewWidth = $(window).width();
135133
var previewHeight = $(window).height() - bottomMargin;
136-
previewHeight = Math.max(200, previewHeight);
137-
var params = {
138-
x: Math.ceil(previewWidth * window.devicePixelRatio),
139-
y: Math.ceil(previewHeight * window.devicePixelRatio),
140-
a: 'true',
141-
file: encodeURIComponent(this.initialDir + $('#filename').val()),
142-
scalingup: 0
143-
};
144-
145-
var imgcontainer = $('<img class="publicpreview" alt="">');
146-
if (hideDownload === 'false') {
147-
imgcontainer = $('<a href="' + $('#previewURL').val() + '" target="_blank"></a>').append(imgcontainer);
148-
}
149-
var img = imgcontainer.hasClass('publicpreview')? imgcontainer: imgcontainer.find('.publicpreview');
150-
img.css({
151-
'max-width': previewWidth,
152-
'max-height': previewHeight
153-
});
154-
155-
var fileSize = parseInt($('#filesize').val(), 10);
156-
var maxGifSize = parseInt($('#maxSizeAnimateGif').val(), 10);
157-
158-
if (mimetype === 'image/gif' &&
159-
(maxGifSize === -1 || fileSize <= (maxGifSize * 1024 * 1024))) {
160-
img.attr('src', $('#downloadURL').val());
161-
imgcontainer.appendTo('#imgframe');
162-
} else if (mimetype.substr(0, mimetype.indexOf('/')) === 'text' && window.btoa) {
163-
if (OC.appswebroots['files_texteditor'] !== undefined ||
164-
OC.appswebroots['text'] !== undefined) {
165-
// the text editor handles the previewing
166-
return;
167-
}
168-
// Undocumented Url to public WebDAV endpoint
169-
var url = parent.location.protocol + '//' + location.host + OC.linkTo('', 'public.php/webdav');
170-
$.ajax({
171-
url: url,
172-
headers: {
173-
Authorization: 'Basic ' + btoa(token + ':'),
174-
Range: 'bytes=0-10000'
175-
}
176-
}).then(function (data) {
177-
self._showTextPreview(data, previewHeight);
178-
});
179-
} else if ((previewSupported === 'true' && mimetype.substr(0, mimetype.indexOf('/')) !== 'video') ||
180-
mimetype.substr(0, mimetype.indexOf('/')) === 'image' &&
181-
mimetype !== 'image/svg+xml') {
182-
img.attr('src', OC.generateUrl('/apps/files_sharing/publicpreview/' + token + '?' + OC.buildQueryString(params)));
183-
imgcontainer.appendTo('#imgframe');
184-
} else if (mimetype.substr(0, mimetype.indexOf('/')) !== 'video') {
185-
img.attr('src', mimetypeIcon);
186-
img.attr('width', 128);
187-
// "#imgframe" is either empty or it contains an audio preview that
188-
// the icon should appear before, so the container should be
189-
// prepended to the frame.
190-
imgcontainer.prependTo('#imgframe');
191-
}
192-
else if (previewSupported === 'true') {
193-
$('#imgframe > video').attr('poster', OC.generateUrl('/apps/files_sharing/publicpreview/' + token + '?' + OC.buildQueryString(params)));
194-
}
134+
OCA.Viewer.setRootElement('#imgframe')
135+
OCA.Viewer.open({ path: '/' })
195136

196137
if (this.fileList) {
197138
// TODO: move this to a separate PublicFileList class that extends OCA.Files.FileList (+ unit tests)

apps/files_sharing/lib/Controller/ShareController.php

Lines changed: 4 additions & 5 deletions
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

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

0 commit comments

Comments
 (0)