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