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

Commit2b17530

Browse files
authored
prioritize session file path over local storage (coderoad#553)
* prioritize session file path over local storageSigned-off-by: shmck <shawn.j.mckay@gmail.com>* move local storage lookup laterSigned-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent8522ec6 commit2b17530

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

‎src/services/storage/index.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,9 @@ class Storage<T> {
3030
this.defaultValue=defaultValue
3131
}
3232
publicget=async():Promise<T>=>{
33-
constvalue:string|undefined=awaitthis.storage.get(this.key)
34-
if(value){
35-
returnJSON.parse(value)
36-
}elseif(SESSION_STORAGE_PATH){
33+
if(SESSION_STORAGE_PATH){
3734
try{
38-
//optionally read from fileas a fallback tolocal storage
35+
//1. read from fileinstead oflocal storage if specified
3936
constsessionFile=awaitreadFile(SESSION_STORAGE_PATH,`${this.filePath}.json`)
4037
if(!sessionFile){
4138
thrownewError('No session file found')
@@ -53,6 +50,16 @@ class Storage<T> {
5350
console.warn(`Failed to read or parse session file:${SESSION_STORAGE_PATH}/${this.filePath}.json`)
5451
}
5552
}
53+
constvalue:string|undefined=awaitthis.storage.get(this.key)
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