Skip to content

Commit

Permalink
Use consistent url for the preview with the activity app
Browse files Browse the repository at this point in the history
Allows to incrase the likehook of browser cache hits

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
  • Loading branch information
CarlSchwan committed Feb 25, 2022
1 parent 4cdc890 commit 71c1274
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions apps/files/js/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -2381,12 +2381,39 @@
*/
urlSpec.a = this._filesConfig.get('cropimagepreviews') ? 0 : 1;

// Use map to get consistent parameter ordering with activity app generated URl (php)
const urlSpecMap = new Map()
urlSpecMap.set('forceIcon', urlSpec.forceIcon)
urlSpecMap.set('a', urlSpec.a)
urlSpecMap.set('x', urlSpec.x)
urlSpecMap.set('y', urlSpec.y)

if (urlSpec.mode) {
urlSpecMap.set('mode', urlSpec.mode)
}

if (typeof urlSpec.fileId !== 'undefined') {
delete urlSpec.file;
return OC.generateUrl('/core/preview?') + $.param(urlSpec);
urlSpecMap.set('fileId', urlSpec.fileId)
urlSpecMap.set('c', urlSpec.c)

let param = []
urlSpecMap.forEach((value, key) => {
param.push(encodeURIComponent(key) + '=' + encodeURIComponent(value))
})
param = param.join('&')

return window.location.protocol + '//' + window.location.hostname + OC.generateUrl('/core/preview?') + param
} else {
delete urlSpec.fileId;
return OC.generateUrl('/core/preview.png?') + $.param(urlSpec);
urlSpecMap.set('file', urlSpec.file)
urlSpecMap.set('c', urlSpec.c)

let param = []
urlSpecMap.forEach((key, value) => {
param.push(encodeURIComponent(key) + '=' + encodeURIComponent(value))
})
param = param.join('&')

return window.location.protocol + '//' + window.location.hostname + OC.generateUrl('/core/preview.png?') + param
}

},
Expand Down

0 comments on commit 71c1274

Please sign in to comment.