Remove JSON mode from download endpoint
This commit is contained in:
@ -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');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user