forked from ChatGPTNextWeb/ChatGPT-Next-Web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ChatGPTNextWeb#1927 from Yidadaa/bugfix-0613
feat: ChatGPTNextWeb#1000 ready to support client-side only
- Loading branch information
Showing
14 changed files
with
134 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,27 @@ | ||
const COMMIT_ID: string = (() => { | ||
try { | ||
const childProcess = require("child_process"); | ||
return childProcess | ||
.execSync('git log -1 --format="%at000" --date=unix') | ||
.toString() | ||
.trim(); | ||
} catch (e) { | ||
console.error("[Build Config] No git or not from git repo."); | ||
return "unknown"; | ||
} | ||
})(); | ||
|
||
export const getBuildConfig = () => { | ||
if (typeof process === "undefined") { | ||
throw Error( | ||
"[Server Config] you are importing a nodejs-only module outside of nodejs", | ||
); | ||
} | ||
|
||
const COMMIT_ID: string = (() => { | ||
try { | ||
const childProcess = require("child_process"); | ||
return childProcess | ||
.execSync('git log -1 --format="%at000" --date=unix') | ||
.toString() | ||
.trim(); | ||
} catch (e) { | ||
console.error("[Build Config] No git or not from git repo."); | ||
return "unknown"; | ||
} | ||
})(); | ||
|
||
return { | ||
commitId: COMMIT_ID, | ||
buildMode: process.env.BUILD_MODE ?? "standalone", | ||
}; | ||
}; | ||
|
||
export type BuildConfig = ReturnType<typeof getBuildConfig>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { BuildConfig, getBuildConfig } from "./build"; | ||
|
||
export function getClientConfig() { | ||
if (typeof document !== "undefined") { | ||
// client side | ||
return JSON.parse(queryMeta("config")) as BuildConfig; | ||
} | ||
|
||
if (typeof process !== "undefined") { | ||
// server side | ||
return getBuildConfig(); | ||
} | ||
} | ||
|
||
function queryMeta(key: string, defaultValue?: string): string { | ||
let ret: string; | ||
if (document) { | ||
const meta = document.head.querySelector( | ||
`meta[name='${key}']`, | ||
) as HTMLMetaElement; | ||
ret = meta?.content ?? ""; | ||
} else { | ||
ret = defaultValue ?? ""; | ||
} | ||
|
||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters