fix: "download" link was using real file name instead of assigned one

Massimo Melina committed Apr 4, 2023 at 19:35 UTC 7bcc3aa8778e1ac7ffd62d9e9a072e5ee644d13a
1 file changed +2 -2
src/serveFile.ts
+2 -2
@@ -40,6 +40,8 @@ export function serveFileNode(ctx: Koa.Context, node: VfsNode) {
40 }
41
42 ctx.vfsNode = node // useful to tell service files from files shared by the user
43 + if ('dl' in ctx.params) // please, download
44 + ctx.attachment(name)
45 return serveFile(ctx, source||'', mimeString)
46 }
47
@@ -49,8 +51,6 @@ export async function serveFile(ctx: Koa.Context, source:string, mime?:string, c
51 if (!source)
52 return
53 const fn = path.basename(source)
52 - if ('dl' in ctx.params) // please, download
53 - ctx.attachment(fn)
54 mime = mime ?? _.find(mimeCfg.get(), (v,k) => matches(fn, k))
55 if (mime === MIME_AUTO)
56 mime = mimetypes.lookup(source) || ''