Skip to content
Open
Changes from all commits
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
21 changes: 13 additions & 8 deletions src/views/PDFView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,22 @@ export default {
},

isDownloadable() {
if (!this.file.shareAttributes) {
if (!this.file || !this.file.shareAttributes) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to use instead the optional chanining operator:

if (!this.file?.shareAttributes) {

as it is shorter and also consistent with other usages (see, for example, isEditable()).

The optional chaining operator should be applied too in hideDownload above.

return true
}

const shareAttributes = JSON.parse(this.file.shareAttributes)
const downloadPermissions = shareAttributes.find(({ scope, key }) => scope === 'permissions' && key === 'download')
if (downloadPermissions) {
return downloadPermissions.value
try {
const shareAttributes = JSON.parse(this.file.shareAttributes)
const downloadPermissions = shareAttributes.find(({ scope, key }) => scope === 'permissions' && key === 'download')
if (downloadPermissions) {
return downloadPermissions.value
}
return true
} catch (e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The try { } catch should enclose only the const shareAttributes = JSON.parse(this.file.shareAttributes) statement, as it is guarding against a parsing error, and the rest of statements should be safe to execute (at least if the function returns early in the catch like it does now).

logger.error('Error parsing shareAttributes:', e)
// If shareAttributes can not be parsed, assume the file is
// downloadable to avoid locking users out of their files.
return true
}

return true
},

isRichDocumentsAvailable() {
Expand Down