Signed-off-by: Vinicius Reis <vinicius.reis@nextcloud.com>
This commit is contained in:
Vinicius Reis 2022-06-08 16:14:29 -03:00 ΠΊΠΎΠΌΠΌΠΈΡ‚ ΠΏΡ€ΠΎΠΈΠ·Π²Ρ‘Π» Julius HΓ€rtl
Π ΠΎΠ΄ΠΈΡ‚Π΅Π»ΡŒ 8da4222fed
ΠšΠΎΠΌΠΌΠΈΡ‚ 7429ce8bfb
НС Π½Π°ΠΉΠ΄Π΅Π½ ΠΊΠ»ΡŽΡ‡, ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΉ Π΄Π°Π½Π½ΠΎΠΉ подписи
Π˜Π΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ ΠΊΠ»ΡŽΡ‡Π° GPG: 4C614C6ED2CDE6DF
1 ΠΈΠ·ΠΌΠ΅Π½Ρ‘Π½Π½Ρ‹Ρ… Ρ„Π°ΠΉΠ»ΠΎΠ²: 28 Π΄ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠΉ ΠΈ 9 ΡƒΠ΄Π°Π»Π΅Π½ΠΈΠΉ

ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„Π°ΠΉΠ»

@ -52,13 +52,16 @@ export default class ImageResolver {
const imageFileName = getQueryVariable(src, 'imageFileName')
return [this.#getAttachmentUrl(imageFileName)]
}
if (this.#session && src.startsWith(`.attachments.${this.#session?.documentId}/`)) {
const imageFileName = decodeURIComponent(src.replace(`.attachments.${this.#session?.documentId}/`, '').split('?')[0])
return [this.#getAttachmentUrl(imageFileName)]
}
if (isDirectUrl(src)) {
return [src]
}
if (hasPreview(src)) { // && this.#mime !== 'image/gif') {
return [this.#previewUrl(src)]
}
@ -71,6 +74,7 @@ export default class ImageResolver {
// try the webdav url and attachment API if the fails
return [this.#davUrl(src), attachmentUrl]
}
return [this.#davUrl(src)]
}
@ -80,12 +84,14 @@ export default class ImageResolver {
`${this.#attachmentDirectory}/${imageFileName}`
)
}
if (this.#user || !this.#shareToken) {
return generateUrl('/apps/text/image?documentId={documentId}&sessionId={sessionId}&sessionToken={sessionToken}&imageFileName={imageFileName}', {
...this.#textApiParams(),
imageFileName,
})
}
return generateUrl('/apps/text/image?documentId={documentId}&sessionId={sessionId}&sessionToken={sessionToken}&imageFileName={imageFileName}&shareToken={shareToken}', {
...this.#textApiParams(),
imageFileName,
@ -101,6 +107,8 @@ export default class ImageResolver {
sessionToken: this.#session.token,
}
}
return {}
}
#previewUrl(src) {
@ -108,15 +116,19 @@ export default class ImageResolver {
const path = this.#filePath(src)
const fileQuery = `file=${encodeURIComponent(path)}`
const query = fileQuery + '&x=1024&y=1024&a=true'
if (this.#user && imageFileId) {
return generateUrl(`/core/preview?fileId=${imageFileId}&${query}`)
}
if (this.#user) {
return generateUrl(`/core/preview.png?${query}`)
}
if (this.#shareToken) {
return generateUrl(`/apps/files_sharing/publicpreview/${this.#shareToken}?${query}`)
}
console.error('No way to authenticate image retrival - need to be logged in or provide a token')
return src
}
@ -126,16 +138,17 @@ export default class ImageResolver {
const uid = this.#user.uid
const encoded = encodeURI(this.#filePath(src))
return generateRemoteUrl(`dav/files/${uid}${encoded}`)
} else {
const path = this.#filePath(src).split('/')
const basename = path.pop()
const dirname = path.join('/')
return generateUrl('/s/{token}/download?path={dirname}&files={basename}', {
token: this.#shareToken,
basename,
dirname,
})
}
const path = this.#filePath(src).split('/')
const basename = path.pop()
const dirname = path.join('/')
return generateUrl('/s/{token}/download?path={dirname}&files={basename}', {
token: this.#shareToken,
basename,
dirname,
})
}
/**
@ -150,6 +163,7 @@ export default class ImageResolver {
getQueryVariable(src, 'imageFileName'),
].join('/')
}
return decodeURI(src.split('?')[0])
}
@ -158,6 +172,7 @@ export default class ImageResolver {
this.#currentDirectory,
this.#relativePath(src),
].join('/')
return pathNormalize(f)
}
@ -196,13 +211,17 @@ function hasPreview(src) {
*/
function getQueryVariable(src, variable) {
const query = src.split('?')[1]
if (typeof query === 'undefined') {
return
}
const vars = query.split(/[&#]/)
if (typeof vars === 'undefined') {
return
}
for (let i = 0; i < vars.length; i++) {
const pair = vars[i].split('=')
if (decodeURIComponent(pair[0]) === variable) {