forked from AprilNEA/ChatGPT-Admin-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.
refactor: AprilNEA#6 check update over one hour and debound scroll
- Loading branch information
Showing
9 changed files
with
85 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export const REPO_URL = "https://github.com/Yidadaa/ChatGPT-Next-Web"; | ||
export const UPDATE_URL = | ||
"https://github.com/Yidadaa/ChatGPT-Next-Web#%E4%BF%9D%E6%8C%81%E6%9B%B4%E6%96%B0-keep-updated"; | ||
export const OWNER = "Yidadaa"; | ||
export const REPO = "ChatGPT-Next-Web"; | ||
export const REPO_URL = `https://github.com/${OWNER}/${REPO}`; | ||
export const UPDATE_URL = `${REPO_URL}#%E4%BF%9D%E6%8C%81%E6%9B%B4%E6%96%B0-keep-updated`; | ||
export const FETCH_COMMIT_URL = `https://api.github.com/repos/${OWNER}/${REPO}/commits?per_page=1`; |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./app"; | ||
export * from "./update"; |
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,49 @@ | ||
import { create } from "zustand"; | ||
import { persist } from "zustand/middleware"; | ||
import { FETCH_COMMIT_URL } from "../constant"; | ||
import { getCurrentCommitId } from "../utils"; | ||
|
||
export interface UpdateStore { | ||
lastUpdate: number; | ||
remoteId: string; | ||
|
||
getLatestCommitId: (force: boolean) => Promise<string>; | ||
} | ||
|
||
export const UPDATE_KEY = "chat-update"; | ||
|
||
export const useUpdateStore = create<UpdateStore>()( | ||
persist( | ||
(set, get) => ({ | ||
lastUpdate: 0, | ||
remoteId: "", | ||
|
||
async getLatestCommitId(force = false) { | ||
const overOneHour = Date.now() - get().lastUpdate > 3600 * 1000; | ||
const shouldFetch = force || overOneHour; | ||
if (!shouldFetch) { | ||
return getCurrentCommitId(); | ||
} | ||
|
||
try { | ||
const data = await (await fetch(FETCH_COMMIT_URL)).json(); | ||
const sha = data[0].sha as string; | ||
const remoteId = sha.substring(0, 7); | ||
set(() => ({ | ||
lastUpdate: Date.now(), | ||
remoteId, | ||
})); | ||
console.log("[Got Upstream] ", remoteId); | ||
return remoteId; | ||
} catch (error) { | ||
console.error("[Fetch Upstream Commit Id]", error); | ||
return getCurrentCommitId(); | ||
} | ||
}, | ||
}), | ||
{ | ||
name: UPDATE_KEY, | ||
version: 1, | ||
} | ||
) | ||
); |
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