mirror of https://github.com/langgenius/dify.git
tweaks
This commit is contained in:
parent
e12aee696d
commit
0bf95fda09
|
|
@ -32,48 +32,50 @@ async function main() {
|
|||
}
|
||||
}
|
||||
|
||||
class StorageMock {
|
||||
data: Record<string, string>
|
||||
if (!('localStorage' in globalThis) || !('sessionStorage' in globalThis)) {
|
||||
class StorageMock {
|
||||
data: Record<string, string>
|
||||
|
||||
constructor() {
|
||||
this.data = {} as Record<string, string>
|
||||
constructor() {
|
||||
this.data = {} as Record<string, string>
|
||||
}
|
||||
|
||||
setItem(name: string, value: string) {
|
||||
this.data[name] = value
|
||||
}
|
||||
|
||||
getItem(name: string) {
|
||||
return this.data[name] || null
|
||||
}
|
||||
|
||||
removeItem(name: string) {
|
||||
delete this.data[name]
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.data = {}
|
||||
}
|
||||
}
|
||||
|
||||
setItem(name: string, value: string) {
|
||||
this.data[name] = value
|
||||
let localStorage, sessionStorage
|
||||
|
||||
try {
|
||||
localStorage = globalThis.localStorage
|
||||
sessionStorage = globalThis.sessionStorage
|
||||
}
|
||||
catch {
|
||||
localStorage = new StorageMock()
|
||||
sessionStorage = new StorageMock()
|
||||
}
|
||||
|
||||
getItem(name: string) {
|
||||
return this.data[name] || null
|
||||
}
|
||||
Object.defineProperty(globalThis, 'localStorage', {
|
||||
value: localStorage,
|
||||
})
|
||||
|
||||
removeItem(name: string) {
|
||||
delete this.data[name]
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.data = {}
|
||||
}
|
||||
Object.defineProperty(globalThis, 'sessionStorage', {
|
||||
value: sessionStorage,
|
||||
})
|
||||
}
|
||||
|
||||
let localStorage, sessionStorage
|
||||
|
||||
try {
|
||||
localStorage = globalThis.localStorage
|
||||
sessionStorage = globalThis.sessionStorage
|
||||
}
|
||||
catch {
|
||||
localStorage = new StorageMock()
|
||||
sessionStorage = new StorageMock()
|
||||
}
|
||||
|
||||
Object.defineProperty(globalThis, 'localStorage', {
|
||||
value: localStorage,
|
||||
})
|
||||
|
||||
Object.defineProperty(globalThis, 'sessionStorage', {
|
||||
value: sessionStorage,
|
||||
})
|
||||
}
|
||||
|
||||
main()
|
||||
|
|
|
|||
Loading…
Reference in New Issue