fix: allow download query on non raw

This commit is contained in:
diced 2023-03-04 17:50:14 -08:00
parent 6583f1114c
commit ac05d82e3a
No known key found for this signature in database
GPG key ID: 370BD1BA142842D1

View file

@ -8,6 +8,8 @@ function dbFileDecorator(fastify: FastifyInstance, _, done) {
done();
async function dbFile(this: FastifyReply, file: File) {
const { download } = this.request.query as { download?: string };
const ext = file.name.split('.').pop();
if (Object.keys(exts).includes(ext)) return this.server.nextHandle(this.request.raw, this.raw);
@ -17,7 +19,7 @@ function dbFileDecorator(fastify: FastifyInstance, _, done) {
const size = await this.server.datasource.size(file.name);
this.header('Content-Length', size);
this.header('Content-Type', file.mimetype);
this.header('Content-Type', download ? 'application/octet-stream' : file.mimetype);
this.header('Content-Disposition', `inline; filename="${file.originalName || file.name}"`);
return this.send(data);