Skip to content

Commit e4244d1

Browse files
committed
fix: Open PDF file in "richdocuments" if it is not downloadable
The PDF viewer must be able to download the file to show it, and if the file is not downloadable an error message was just shown. However, Nextcloud Office ("richdocuments") is able to show PDF files even if they can not be downloaded, so now the viewer is reopened forcing "richdocuments" to handle opening the file when it is not downloadable. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
1 parent a554eab commit e4244d1

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/views/PDFView.vue

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
ref="iframe"
88
:src="iframeSrc"
99
@load="onIFrameLoaded" />
10-
<div v-else id="emptycontent">
10+
<div v-else-if="!isRichDocumentsAvailable" id="emptycontent">
1111
<div class="icon-error" />
1212
<h3>{{ t('files_pdfviewer', 'To view a shared PDF file, the download needs to be allowed for this file share') }}</h3>
1313
</div>
@@ -59,6 +59,10 @@ export default {
5959
return true
6060
},
6161
62+
isRichDocumentsAvailable() {
63+
return 'richdocuments' in OC.appswebroots
64+
},
65+
6266
isEditable() {
6367
return this.file?.permissions?.indexOf('W') >= 0
6468
},
@@ -68,6 +72,23 @@ export default {
6872
if (!this.isDownloadable) {
6973
this.doneLoading()
7074
75+
if (this.isRichDocumentsAvailable) {
76+
console.info('PDF file is not downloadable, but "richdocuments" is available, so falling back to it')
77+
78+
// Opening the viewer again overwrites its current state, so the
79+
// current options need to be explicitly passed again.
80+
OCA.Viewer.openWith('richdocuments', {
81+
fileInfo: this.file,
82+
list: OCA.Viewer.list,
83+
enableSidebar: OCA.Viewer.enableSidebar,
84+
loadMore: OCA.Viewer.loadMore,
85+
canLoop: OCA.Viewer.canLoop,
86+
onPrev: OCA.Viewer.onPrev,
87+
onNext: OCA.Viewer.onNext,
88+
onClose: OCA.Viewer.onClose,
89+
})
90+
}
91+
7192
return
7293
}
7394

0 commit comments

Comments
 (0)