Change many lines
This commit is contained in:
26
src/routes/g/[slug]/[[timestamp]]/i/[...item]/d/+server.js
Normal file
26
src/routes/g/[slug]/[[timestamp]]/i/[...item]/d/+server.js
Normal 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'
|
||||
}
|
||||
});
|
||||
}
|
||||
17
src/routes/g/[slug]/[[timestamp]]/i/[...item]/t/+server.js
Normal file
17
src/routes/g/[slug]/[[timestamp]]/i/[...item]/t/+server.js
Normal file
@ -0,0 +1,17 @@
|
||||
import { error } from '@sveltejs/kit';
|
||||
|
||||
/** @type {import('./$types').RequestHandler} */
|
||||
export function GET({ url }) {
|
||||
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));
|
||||
}
|
||||
Reference in New Issue
Block a user