mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-07-13 00:21:25 +08:00
✨ Feature: add remote file delete , picBed management
First version of PicList. In album, you can delete remote file now. Add picBed management function.
This commit is contained in:
66
src/main/manage/datastore/db.ts
Normal file
66
src/main/manage/datastore/db.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
/* eslint-disable */
|
||||
import { JSONStore } from '@picgo/store'
|
||||
import { IJSON } from '@picgo/store/dist/types'
|
||||
import { ManageApiType, ManageConfigType } from '~/universal/types/manage'
|
||||
|
||||
class ManageDB {
|
||||
private readonly ctx: ManageApiType
|
||||
private readonly db: JSONStore
|
||||
constructor (ctx: ManageApiType) {
|
||||
this.ctx = ctx
|
||||
this.db = new JSONStore(this.ctx.configPath)
|
||||
let initParams: IStringKeyMap = {
|
||||
picBed: {},
|
||||
settings: {},
|
||||
currentPicBed: 'placeholder'
|
||||
}
|
||||
for (let key in initParams) {
|
||||
if (!this.db.has(key)) {
|
||||
try {
|
||||
this.db.set(key, initParams[key])
|
||||
} catch (e: any) {
|
||||
this.ctx.logger.error(e)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
read (flush?: boolean): IJSON {
|
||||
return this.db.read(flush)
|
||||
}
|
||||
|
||||
get (key: string = ''): any {
|
||||
this.read(true)
|
||||
return this.db.get(key)
|
||||
}
|
||||
|
||||
set (key: string, value: any): void {
|
||||
this.read(true)
|
||||
return this.db.set(key, value)
|
||||
}
|
||||
|
||||
has (key: string): boolean {
|
||||
this.read(true)
|
||||
return this.db.has(key)
|
||||
}
|
||||
|
||||
unset (key: string, value: any): boolean {
|
||||
this.read(true)
|
||||
return this.db.unset(key, value)
|
||||
}
|
||||
|
||||
saveConfig (config: Partial<ManageConfigType>): void {
|
||||
Object.keys(config).forEach((name: string) => {
|
||||
this.set(name, config[name])
|
||||
})
|
||||
}
|
||||
|
||||
removeConfig (config: ManageConfigType): void {
|
||||
Object.keys(config).forEach((name: string) => {
|
||||
this.unset(name, config[name])
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default ManageDB
|
||||
Reference in New Issue
Block a user