feat(website): 首页 Hero 徽标显示 v0.6.8 + 更新日志缓存按版本失效
This commit is contained in:
1 parent
6bc9e4644e
commit
a285d192eb
2 files changed
+14
-9
No files matched your search
@@ -19,7 +19,7 @@ const zh = {
|
|||||||
downloadBtn: "下载 v0.6.8",
|
downloadBtn: "下载 v0.6.8",
|
||||||
},
|
},
|
||||||
hero: {
|
hero: {
|
||||||
badge: "开源 MIT · Windows 10 / 11",
|
badge: "v0.6.8 · 开源 MIT · Windows / macOS / Linux",
|
||||||
titleBefore: "统一管理你的",
|
titleBefore: "统一管理你的",
|
||||||
titleAccent: "AI 供应商",
|
titleAccent: "AI 供应商",
|
||||||
titleAfter: "",
|
titleAfter: "",
|
||||||
@@ -315,7 +315,7 @@ const en: Dict = {
|
|||||||
downloadBtn: "Download v0.6.8",
|
downloadBtn: "Download v0.6.8",
|
||||||
},
|
},
|
||||||
hero: {
|
hero: {
|
||||||
badge: "Open source MIT · Windows 10 / 11",
|
badge: "v0.6.8 · Open source MIT · Windows / macOS / Linux",
|
||||||
titleBefore: "One app for all your ",
|
titleBefore: "One app for all your ",
|
||||||
titleAccent: "AI providers",
|
titleAccent: "AI providers",
|
||||||
titleAfter: "",
|
titleAfter: "",
|
||||||
|
|||||||
@@ -10,9 +10,14 @@ interface ChangelogEntry {
|
|||||||
|
|
||||||
const API_URL =
|
const API_URL =
|
||||||
"https://api.github.com/repos/billowliu2/KimiSwitch/releases?per_page=20";
|
"https://api.github.com/repos/billowliu2/KimiSwitch/releases?per_page=20";
|
||||||
const CACHE_KEY = "kimi-switch-changelog";
|
|
||||||
const CACHE_TTL = 60 * 60 * 1000; // 1 hour
|
const CACHE_TTL = 60 * 60 * 1000; // 1 hour
|
||||||
|
|
||||||
|
/** Cache key is versioned by the newest embedded release so redeploys
|
||||||
|
* invalidate stale caches in the browser immediately. */
|
||||||
|
function cacheKey(embedded: ChangelogEntry[]) {
|
||||||
|
return `kimi-switch-changelog-${embedded[0]?.version ?? "v1"}`;
|
||||||
|
}
|
||||||
|
|
||||||
/** Parse a GitHub release body into bullet items. */
|
/** Parse a GitHub release body into bullet items. */
|
||||||
function parseBody(body: string): string[] {
|
function parseBody(body: string): string[] {
|
||||||
return body
|
return body
|
||||||
@@ -36,9 +41,9 @@ async function fetchReleases(): Promise<ChangelogEntry[]> {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
function readCache(): ChangelogEntry[] | null {
|
function readCache(embedded: ChangelogEntry[]): ChangelogEntry[] | null {
|
||||||
try {
|
try {
|
||||||
const raw = localStorage.getItem(CACHE_KEY);
|
const raw = localStorage.getItem(cacheKey(embedded));
|
||||||
if (!raw) return null;
|
if (!raw) return null;
|
||||||
const { ts, data } = JSON.parse(raw) as { ts: number; data: ChangelogEntry[] };
|
const { ts, data } = JSON.parse(raw) as { ts: number; data: ChangelogEntry[] };
|
||||||
if (Date.now() - ts > CACHE_TTL) return null;
|
if (Date.now() - ts > CACHE_TTL) return null;
|
||||||
@@ -48,10 +53,10 @@ function readCache(): ChangelogEntry[] | null {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeCache(data: ChangelogEntry[]) {
|
function writeCache(data: ChangelogEntry[], embedded: ChangelogEntry[]) {
|
||||||
try {
|
try {
|
||||||
localStorage.setItem(
|
localStorage.setItem(
|
||||||
CACHE_KEY,
|
cacheKey(embedded),
|
||||||
JSON.stringify({ ts: Date.now(), data }),
|
JSON.stringify({ ts: Date.now(), data }),
|
||||||
);
|
);
|
||||||
} catch {
|
} catch {
|
||||||
@@ -67,7 +72,7 @@ export default function Changelog() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
const cached = readCache();
|
const cached = readCache(embedded);
|
||||||
if (cached) {
|
if (cached) {
|
||||||
setRemote(cached);
|
setRemote(cached);
|
||||||
setSynced(true);
|
setSynced(true);
|
||||||
@@ -78,7 +83,7 @@ export default function Changelog() {
|
|||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
setRemote(data);
|
setRemote(data);
|
||||||
setSynced(true);
|
setSynced(true);
|
||||||
writeCache(data);
|
writeCache(data, embedded);
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
/* 网络不通时使用内置列表兜底 */
|
/* 网络不通时使用内置列表兜底 */
|
||||||
|
|||||||
Reference in new issue
Block a user