Change many lines

This commit is contained in:
Luca Bosin
2023-08-17 09:41:41 +02:00
parent 5e99dc4aa2
commit ba42d6958a
36 changed files with 1251 additions and 312 deletions

View File

@ -0,0 +1,24 @@
import StreamZip from 'node-stream-zip';
import sharp from 'sharp';
/** @type {import('./$types').RequestHandler} */
export async function GET({ params }) {
let entryData = null;
try {
const zip = new StreamZip.async({ file: `./zip/${params.slug}.zip` });
const entries = Object.values(await zip.entries()).filter(entry => entry.name.endsWith('.jpg'));
const entry = entries[Math.floor(Math.random() * entries.length)];
const content = await zip.entryData(entry.name);
await zip.close();
entryData = await sharp(content).resize(400).avif({ quality: 70, effort: 0 }).toBuffer()
} catch (err) {
console.error(err);
}
return new Response(entryData, {
headers: {
'Content-Type': 'image/avif',
'Content-Disposition': 'inline'
}
});
}