File size: 1,205 Bytes
727ce74
 
5dfd24d
83deba1
 
5dfd24d
 
 
83deba1
f05d33c
83deba1
 
 
 
 
727ce74
 
 
 
 
83deba1
 
5dfd24d
549506b
5dfd24d
549506b
 
 
 
 
c479a59
 
 
 
 
83deba1
 
 
 
549506b
 
727ce74
83deba1
97ec6f2
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
41
42
43
44
import { modelStore } from "$lib/stores/use-model";

/** @type {import('./$types').PageServerLoad} */
export async function load({ fetch, url }) {
  const model_param = url.searchParams.get("model")
  const search_param = url.searchParams.get("search") ?? undefined
  const filter_param = url.searchParams.get("filter") ?? undefined
  
  if (model_param) {
    const model_request = await fetch(`/api/models/${model_param?.replace("/", "@")}?full=true`, {
      method: "GET",
      headers: {
        "Content-Type": "application/json"
      }
    })
    const data = await model_request?.clone().json().catch(() => null);
    modelStore.set({
      model: data?.model ?? null,
      open: true
    });
  }

  
  const data = {
    filter: filter_param ?? "hotest",
    page: "0",
    search: search_param ?? ""
  }

  const response = await fetch(`/api/models?${new URLSearchParams(data)}`, {
    method: "GET",
    headers: {
      "Content-Type": "application/json"
    }
  })
  const models = await response.json()
  return {
    models: models?.cards ?? [],
    total_items: models?.total_items ?? 0,
    search: search_param ?? "",
    filter: filter_param,
    // model: model?.model ?? null
  }
}