yolk/modules/tauri/runtime/storage.ts

41 lines
859 B
TypeScript

import { Store } from 'tauri-plugin-store-api'
import { createStorage } from 'unstorage'
import redisDriver from 'unstorage/drivers/redis'
const store = new Store('.servers.dat')
/**
* TODO: Use redis as storage
* - docs: https://unstorage.unjs.io/drivers/redis
* - then we can probably remove need for `/elk/data` (see docker-compose)
*/
const storage = createStorage({
driver: redisDriver({
base: 'unstorage:elk:',
}),
})
storage.mount('servers', {
getKeys() {
return store.keys()
},
async removeItem(key: string) {
await store.delete(key)
},
clear() {
return store.clear()
},
hasItem(key: string) {
return store.has(key)
},
setItem(key: string, value: any) {
return store.set(key, value)
},
getItem(key: string) {
return store.get(key)
},
})
export function useStorage() {
return storage
}