mirror of
https://github.com/logseq/logseq.git
synced 2026-05-01 09:26:28 +00:00
Enhance/api storages for graph assets (#6488)
* improve(api): assets storage for plugin Co-authored-by: charlie <xyhp915@qq.com>
This commit is contained in:
@@ -9,6 +9,8 @@ export interface IAsyncStorage {
|
||||
|
||||
hasItem(key: string): Promise<boolean>
|
||||
|
||||
allKeys(): Promise<Array<string>>
|
||||
|
||||
clear(): Promise<void>
|
||||
}
|
||||
|
||||
@@ -18,8 +20,14 @@ export interface IAsyncStorage {
|
||||
class LSPluginFileStorage implements IAsyncStorage {
|
||||
/**
|
||||
* @param ctx
|
||||
* @param opts
|
||||
*/
|
||||
constructor(private ctx: LSPluginUser) {}
|
||||
constructor(
|
||||
private ctx: LSPluginUser,
|
||||
private opts?: {
|
||||
assets: boolean
|
||||
}
|
||||
) {}
|
||||
|
||||
/**
|
||||
* plugin id
|
||||
@@ -32,20 +40,20 @@ class LSPluginFileStorage implements IAsyncStorage {
|
||||
* @param key A string as file name that support nested directory
|
||||
* @param value Storage value
|
||||
*/
|
||||
setItem(key: string, value: string): Promise<void> {
|
||||
setItem(key: string, value: string | any): Promise<void> {
|
||||
return this.ctx.caller.callAsync(`api:call`, {
|
||||
method: 'write-plugin-storage-file',
|
||||
args: [this.ctxId, key, value],
|
||||
args: [this.ctxId, key, value, this.opts?.assets],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key
|
||||
*/
|
||||
getItem(key: string): Promise<string | undefined> {
|
||||
getItem(key: string): Promise<string | any> {
|
||||
return this.ctx.caller.callAsync(`api:call`, {
|
||||
method: 'read-plugin-storage-file',
|
||||
args: [this.ctxId, key],
|
||||
args: [this.ctxId, key, this.opts?.assets],
|
||||
})
|
||||
}
|
||||
|
||||
@@ -55,7 +63,17 @@ class LSPluginFileStorage implements IAsyncStorage {
|
||||
removeItem(key: string): Promise<void> {
|
||||
return this.ctx.caller.call(`api:call`, {
|
||||
method: 'unlink-plugin-storage-file',
|
||||
args: [this.ctxId, key],
|
||||
args: [this.ctxId, key, this.opts?.assets],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all path file keys
|
||||
*/
|
||||
allKeys(): Promise<Array<string>> {
|
||||
return this.ctx.caller.callAsync(`api:call`, {
|
||||
method: 'list-plugin-storage-files',
|
||||
args: [this.ctxId, this.opts?.assets]
|
||||
})
|
||||
}
|
||||
|
||||
@@ -65,7 +83,7 @@ class LSPluginFileStorage implements IAsyncStorage {
|
||||
clear(): Promise<void> {
|
||||
return this.ctx.caller.call(`api:call`, {
|
||||
method: 'clear-plugin-storage-files',
|
||||
args: [this.ctxId],
|
||||
args: [this.ctxId, this.opts?.assets],
|
||||
})
|
||||
}
|
||||
|
||||
@@ -75,7 +93,7 @@ class LSPluginFileStorage implements IAsyncStorage {
|
||||
hasItem(key: string): Promise<boolean> {
|
||||
return this.ctx.caller.callAsync(`api:call`, {
|
||||
method: 'exist-plugin-storage-file',
|
||||
args: [this.ctxId, key],
|
||||
args: [this.ctxId, key, this.opts?.assets],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user