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,26 @@
import { error } from '@sveltejs/kit';
/** @type {import('./$types').RequestHandler} */
export function GET({ url }) {
const noAttachment = url.searchParams.has('r');
const min = Number(url.searchParams.get('min') ?? '0');
const max = Number(url.searchParams.get('max') ?? '1');
const d = max - min;
if (isNaN(d) || d < 0) {
throw error(400, 'min and max must be numbers, and min must be less than max');
}
const random = min + Math.random() * d;
return new Response(String(random), {
headers: {
'Content-Type': 'text/plain',
'Content-Disposition': noAttachment ? 'inline' : 'attachment'
}
});
}