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

View File

@ -260,14 +260,16 @@ export function createQuery (dontDestroy?: boolean): LiveQuery {
/** /**
* @public * @public
*/ */
export function getFileUrl (file: string, size: IconSize = 'full'): string { export function getFileUrl (file: string, size: IconSize = 'full', filename?: string): string {
if (file.includes('://')) { if (file.includes('://')) {
return file return file
} }
const uploadUrl = getMetadata(plugin.metadata.UploadURL) const uploadUrl = getMetadata(plugin.metadata.UploadURL)
const token = getMetadata(plugin.metadata.Token) const token = getMetadata(plugin.metadata.Token)
const url = `${uploadUrl as string}?file=${file}&token=${token as string}&size=${size as string}` if (filename !== undefined) {
return url 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 const filesHandler = async (req: any, res: Response): Promise<void> => {
app.get('/files', async (req, res: Response) => {
try { try {
const token = req.query.token as string const token = req.query.token as string
const payload = decodeToken(token) const payload = decodeToken(token)
@ -236,7 +235,13 @@ export function start (
console.log(error) console.log(error)
res.status(500).send() 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 // eslint-disable-next-line @typescript-eslint/no-misused-promises
app.post('/files', async (req, res) => { app.post('/files', async (req, res) => {