Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhangyue
committed
Mar 16, 2024
1 parent
952cff9
commit c44c32a
Showing
3 changed files
with
27 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
libs/Universal-PicGo-Store/src/lib/adapters/LocalForgeAdapter.ts
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
libs/Universal-PicGo-Store/src/lib/adapters/LocalStorageAdapter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { IJSON } from "../../types" | ||
import { LocalKey, LocalStorage } from "ts-localstorage" | ||
|
||
export class LocalStorageAdapter { | ||
private readonly adapter: typeof LocalStorage | ||
private readonly key: LocalKey<any> | ||
|
||
constructor(dbPath: string) { | ||
this.adapter = LocalStorage | ||
this.key = new LocalKey(dbPath, {}) | ||
} | ||
|
||
read(): IJSON { | ||
const data = this.adapter.getItem(this.key) | ||
/* istanbul ignore if */ | ||
if (data === null) { | ||
return {} | ||
} | ||
return data | ||
} | ||
|
||
write(obj: any): void { | ||
this.adapter.setItem(this.key, obj) | ||
} | ||
} |