mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 21:37:11 +00:00
feat: chaite 初始化逻辑
This commit is contained in:
parent
88312cdf38
commit
fbcf4e6c08
16 changed files with 549 additions and 1269 deletions
66
models/chaite/user_state_storage.js
Normal file
66
models/chaite/user_state_storage.js
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import ChatGPTStorage from '../storage.js'
|
||||
import { ChaiteStorage } from 'chaite'
|
||||
|
||||
/**
|
||||
* @extends {ChaiteStorage<import('chaite').UserState>}
|
||||
*/
|
||||
export class LowDBUserStateStorage extends ChaiteStorage {
|
||||
/**
|
||||
*
|
||||
* @param {LowDBStorage} storage
|
||||
*/
|
||||
constructor (storage = ChatGPTStorage) {
|
||||
super()
|
||||
this.storage = storage
|
||||
/**
|
||||
* 集合
|
||||
* @type {LowDBCollection}
|
||||
*/
|
||||
this.collection = this.storage.collection('user_states')
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} key
|
||||
* @returns {Promise<import('chaite').UserState>}
|
||||
*/
|
||||
async getItem (key) {
|
||||
return this.collection.findOne({ id: key })
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} id
|
||||
* @param {import('chaite').UserState} state
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
async setItem (id, state) {
|
||||
if (id) {
|
||||
await this.collection.updateById(id, state)
|
||||
return id
|
||||
}
|
||||
const result = await this.collection.insert(state)
|
||||
return result.id
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} key
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async removeItem (key) {
|
||||
await this.collection.deleteById(key)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns {Promise<import('chaite').UserState[]>}
|
||||
*/
|
||||
async listItems () {
|
||||
return this.collection.findAll()
|
||||
}
|
||||
|
||||
async clear () {
|
||||
await this.collection.deleteAll()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue