Skip to content

Commit dd20e9a

Browse files
committed
chore: 移除无用文件
1 parent 838679f commit dd20e9a

File tree

6 files changed

+57
-150
lines changed

6 files changed

+57
-150
lines changed

config/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

config/proxy.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/utils/crypto/index.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/utils/format/index.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/utils/storage/index.ts

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,57 @@
1-
export * from './local'
1+
interface StorageData<T = any> {
2+
data: T
3+
expire: number | null
4+
}
5+
6+
export function createLocalStorage(options?: { expire?: number | null }) {
7+
const DEFAULT_CACHE_TIME = 60 * 60 * 24 * 7
8+
9+
const { expire } = Object.assign({ expire: DEFAULT_CACHE_TIME }, options)
10+
11+
function set<T = any>(key: string, data: T) {
12+
const storageData: StorageData<T> = {
13+
data,
14+
expire: expire !== null ? new Date().getTime() + expire * 1000 : null,
15+
}
16+
17+
const json = JSON.stringify(storageData)
18+
window.localStorage.setItem(key, json)
19+
}
20+
21+
function get(key: string) {
22+
const json = window.localStorage.getItem(key)
23+
if (json) {
24+
let storageData: StorageData | null = null
25+
26+
try {
27+
storageData = JSON.parse(json)
28+
}
29+
catch {
30+
// Prevent failure
31+
}
32+
33+
if (storageData) {
34+
const { data, expire } = storageData
35+
if (expire === null || expire >= Date.now())
36+
return data
37+
}
38+
39+
remove(key)
40+
return null
41+
}
42+
}
43+
44+
function remove(key: string) {
45+
window.localStorage.removeItem(key)
46+
}
47+
48+
function clear() {
49+
window.localStorage.clear()
50+
}
51+
52+
return { set, get, remove, clear }
53+
}
54+
55+
export const ls = createLocalStorage()
56+
57+
export const ss = createLocalStorage({ expire: null })

src/utils/storage/local.ts

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)