Skip to content

Commit

Permalink
feat: finish picgo store ataptor
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyue committed Mar 16, 2024
1 parent 952cff9 commit c44c32a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 32 deletions.
4 changes: 2 additions & 2 deletions libs/Universal-PicGo-Store/src/lib/JSONStore.ts
Expand Up @@ -3,7 +3,7 @@ import { JSONAdapter } from "./adapters/JSONAdapter"
import _ from "lodash"
import { IJSON } from "../types"
import { hasNodeEnv } from "./utils"
import { LocalForgeAdapter } from "./adapters/LocalForgeAdapter"
import { LocalStorageAdapter } from "./adapters/LocalStorageAdapter"

class LowWithLodash<T> extends LowSync<T> {
chain: _.ExpChain<this["data"]> = _.chain(this).get("data")
Expand All @@ -21,7 +21,7 @@ class JSONStore {
if (hasNodeEnv) {
adapter = new JSONAdapter(dbPath)
} else {
adapter = new LocalForgeAdapter(dbPath)
adapter = new LocalStorageAdapter(dbPath)
}
this.db = new LowWithLodash(adapter)
this.read()
Expand Down
30 changes: 0 additions & 30 deletions libs/Universal-PicGo-Store/src/lib/adapters/LocalForgeAdapter.ts

This file was deleted.

25 changes: 25 additions & 0 deletions libs/Universal-PicGo-Store/src/lib/adapters/LocalStorageAdapter.ts
@@ -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)
}
}

0 comments on commit c44c32a

Please sign in to comment.