Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Rename "canDownload" to "hideDownload"
"canDownload" inverted the value of the "hideDownload" setting. However,
that was not accurate, as if the download is hidden the file can still
be downloaded. Moreover, it is possible to actually disallow downloads,
which is a different setting (using share attributes) than hiding it.

Therefore, to better differentiate between a hidden download and a
disabled download the previous "canDownload" was renamed (and adjusted
as needed) to "hideDownload".

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
  • Loading branch information
danxuliu committed Dec 31, 2024
commit d7f9c2c256cb97f8a226acb0b3b4b94c4fe942d2
8 changes: 4 additions & 4 deletions src/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
import { generateUrl } from '@nextcloud/router'

import logger from './services/logger.js'
import canDownload from './utils/canDownload.js'
import hideDownload from './utils/hideDownload.js'
import isPublicPage from './utils/isPublicPage.js'
import isPdf from './utils/isPdf.js'
import isSecureViewerAvailable from './utils/isSecureViewerAvailable.js'

window.addEventListener('DOMContentLoaded', function() {
logger.debug('Initializing for public page', {
isPublicPage: isPublicPage(),
canDownload: canDownload(),
hideDownload: hideDownload(),
isSecureViewerAvailable: isSecureViewerAvailable(),
})

Expand All @@ -53,8 +53,8 @@ window.addEventListener('DOMContentLoaded', function() {

const sharingToken = sharingTokenElmt.value
const downloadUrl = generateUrl('/s/{token}/download', { token: sharingToken })
const viewerUrl = generateUrl('/apps/files_pdfviewer/?file={downloadUrl}&canDownload={canDownload}#page={page}', {
canDownload: canDownload() ? 1 : 0,
const viewerUrl = generateUrl('/apps/files_pdfviewer/?file={downloadUrl}&hideDownload={hideDownload}#page={page}', {
hideDownload: hideDownload() ? 1 : 0,
downloadUrl,
page,
})
Expand Down
2 changes: 1 addition & 1 deletion src/utils/canDownload.js → src/utils/hideDownload.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
*/

const hideDownloadElmt = document.getElementById('hideDownload')
export default () => !hideDownloadElmt || (hideDownloadElmt && hideDownloadElmt.value !== 'true')
export default () => hideDownloadElmt && hideDownloadElmt.value === 'true'
4 changes: 2 additions & 2 deletions src/utils/isSecureViewerAvailable.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
*
*/

import canDownload from './canDownload.js'
import hideDownload from './hideDownload.js'

export default () => !canDownload() && typeof OCA.RichDocuments !== 'undefined'
export default () => hideDownload() && typeof OCA.RichDocuments !== 'undefined'
6 changes: 3 additions & 3 deletions src/views/PDFView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { getLanguage } from '@nextcloud/l10n'
import { generateUrl } from '@nextcloud/router'
import logger from '../services/logger.js'
import uploadPdfFile from '../services/uploadPdfFile.js'
import canDownload from '../utils/canDownload.js'
import hideDownload from '../utils/hideDownload.js'
import isPdf from '../utils/isPdf.js'
import isPublicPage from '../utils/isPublicPage.js'

Expand All @@ -48,8 +48,8 @@ export default {

computed: {
iframeSrc() {
return generateUrl('/apps/files_pdfviewer/?file={file}&canDownload={canDownload}', {
canDownload: canDownload() ? 1 : 0,
return generateUrl('/apps/files_pdfviewer/?file={file}&hideDownload={hideDownload}', {
hideDownload: hideDownload() ? 1 : 0,
file: this.source ?? this.davPath,
})
},
Expand Down
6 changes: 3 additions & 3 deletions src/workersrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import redirectIfNotIframe from './utils/redirectIfNotIframe.js'
// Checks if the page is displayed in an iframe. If not redirect to /.
redirectIfNotIframe()

// Retrieve the canDownload from the url, this is
// Retrieve the hideDownload from the url, this is
// the most easy way to pass the prop to this iframe
const queryString = window.location.search
const urlParams = new URLSearchParams(queryString)
const canDownload = urlParams.get('canDownload')
const hideDownload = urlParams.get('hideDownload')

function initializeCustomPDFViewerApplication() {
const head = document.getElementsByTagName('head')[0]
Expand All @@ -49,7 +49,7 @@ function initializeCustomPDFViewerApplication() {
PDFViewerApplicationOptions.set('imageResourcesPath', './js/pdfjs/web/images/')
PDFViewerApplicationOptions.set('enableScripting', head.getAttribute('data-enableScripting') === true)

if (canDownload === '0') {
if (hideDownload === '1') {
const pdfViewer = window.document.querySelector('.pdfViewer')

if (pdfViewer) {
Expand Down