fix missing attached filenames (#3172)

Signed-off-by: Ruslan Bayandinov <wazsone@ya.ru>
This commit is contained in:
Ruslan Bayandinov 2023-05-12 10:24:42 +04:00 committed by GitHub
parent 0473d9eaf9
commit a57f3b8c2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 9 deletions

View File

@ -61,7 +61,7 @@
</svelte:fragment>
<svelte:fragment slot="utils">
<a class="no-line" href={getFileUrl(file)} download={name} bind:this={download}>
<a class="no-line" href={getFileUrl(file, 'full', name)} download={name} bind:this={download}>
<Button
icon={Download}
kind={'transparent'}
@ -75,14 +75,14 @@
{#if contentType && contentType.startsWith('image/')}
<div class="pdfviewer-content img" style:margin={$deviceInfo.minWidth ? '.5rem' : '1.5rem'}>
<img class="img-fit" src={getFileUrl(file)} alt="" />
<img class="img-fit" src={getFileUrl(file, 'full', name)} alt="" />
</div>
<div class="space" />
{:else}
<iframe
class="pdfviewer-content"
style:margin={$deviceInfo.minWidth ? '.5rem' : '1.5rem'}
src={getFileUrl(file) + '#view=FitH&navpanes=0'}
src={getFileUrl(file, 'full', name) + '#view=FitH&navpanes=0'}
title=""
/>
{/if}

View File

@ -260,14 +260,16 @@ export function createQuery (dontDestroy?: boolean): LiveQuery {
/**
* @public
*/
export function getFileUrl (file: string, size: IconSize = 'full'): string {
export function getFileUrl (file: string, size: IconSize = 'full', filename?: string): string {
if (file.includes('://')) {
return file
}
const uploadUrl = getMetadata(plugin.metadata.UploadURL)
const token = getMetadata(plugin.metadata.Token)
const url = `${uploadUrl as string}?file=${file}&token=${token as string}&size=${size as string}`
return url
if (filename !== undefined) {
return `${uploadUrl as string}/${filename}?file=${file}&token=${token as string}&size=${size as string}`
}
return `${uploadUrl as string}?file=${file}&token=${token as string}&size=${size as string}`
}
/**

View File

@ -216,8 +216,7 @@ export function start (
}
})
// eslint-disable-next-line @typescript-eslint/no-misused-promises
app.get('/files', async (req, res: Response) => {
const filesHandler = async (req: any, res: Response): Promise<void> => {
try {
const token = req.query.token as string
const payload = decodeToken(token)
@ -236,7 +235,13 @@ export function start (
console.log(error)
res.status(500).send()
}
})
}
// eslint-disable-next-line @typescript-eslint/no-misused-promises
app.get('/files/', filesHandler)
// eslint-disable-next-line @typescript-eslint/no-misused-promises
app.get('/files/*', filesHandler)
// eslint-disable-next-line @typescript-eslint/no-misused-promises
app.post('/files', async (req, res) => {