mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 21:37:11 +00:00
feat: init v3
This commit is contained in:
parent
d6cb085c40
commit
531986b2dc
284 changed files with 618 additions and 405179 deletions
74
models/chaite/channel_storage.js
Normal file
74
models/chaite/channel_storage.js
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
import ChatGPTStorage from '../storage.js'
|
||||
|
||||
/**
|
||||
* @returns {import('chaite').ChannelsStorage}
|
||||
*/
|
||||
export async function createChannelsStorage () {
|
||||
return new LowDBChannelStorage(ChatGPTStorage)
|
||||
}
|
||||
|
||||
class LowDBChannelStorage {
|
||||
/**
|
||||
*
|
||||
* @param { LowDBStorage } storage
|
||||
*/
|
||||
constructor (storage) {
|
||||
this.storage = storage
|
||||
/**
|
||||
* 集合
|
||||
* @type {LowDBCollection}
|
||||
*/
|
||||
this.collection = this.storage.collection('channel')
|
||||
}
|
||||
|
||||
async saveChannel (channel) {
|
||||
await this.collection.insert(channel)
|
||||
}
|
||||
|
||||
async getChannel (id) {
|
||||
return this.collection.collection()
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @returns {Promise<import('chaite').Channel[]>}
|
||||
*/
|
||||
async getChannelByName (name) {
|
||||
return this.collection.find({ name })
|
||||
}
|
||||
|
||||
async deleteChannel (name) {
|
||||
await this.collection.delete({ name })
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有渠道
|
||||
* @param {string?} model
|
||||
* @returns {Promise<import('chaite').Channel[]>}
|
||||
*/
|
||||
async getAllChannels (model) {
|
||||
if (model) {
|
||||
return this.collection.find({ 'options.model': model })
|
||||
}
|
||||
return this.collection.findAll()
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import('chaite').ClientType} type
|
||||
* @returns {Promise<Object[]>}
|
||||
*/
|
||||
async getChannelByType (type) {
|
||||
return this.collection.find({ type })
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {'enabled' | 'disabled'} status
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
async getChannelByStatus (status) {
|
||||
return this.collection.find({ status })
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue