mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-11-18 15:03:43 +08:00
style: eslint 规则同步代码格式
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
import packageJson from "../../package.json";
|
||||
import { DEFAULT_INPUT_TEMPLATE } from "../constant";
|
||||
import packageJson from '../../package.json';
|
||||
import { DEFAULT_INPUT_TEMPLATE } from '../constant';
|
||||
|
||||
export const getBuildConfig = () => {
|
||||
if (typeof process === "undefined") {
|
||||
throw Error(
|
||||
"[Server Config] you are importing a nodejs-only module outside of nodejs",
|
||||
export function getBuildConfig() {
|
||||
if (typeof process === 'undefined') {
|
||||
throw new TypeError(
|
||||
'[Server Config] you are importing a nodejs-only module outside of nodejs',
|
||||
);
|
||||
}
|
||||
|
||||
const buildMode = process.env.BUILD_MODE ?? "standalone";
|
||||
const buildMode = process.env.BUILD_MODE ?? 'standalone';
|
||||
const isApp = !!process.env.BUILD_APP;
|
||||
const version = "v" + packageJson.version;
|
||||
const version = `v${packageJson.version}`;
|
||||
|
||||
const commitInfo = (() => {
|
||||
try {
|
||||
const childProcess = require("child_process");
|
||||
const childProcess = require('node:child_process');
|
||||
const commitDate: string = childProcess
|
||||
.execSync('git log -1 --format="%at000" --date=unix')
|
||||
.toString()
|
||||
@@ -26,10 +26,10 @@ export const getBuildConfig = () => {
|
||||
|
||||
return { commitDate, commitHash };
|
||||
} catch (e) {
|
||||
console.error("[Build Config] No git or not from git repo.");
|
||||
console.error('[Build Config] No git or not from git repo.');
|
||||
return {
|
||||
commitDate: "unknown",
|
||||
commitHash: "unknown",
|
||||
commitDate: 'unknown',
|
||||
commitHash: 'unknown',
|
||||
};
|
||||
}
|
||||
})();
|
||||
@@ -41,6 +41,6 @@ export const getBuildConfig = () => {
|
||||
isApp,
|
||||
template: process.env.DEFAULT_INPUT_TEMPLATE ?? DEFAULT_INPUT_TEMPLATE,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export type BuildConfig = ReturnType<typeof getBuildConfig>;
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { BuildConfig, getBuildConfig } from "./build";
|
||||
import type { BuildConfig } from './build';
|
||||
import { getBuildConfig } from './build';
|
||||
|
||||
export function getClientConfig() {
|
||||
if (typeof document !== "undefined") {
|
||||
if (typeof document !== 'undefined') {
|
||||
// client side
|
||||
return JSON.parse(queryMeta("config") || "{}") as BuildConfig;
|
||||
return JSON.parse(queryMeta('config') || '{}') as BuildConfig;
|
||||
}
|
||||
|
||||
if (typeof process !== "undefined") {
|
||||
if (typeof process !== 'undefined') {
|
||||
// server side
|
||||
return getBuildConfig();
|
||||
}
|
||||
@@ -18,9 +19,9 @@ function queryMeta(key: string, defaultValue?: string): string {
|
||||
const meta = document.head.querySelector(
|
||||
`meta[name='${key}']`,
|
||||
) as HTMLMetaElement;
|
||||
ret = meta?.content ?? "";
|
||||
ret = meta?.content ?? '';
|
||||
} else {
|
||||
ret = defaultValue ?? "";
|
||||
ret = defaultValue ?? '';
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import md5 from "spark-md5";
|
||||
import { DEFAULT_MODELS, DEFAULT_GA_ID } from "../constant";
|
||||
import md5 from 'spark-md5';
|
||||
import { DEFAULT_GA_ID, DEFAULT_MODELS } from '../constant';
|
||||
|
||||
declare global {
|
||||
namespace NodeJS {
|
||||
@@ -13,7 +13,7 @@ declare global {
|
||||
OPENAI_ORG_ID?: string; // openai only
|
||||
|
||||
VERCEL?: string;
|
||||
BUILD_MODE?: "standalone" | "export";
|
||||
BUILD_MODE?: 'standalone' | 'export';
|
||||
BUILD_APP?: string; // is building desktop app
|
||||
|
||||
HIDE_USER_API_KEY?: string; // disable user's api key input
|
||||
@@ -89,9 +89,9 @@ 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()));
|
||||
const codes = (code?.split(',') ?? [])
|
||||
.filter(v => !!v)
|
||||
.map(v => md5.hash(v.trim()));
|
||||
return new Set(codes);
|
||||
} catch (e) {
|
||||
return new Set();
|
||||
@@ -99,8 +99,8 @@ const ACCESS_CODES = (function getAccessCodes(): Set<string> {
|
||||
})();
|
||||
|
||||
function getApiKey(keys?: string) {
|
||||
const apiKeyEnvVar = keys ?? "";
|
||||
const apiKeys = apiKeyEnvVar.split(",").map((v) => v.trim());
|
||||
const apiKeyEnvVar = keys ?? '';
|
||||
const apiKeys = apiKeyEnvVar.split(',').map(v => v.trim());
|
||||
const randomIndex = Math.floor(Math.random() * apiKeys.length);
|
||||
const apiKey = apiKeys[randomIndex];
|
||||
if (apiKey) {
|
||||
@@ -114,33 +114,35 @@ function getApiKey(keys?: string) {
|
||||
return apiKey;
|
||||
}
|
||||
|
||||
export const getServerSideConfig = () => {
|
||||
if (typeof process === "undefined") {
|
||||
throw Error(
|
||||
"[Server Config] you are importing a nodejs-only module outside of nodejs",
|
||||
export function getServerSideConfig() {
|
||||
if (typeof process === 'undefined') {
|
||||
throw new TypeError(
|
||||
'[Server Config] you are importing a nodejs-only module outside of nodejs',
|
||||
);
|
||||
}
|
||||
|
||||
const disableGPT4 = !!process.env.DISABLE_GPT4;
|
||||
let customModels = process.env.CUSTOM_MODELS ?? "";
|
||||
let defaultModel = process.env.DEFAULT_MODEL ?? "";
|
||||
let customModels = process.env.CUSTOM_MODELS ?? '';
|
||||
let defaultModel = process.env.DEFAULT_MODEL ?? '';
|
||||
|
||||
if (disableGPT4) {
|
||||
if (customModels) customModels += ",";
|
||||
if (customModels)
|
||||
{ customModels += ','; }
|
||||
customModels += DEFAULT_MODELS.filter(
|
||||
(m) =>
|
||||
(m.name.startsWith("gpt-4") || m.name.startsWith("chatgpt-4o") || m.name.startsWith("o1")) &&
|
||||
!m.name.startsWith("gpt-4o-mini"),
|
||||
m =>
|
||||
(m.name.startsWith('gpt-4') || m.name.startsWith('chatgpt-4o') || m.name.startsWith('o1'))
|
||||
&& !m.name.startsWith('gpt-4o-mini'),
|
||||
)
|
||||
.map((m) => "-" + m.name)
|
||||
.join(",");
|
||||
.map(m => `-${m.name}`)
|
||||
.join(',');
|
||||
if (
|
||||
(defaultModel.startsWith("gpt-4") ||
|
||||
defaultModel.startsWith("chatgpt-4o") ||
|
||||
defaultModel.startsWith("o1")) &&
|
||||
!defaultModel.startsWith("gpt-4o-mini")
|
||||
)
|
||||
defaultModel = "";
|
||||
(defaultModel.startsWith('gpt-4')
|
||||
|| defaultModel.startsWith('chatgpt-4o')
|
||||
|| defaultModel.startsWith('o1'))
|
||||
&& !defaultModel.startsWith('gpt-4o-mini')
|
||||
) {
|
||||
defaultModel = '';
|
||||
}
|
||||
}
|
||||
|
||||
const isStability = !!process.env.STABILITY_API_KEY;
|
||||
@@ -166,8 +168,8 @@ export const getServerSideConfig = () => {
|
||||
// );
|
||||
|
||||
const allowedWebDavEndpoints = (
|
||||
process.env.WHITE_WEBDAV_ENDPOINTS ?? ""
|
||||
).split(",");
|
||||
process.env.WHITE_WEBDAV_ENDPOINTS ?? ''
|
||||
).split(',');
|
||||
|
||||
return {
|
||||
baseUrl: process.env.BASE_URL,
|
||||
@@ -250,4 +252,4 @@ export const getServerSideConfig = () => {
|
||||
defaultModel,
|
||||
allowedWebDavEndpoints,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user