fix: encodeURI for thumbnails and timelapse files (#539)

GET requests including file names with special characters such as '%' will properly encode the request to the server.
This commit is contained in:
Kevin Nguyen 2022-01-17 19:04:16 -05:00 committed by GitHub
parent bf60aef344
commit 7b19c902de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 12 deletions

View File

@ -924,7 +924,9 @@ export default class GcodefilesPanel extends Mixins(BaseMixin) {
thumb.height >= thumbnailSmallMin && thumb.height <= thumbnailSmallMax
)
if (thumbnail && 'relative_path' in thumbnail) return this.apiUrl+'/server/files/'+this.currentPath+'/'+encodeURI(thumbnail.relative_path)+'?timestamp='+item.modified.getTime()
if (thumbnail && 'relative_path' in thumbnail) {
return encodeURI(`${this.apiUrl}/server/files/${this.currentPath}/${thumbnail.relative_path}?timestamp=${item.modified.getTime()}`)
}
}
return ''
@ -934,7 +936,9 @@ export default class GcodefilesPanel extends Mixins(BaseMixin) {
if (item.thumbnails?.length) {
const thumbnail = item.thumbnails.find(thumb => thumb.width >= thumbnailBigMin)
if (thumbnail && 'relative_path' in thumbnail) return this.apiUrl+'/server/files/'+this.currentPath+'/'+encodeURI(thumbnail.relative_path)+'?timestamp='+item.modified.getTime()
if (thumbnail && 'relative_path' in thumbnail) {
return encodeURI(`${this.apiUrl}/server/files/${this.currentPath}/${thumbnail.relative_path}?timestamp=${item.modified.getTime()}`)
}
}
return ''

View File

@ -595,8 +595,9 @@ export default class HistoryListPanel extends Mixins(BaseMixin) {
relative_url = item.filename.substr(0, item.filename.lastIndexOf('/')+1)
}
if (thumbnail && 'relative_path' in thumbnail)
return this.apiUrl+'/server/files/gcodes/'+relative_url+thumbnail.relative_path+'?timestamp='+item.metadata.modified
if (thumbnail && 'relative_path' in thumbnail) {
return encodeURI(`${this.apiUrl}/server/files/gcodes/${relative_url+thumbnail.relative_path}?timestamp=${item.metadata.modified}`)
}
}
return false
@ -616,7 +617,7 @@ export default class HistoryListPanel extends Mixins(BaseMixin) {
}
if (thumbnail && 'relative_path' in thumbnail)
return this.apiUrl+'/server/files/gcodes/'+relative_url+thumbnail.relative_path+'?timestamp='+item.metadata.modified
return encodeURI(`${this.apiUrl}/server/files/gcodes/${relative_url+thumbnail.relative_path}?timestamp=${item.metadata.modified}`)
}
return false

View File

@ -657,7 +657,7 @@ export default class ConfigFilesPanel extends Mixins(BaseMixin) {
downloadFile() {
const filename = (this.absolutePath+'/'+this.contextMenu.item.filename)
const href = this.apiUrl + '/server/files' + filename
const href = encodeURI(`${this.apiUrl}/server/files${filename}`)
window.open(href)
}

View File

@ -513,8 +513,9 @@ export default class StatusPanel extends Mixins(BaseMixin) {
relative_url = this.current_file.filename.substr(0, this.current_file.filename.lastIndexOf('/')+1)
}
if (thumbnail && 'relative_path' in thumbnail)
return this.apiUrl+'/server/files/gcodes/'+relative_url+thumbnail.relative_path+'?timestamp='+this.current_file.modified
if (thumbnail && 'relative_path' in thumbnail) {
return encodeURI(`${this.apiUrl}/server/files/gcodes/${relative_url+thumbnail.relative_path}?timestamp=${this.current_file.modified}`)
}
}
}
@ -534,8 +535,9 @@ export default class StatusPanel extends Mixins(BaseMixin) {
relative_url = this.current_file.filename.substr(0, this.current_file.filename.lastIndexOf('/')+1)
}
if (thumbnail && 'relative_path' in thumbnail)
return this.apiUrl+'/server/files/gcodes/'+relative_url+thumbnail.relative_path+'?timestamp='+this.current_file.modified
if (thumbnail && 'relative_path' in thumbnail) {
return encodeURI(`${this.apiUrl}/server/files/gcodes/${relative_url+thumbnail.relative_path}?timestamp=${this.current_file.modified}`)
}
}
}

View File

@ -443,7 +443,7 @@ export default class TimelapseFilesPanel extends Mixins(BaseMixin) {
const filename = item.filename.slice(0, item.filename.lastIndexOf('.'))
const preview = this.files?.find((file) => file.filename === filename+'.jpg')
if (preview) {
return this.apiUrl+'/server/files/'+this.currentPath+'/'+preview.filename+'?timestamp='+preview.modified.getTime()
return encodeURI(`${this.apiUrl}/server/files/${this.currentPath}/${preview.filename}?timestamp=${preview.modified.getTime()}`)
}
return ''
@ -457,7 +457,7 @@ export default class TimelapseFilesPanel extends Mixins(BaseMixin) {
else if (item.filename.endsWith('zip')) {
this.downloadFile(item.filename)
} else if (item.filename.endsWith('mp4')) {
this.videoDialogFilename = this.currentPath + '/' + item.filename
this.videoDialogFilename = encodeURI(`${this.currentPath}/${item.filename}`)
this.boolVideoDialog = true
}
}