mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-23 09:12:57 +08:00
🚧 WIP(custom): v3.0.0 migrate to vite and esm
This commit is contained in:
@@ -1,13 +1,30 @@
|
||||
import { IObject, IResult, IGetResult, IFilter } from '@picgo/store/dist/types'
|
||||
|
||||
import { triggerRPC } from '@/utils/common'
|
||||
|
||||
import { IRPCActionType } from '#/types/enum'
|
||||
import { IGalleryDB } from '#/types/extra-vue'
|
||||
|
||||
interface IFilter {
|
||||
orderBy?: 'asc' | 'desc'
|
||||
limit?: number
|
||||
offset?: number
|
||||
}
|
||||
|
||||
interface IGetResult<T> {
|
||||
total: number
|
||||
data: IResult<T>[]
|
||||
}
|
||||
interface IObject {
|
||||
id?: string
|
||||
[propName: string]: any
|
||||
}
|
||||
|
||||
type IResult<T> = T & {
|
||||
id: string
|
||||
createdAt: number
|
||||
updatedAt: number
|
||||
}
|
||||
|
||||
export class GalleryDB implements IGalleryDB {
|
||||
async #actionHandler<T>(method: IRPCActionType, ...args: any[]): Promise<T | undefined> {
|
||||
return await triggerRPC<T>(method, ...args)
|
||||
return await window.electron.triggerRPC<T>(method, ...args)
|
||||
}
|
||||
|
||||
async get<T>(filter?: IFilter): Promise<IGetResult<T> | undefined> {
|
||||
@@ -22,7 +39,7 @@ export class GalleryDB implements IGalleryDB {
|
||||
return await this.#actionHandler<IResult<T>[]>(IRPCActionType.GALLERY_INSERT_DB_BATCH, value)
|
||||
}
|
||||
|
||||
async updateById(id: string, value: IObject): Promise<boolean> {
|
||||
async updateById (id: string, value: IObject): Promise<boolean> {
|
||||
return (await this.#actionHandler<boolean>(IRPCActionType.GALLERY_UPDATE_BY_ID_DB, id, value)) || false
|
||||
}
|
||||
|
||||
@@ -30,7 +47,7 @@ export class GalleryDB implements IGalleryDB {
|
||||
return await this.#actionHandler<IResult<T> | undefined>(IRPCActionType.GALLERY_GET_BY_ID_DB, id)
|
||||
}
|
||||
|
||||
async removeById(id: string): Promise<void> {
|
||||
async removeById (id: string): Promise<void> {
|
||||
return await this.#actionHandler<void>(IRPCActionType.GALLERY_REMOVE_BY_ID_DB, id)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user