Add route structure

This commit is contained in:
Luca Bosin
2023-08-04 21:51:54 +02:00
parent 8b23cd62e5
commit 5e99dc4aa2
23 changed files with 197 additions and 3 deletions

6
src/routes/+error.svelte Normal file
View File

@ -0,0 +1,6 @@
<script>
import { page } from '$app/stores';
</script>
<h1>{$page.status}</h1>
<p>{$page.error?.message}</p>

View File

@ -1,2 +0,0 @@
<h1>Welcome to SvelteKit</h1>
<p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p>

View File

0
src/routes/g/.gallery Normal file
View File

View File

@ -0,0 +1,16 @@
import { error } from '@sveltejs/kit';
import albums from '$lib/albums.json';
/** @type {import('./$types').PageLoad} */
export function load({ params }) {
const album = albums.find((album) => album.slug === params.slug);
if (album) {
return {
title: album.title,
content: album.description,
image: '/s/lga/?i=LFB04128-Enhanced-NR.jpg'
};
}
throw error(404, 'Not found');
}

View File

@ -0,0 +1,8 @@
<script>
/** @type {import('./$types').PageData} */
export let data;
</script>
<h1>{data.title}</h1>
<div>{@html data.content}</div>
<img src={data.image} alt={data.title} />

View File

View 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));
}

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'
}
});
}

View 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));
}

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'
}
});
}