File size: 851 Bytes
786115c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0b2a549
786115c
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { base } from "$app/paths";
import { ENABLE_ASSISTANTS } from "$env/static/private";
import { collections } from "$lib/server/database.js";
import type { Assistant } from "$lib/types/Assistant";
import { redirect } from "@sveltejs/kit";

export const load = async ({ url }) => {
	if (!ENABLE_ASSISTANTS) {
		throw redirect(302, `${base}/`);
	}

	const modelId = url.searchParams.get("modelId");

	// fetch the top 10 assistants sorted by user count from biggest to smallest, filter out all assistants with only 1 users. filter by model too if modelId is provided
	const assistants = await collections.assistants
		.find({ userCount: { $gt: 1 }, modelId: modelId ?? { $exists: true }, featured: true })
		.sort({ userCount: -1 })
		.limit(10)
		.toArray();

	return { assistants: JSON.parse(JSON.stringify(assistants)) as Array<Assistant> };
};