Π·Π΅ΡΠΊΠ°Π»ΠΎ ΠΈΠ· https://github.com/nextcloud/text.git
π¨ (#2463): format code
Signed-off-by: Vinicius Reis <vinicius.reis@nextcloud.com>
This commit is contained in:
Π ΠΎΠ΄ΠΈΡΠ΅Π»Ρ
8da4222fed
ΠΠΎΠΌΠΌΠΈΡ
7429ce8bfb
|
@ -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) {
|
||||
|
|
ΠΠ°Π³ΡΡΠ·ΠΊΠ°β¦
Π‘ΡΡΠ»ΠΊΠ° Π² Π½ΠΎΠ²ΠΎΠΉ Π·Π°Π΄Π°ΡΠ΅