feat: wont fetch prompts in every building
This commit is contained in:
parent
30676d118f
commit
93044590cc
2
.gitignore
vendored
2
.gitignore
vendored
@ -36,8 +36,6 @@ yarn-error.log*
|
|||||||
next-env.d.ts
|
next-env.d.ts
|
||||||
dev
|
dev
|
||||||
|
|
||||||
public/prompts.json
|
|
||||||
|
|
||||||
.vscode
|
.vscode
|
||||||
.idea
|
.idea
|
||||||
|
|
||||||
|
@ -4,11 +4,11 @@
|
|||||||
"private": false,
|
"private": false,
|
||||||
"license": "Anti 996",
|
"license": "Anti 996",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "yarn fetch && next dev",
|
"dev": "next dev",
|
||||||
"build": "yarn fetch && next build",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"lint": "next lint",
|
"lint": "next lint",
|
||||||
"fetch": "node ./scripts/fetch-prompts.mjs",
|
"prompts": "node ./scripts/fetch-prompts.mjs",
|
||||||
"prepare": "husky install",
|
"prepare": "husky install",
|
||||||
"proxy-dev": "sh ./scripts/init-proxy.sh && proxychains -f ./scripts/proxychains.conf yarn dev"
|
"proxy-dev": "sh ./scripts/init-proxy.sh && proxychains -f ./scripts/proxychains.conf yarn dev"
|
||||||
},
|
},
|
||||||
|
1144
public/prompts.json
Normal file
1144
public/prompts.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -2,7 +2,7 @@ import fetch from "node-fetch";
|
|||||||
import fs from "fs/promises";
|
import fs from "fs/promises";
|
||||||
|
|
||||||
const RAW_FILE_URL = "https://raw.githubusercontent.com/";
|
const RAW_FILE_URL = "https://raw.githubusercontent.com/";
|
||||||
const MIRRORF_FILE_URL = "https://raw.fgit.ml/";
|
const MIRRORF_FILE_URL = "http://raw.fgit.ml/";
|
||||||
|
|
||||||
const RAW_CN_URL = "PlexPt/awesome-chatgpt-prompts-zh/main/prompts-zh.json";
|
const RAW_CN_URL = "PlexPt/awesome-chatgpt-prompts-zh/main/prompts-zh.json";
|
||||||
const CN_URL = MIRRORF_FILE_URL + RAW_CN_URL;
|
const CN_URL = MIRRORF_FILE_URL + RAW_CN_URL;
|
||||||
@ -10,10 +10,12 @@ const RAW_EN_URL = "f/awesome-chatgpt-prompts/main/prompts.csv";
|
|||||||
const EN_URL = MIRRORF_FILE_URL + RAW_EN_URL;
|
const EN_URL = MIRRORF_FILE_URL + RAW_EN_URL;
|
||||||
const FILE = "./public/prompts.json";
|
const FILE = "./public/prompts.json";
|
||||||
|
|
||||||
|
const ignoreWords = ["涩涩", "魅魔"];
|
||||||
|
|
||||||
const timeoutPromise = (timeout) => {
|
const timeoutPromise = (timeout) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
reject(new Error('Request timeout'));
|
reject(new Error("Request timeout"));
|
||||||
}, timeout);
|
}, timeout);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -21,10 +23,16 @@ const timeoutPromise = (timeout) => {
|
|||||||
async function fetchCN() {
|
async function fetchCN() {
|
||||||
console.log("[Fetch] fetching cn prompts...");
|
console.log("[Fetch] fetching cn prompts...");
|
||||||
try {
|
try {
|
||||||
// const raw = await (await fetch(CN_URL)).json();
|
|
||||||
const response = await Promise.race([fetch(CN_URL), timeoutPromise(5000)]);
|
const response = await Promise.race([fetch(CN_URL), timeoutPromise(5000)]);
|
||||||
const raw = await response.json();
|
const raw = await response.json();
|
||||||
return raw.map((v) => [v.act, v.prompt]);
|
return raw
|
||||||
|
.map((v) => [v.act, v.prompt])
|
||||||
|
.filter(
|
||||||
|
(v) =>
|
||||||
|
v[0] &&
|
||||||
|
v[1] &&
|
||||||
|
ignoreWords.every((w) => !v[0].includes(w) && !v[1].includes(w)),
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("[Fetch] failed to fetch cn prompts", error);
|
console.error("[Fetch] failed to fetch cn prompts", error);
|
||||||
return [];
|
return [];
|
||||||
@ -40,7 +48,12 @@ async function fetchEN() {
|
|||||||
return raw
|
return raw
|
||||||
.split("\n")
|
.split("\n")
|
||||||
.slice(1)
|
.slice(1)
|
||||||
.map((v) => v.split('","').map((v) => v.replace(/^"|"$/g, '').replaceAll('""','"')));
|
.map((v) =>
|
||||||
|
v
|
||||||
|
.split('","')
|
||||||
|
.map((v) => v.replace(/^"|"$/g, "").replaceAll('""', '"'))
|
||||||
|
.filter((v) => v[0] && v[1]),
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("[Fetch] failed to fetch en prompts", error);
|
console.error("[Fetch] failed to fetch en prompts", error);
|
||||||
return [];
|
return [];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user