src/lib/feed.ts 952 B raw
1
import type { ImageItem } from "$lib/types";
2
3
const R2_BASE_URL = "https://r2.steve.photo";
4
5
export async function getPhotos(
6
	platform: App.Platform | undefined,
7
): Promise<ImageItem[]> {
8
	const db = platform?.env?.DB;
9
10
	if (!db) {
11
		return [];
12
	}
13
14
	const result = await db
15
		.prepare("SELECT * FROM photos ORDER BY date DESC")
16
		.all();
17
18
	const photos: ImageItem[] = result.results.map(
19
		(row: Record<string, unknown>) => ({
20
			slug: row.slug as string,
21
			title: row.title as string,
22
			date: row.date as string,
23
			image: `${R2_BASE_URL}/${row.image_key}`,
24
			thumb: `${R2_BASE_URL}/${row.thumb_key}`,
25
			type: row.type as string,
26
			camera: row.camera as string,
27
			lens: row.lens as string,
28
			aperture: row.aperture as string,
29
			exposure: row.exposure as string,
30
			focalLength: row.focal_length as string,
31
			iso: row.iso as string,
32
			make: row.make as string,
33
			tags: [],
34
			blurData: row.blur_data as string,
35
		}),
36
	);
37
38
	return photos;
39
}