forked from ChatGPTNextWeb/ChatGPT-Next-Web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
38 lines (33 loc) · 1.01 KB
/
index.ts
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
import { Mask } from "../store/mask";
import { type BuiltinMask } from "./typing";
export { type BuiltinMask } from "./typing";
export const BUILTIN_MASK_ID = 100000;
export const BUILTIN_MASK_STORE = {
buildinId: BUILTIN_MASK_ID,
masks: {} as Record<string, BuiltinMask>,
get(id?: string) {
if (!id) return undefined;
return this.masks[id] as Mask | undefined;
},
add(m: BuiltinMask) {
const mask = { ...m, id: this.buildinId++, builtin: true };
this.masks[mask.id] = mask;
return mask;
},
};
export const BUILTIN_MASKS: BuiltinMask[] = [];
if (typeof window != "undefined") {
// run in browser skip in next server
fetch("/masks.json")
.then((res) => res.json())
.catch((error) => {
console.error("[Fetch] failed to fetch masks", error);
return { cn: [], tw: [], en: [] };
})
.then((masks) => {
const { cn = [], tw = [], en = [] } = masks;
return [...cn, ...tw, ...en].map((m) => {
BUILTIN_MASKS.push(BUILTIN_MASK_STORE.add(m));
});
});
}