feat: download query on /r/

This commit is contained in:
diced 2023-01-13 17:28:38 -08:00
parent 5e6c53432b
commit 2adb355183
No known key found for this signature in database
GPG key ID: 370BD1BA142842D1

View file

@ -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);
}
}