Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit445abf5

Browse files
committed
prioritize session file path over local storage
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent8522ec6 commit445abf5

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

‎src/services/storage/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ class Storage<T> {
3131
}
3232
publicget=async():Promise<T>=>{
3333
constvalue:string|undefined=awaitthis.storage.get(this.key)
34-
if(value){
35-
returnJSON.parse(value)
36-
}elseif(SESSION_STORAGE_PATH){
34+
if(SESSION_STORAGE_PATH){
3735
try{
38-
//optionally read from fileas a fallback tolocal storage
36+
//1. read from fileinstead oflocal storage if specified
3937
constsessionFile=awaitreadFile(SESSION_STORAGE_PATH,`${this.filePath}.json`)
4038
if(!sessionFile){
4139
thrownewError('No session file found')
@@ -53,6 +51,15 @@ class Storage<T> {
5351
console.warn(`Failed to read or parse session file:${SESSION_STORAGE_PATH}/${this.filePath}.json`)
5452
}
5553
}
54+
if(value){
55+
// 2. read from local storage
56+
try{
57+
returnJSON.parse(value)
58+
}catch(err){
59+
console.warn(`Failed to parse session state from local storage:${value}`)
60+
}
61+
}
62+
// 3. fallback to the default
5663
returnthis.defaultValue
5764
}
5865
publicset=(value:T):void=>{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp