Remove JSON mode from download endpoint

This commit is contained in:
Luca Bosin
2023-08-28 08:40:27 +02:00
parent 7c8e9fc1a0
commit 342b586ab9

View File

@ -4,7 +4,7 @@ import { error } from '@sveltejs/kit';
import fs from 'node:fs/promises'; import fs from 'node:fs/promises';
import type { RequestHandler } from './$types'; import type { RequestHandler } from './$types';
export const GET: RequestHandler = async ({ params, url }) => { export const GET: RequestHandler = async ({ params }) => {
try { try {
const zipName = getZipName(params); const zipName = getZipName(params);
const album = await getMetadata(zipName); const album = await getMetadata(zipName);
@ -12,22 +12,13 @@ export const GET: RequestHandler = async ({ params, url }) => {
if (!allowDownload) { if (!allowDownload) {
throw error(403, 'Forbidden'); throw error(403, 'Forbidden');
} }
if (url.searchParams.get('type') === 'json') { const content = await fs.readFile(`./zip/${zipName}`);
return new Response(JSON.stringify(album), { return new Response(content, {
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/zip',
'Content-Disposition': 'inline' 'Content-Disposition': `attachment; filename="${zipName}"`
} }
}); });
} else {
const content = await fs.readFile(`./zip/${zipName}`);
return new Response(content, {
headers: {
'Content-Type': 'application/zip',
'Content-Disposition': `attachment; filename="${zipName}"`
}
});
}
} catch (err) { } catch (err) {
throw error(404, 'Not found'); throw error(404, 'Not found');
} }