feat: 🎸 update portal ui
This commit is contained in:
27
1000h-portal/utils/http.ts
Normal file
27
1000h-portal/utils/http.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
export async function request(url: string) {
|
||||
const perfix = "http-cache";
|
||||
const key = `${perfix}-${url}`;
|
||||
|
||||
try {
|
||||
const value = JSON.parse(localStorage.getItem(key) || "");
|
||||
|
||||
if (Number(value.expire_time) > new Date().getTime()) {
|
||||
return value.data;
|
||||
}
|
||||
} catch (error) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
const resp = await fetch(url, { method: "Get" });
|
||||
const data = await resp.json();
|
||||
|
||||
localStorage.setItem(
|
||||
key,
|
||||
JSON.stringify({
|
||||
expire_time: new Date().getTime() + 1000 * 60 * 60 * 24,
|
||||
data,
|
||||
})
|
||||
);
|
||||
|
||||
return data;
|
||||
}
|
||||
Reference in New Issue
Block a user