| 1 | import { json } from "@sveltejs/kit"; |
| 2 | import type { RequestHandler } from "./$types"; |
| 3 | import type { ImageItem } from "$lib"; |
| 4 | |
| 5 | const R2_BASE_URL = "https://r2.steve.photo"; |
| 6 | const PAGE_SIZE = 15; |
| 7 | |
| 8 | export const GET: RequestHandler = async ({ url, platform }) => { |
| 9 | const db = platform?.env?.DB; |
| 10 | const offset = parseInt(url.searchParams.get("offset") || "0", 10); |
| 11 | |
| 12 | const result = await db |
| 13 | .prepare("SELECT * FROM photos ORDER BY date DESC LIMIT ? OFFSET ?") |
| 14 | .bind(PAGE_SIZE, offset) |
| 15 | .all(); |
| 16 | |
| 17 | const photos: ImageItem[] = result.results.map( |
| 18 | (row: Record<string, unknown>) => ({ |
| 19 | slug: row.slug as string, |
| 20 | title: row.title as string, |
| 21 | date: row.date as string, |
| 22 | image: `${R2_BASE_URL}/${row.image_key}`, |
| 23 | thumb: `${R2_BASE_URL}/${row.thumb_key}`, |
| 24 | type: row.type as string, |
| 25 | camera: row.camera as string, |
| 26 | lens: row.lens as string, |
| 27 | aperture: row.aperture as string, |
| 28 | exposure: row.exposure as string, |
| 29 | focalLength: row.focal_length as string, |
| 30 | iso: row.iso as string, |
| 31 | make: row.make as string, |
| 32 | blurData: row.blur_data as string, |
| 33 | }), |
| 34 | ); |
| 35 | |
| 36 | return json({ photos }); |
| 37 | }; |