2023-04-10 17:21:34 +00:00
|
|
|
import md5 from "spark-md5";
|
|
|
|
|
|
|
|
declare global {
|
|
|
|
namespace NodeJS {
|
|
|
|
interface ProcessEnv {
|
|
|
|
OPENAI_API_KEY?: string;
|
|
|
|
CODE?: string;
|
2023-05-19 15:53:27 +00:00
|
|
|
BASE_URL?: string;
|
2023-04-10 17:21:34 +00:00
|
|
|
PROXY_URL?: string;
|
|
|
|
VERCEL?: string;
|
2023-05-03 15:49:33 +00:00
|
|
|
HIDE_USER_API_KEY?: string; // disable user's api key input
|
2023-05-09 15:20:03 +00:00
|
|
|
DISABLE_GPT4?: string; // allow user to use gpt-4 or not
|
2023-06-13 16:37:42 +00:00
|
|
|
BUILD_MODE?: "standalone" | "export";
|
2023-04-10 17:21:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const ACCESS_CODES = (function getAccessCodes(): Set<string> {
|
|
|
|
const code = process.env.CODE;
|
|
|
|
|
|
|
|
try {
|
|
|
|
const codes = (code?.split(",") ?? [])
|
|
|
|
.filter((v) => !!v)
|
|
|
|
.map((v) => md5.hash(v.trim()));
|
|
|
|
return new Set(codes);
|
|
|
|
} catch (e) {
|
|
|
|
return new Set();
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
export const getServerSideConfig = () => {
|
|
|
|
if (typeof process === "undefined") {
|
|
|
|
throw Error(
|
|
|
|
"[Server Config] you are importing a nodejs-only module outside of nodejs",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
apiKey: process.env.OPENAI_API_KEY,
|
|
|
|
code: process.env.CODE,
|
|
|
|
codes: ACCESS_CODES,
|
|
|
|
needCode: ACCESS_CODES.size > 0,
|
2023-05-19 15:53:27 +00:00
|
|
|
baseUrl: process.env.BASE_URL,
|
2023-04-10 17:21:34 +00:00
|
|
|
proxyUrl: process.env.PROXY_URL,
|
|
|
|
isVercel: !!process.env.VERCEL,
|
2023-05-03 15:49:33 +00:00
|
|
|
hideUserApiKey: !!process.env.HIDE_USER_API_KEY,
|
2023-05-09 15:20:03 +00:00
|
|
|
enableGPT4: !process.env.DISABLE_GPT4,
|
2023-04-10 17:21:34 +00:00
|
|
|
};
|
|
|
|
};
|