Files
FastGPT/packages/service/common/system/config/schema.ts
Archer 84cf6b5658 v4.6.4 (#585)
* perf: md format

* add systemConfig schema (#2)

* fix: markdown

* fix: root

* fix: root

---------

Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com>
2023-12-08 16:33:15 +08:00

33 lines
894 B
TypeScript

import { SystemConfigsType } from '@fastgpt/global/common/system/config/type';
import { connectionMongo, type Model } from '../../../common/mongo';
import { SystemConfigsTypeMap } from '@fastgpt/global/common/system/config/constants';
const { Schema, model, models } = connectionMongo;
const collectionName = 'systemConfigs';
const systemConfigSchema = new Schema({
type: {
type: String,
required: true,
enum: Object.keys(SystemConfigsTypeMap)
},
value: {
type: Object,
required: true
},
createTime: {
type: Date,
default: () => new Date()
}
})
try {
systemConfigSchema.index({ createTime: -1 }, { expireAfterSeconds: 90 * 24 * 60 * 60 });
} catch (error) {
console.log(error);
}
export const MongoSystemConfigs: Model<SystemConfigsType>=
models[collectionName] || model(collectionName, systemConfigSchema);
MongoSystemConfigs.syncIndexes();