From 2adb35518341a462df8b0f0c2e55c8145deeb5b8 Mon Sep 17 00:00:00 2001 From: diced Date: Fri, 13 Jan 2023 17:28:38 -0800 Subject: [PATCH] feat: download query on /r/ --- src/server/decorators/rawFile.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/server/decorators/rawFile.ts b/src/server/decorators/rawFile.ts index 9d88e690..7f2b121f 100644 --- a/src/server/decorators/rawFile.ts +++ b/src/server/decorators/rawFile.ts @@ -8,6 +8,8 @@ function rawFileDecorator(fastify: FastifyInstance, _, done) { done(); async function rawFile(this: FastifyReply, id: string) { + const { download } = this.request.query as { download?: string }; + const data = await this.server.datasource.get(id); if (!data) return this.notFound(); @@ -15,7 +17,7 @@ function rawFileDecorator(fastify: FastifyInstance, _, done) { const size = await this.server.datasource.size(id); this.header('Content-Length', size); - this.header('Content-Type', mimetype); + this.header('Content-Type', download ? 'application/octet-stream' : mimetype); return this.send(data); } }