Skip to content

Commit

Permalink
Rename "canDownload" to "hideDownload"
Browse files Browse the repository at this point in the history
"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 authored and backportbot[bot] committed Dec 7, 2024
1 parent a925f8c commit 6e5a8ed
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,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 @@ -36,8 +36,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 @@ -3,4 +3,4 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
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 @@ -2,6 +2,6 @@
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
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 @@ -14,7 +14,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 @@ -30,8 +30,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 @@ -10,11 +10,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 @@ -32,7 +32,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

0 comments on commit 6e5a8ed

Please sign in to comment.