File size: 1,010 Bytes
65b4f03
 
 
 
fa79853
de10f77
65b4f03
 
 
 
 
fa79853
 
 
de10f77
fa79853
65b4f03
fa79853
bd9595b
36f8d04
 
 
 
 
 
65b4f03
 
 
 
 
bd9595b
36f8d04
 
 
 
 
 
65b4f03
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import type { LayoutServerLoad } from './$types';
import '$lib/server/db';
import { pages } from '$lib/server/db/page';
import type { Picture } from '$lib/types/Picture';
import { filterNullish } from '$lib/utils/filterNullish';
import { collections } from '$lib/server/db';

export const load: LayoutServerLoad = async (input) => {
	const pageId = input.url.pathname;

	if (pageId in pages) {
		const pageData = pages[pageId as keyof typeof pages];

		const pictureIds = filterNullish(Object.values(pageData.pictures));
		const pics = await collections.pictures.find({ _id: { $in: pictureIds } }).toArray();

		return {
			pageData,
			pictures: pics,
			user: input.locals.user
				? {
						email: input.locals.user.email,
						admin: input.locals.user.authority === 'admin'
				  }
				: null
		};
	}

	return {
		pageData: null,
		pictures: [] as Picture[],
		user: input.locals.user
			? {
					email: input.locals.user.email,
					admin: input.locals.user.authority === 'admin'
			  }
			: null
	};
};