Files
FastGPT/packages/service/support/outLink/schema.ts
T
Archer c37b3aa0e8 wechat publish (#6607)
* wechat publish

* update test

* doc
2026-03-23 11:57:05 +08:00

123 lines
2.4 KiB
TypeScript

import { connectionMongo, getMongoModel } from '../../common/mongo';
const { Schema } = connectionMongo;
import { type OutLinkSchema as SchemaType } from '@fastgpt/global/support/outLink/type';
import {
TeamCollectionName,
TeamMemberCollectionName
} from '@fastgpt/global/support/user/team/constant';
import { AppCollectionName } from '../../core/app/schema';
import { getLogger, LogCategories } from '../../common/logger';
const OutLinkSchema = new Schema({
shareId: {
type: String,
required: true
},
teamId: {
type: Schema.Types.ObjectId,
ref: TeamCollectionName,
required: true
},
tmbId: {
type: Schema.Types.ObjectId,
ref: TeamMemberCollectionName,
required: true
},
appId: {
type: Schema.Types.ObjectId,
ref: AppCollectionName,
required: true
},
type: {
type: String,
required: true
},
name: {
type: String,
required: true
},
usagePoints: {
type: Number,
default: 0
},
lastTime: {
type: Date
},
showRunningStatus: {
type: Boolean,
default: false
},
showCite: {
type: Boolean,
default: false
},
showFullText: {
type: Boolean,
default: false
},
canDownloadSource: {
type: Boolean,
default: false
},
showWholeResponse: {
type: Boolean,
default: true
},
limit: {
maxUsagePoints: {
type: Number,
default: -1
},
expiredTime: {
type: Date
},
QPM: {
type: Number,
default: 1000
},
hookUrl: {
type: String
}
},
// Third part app config
app: {
type: Object // could be FeishuAppType | WecomAppType | ...
},
immediateResponse: {
type: String
},
defaultResponse: {
type: String
},
//@deprecated
responseDetail: Boolean,
showNodeStatus: Boolean,
showRawSource: Boolean
});
OutLinkSchema.virtual('associatedApp', {
ref: AppCollectionName,
localField: 'appId',
foreignField: '_id',
justOne: true
});
const logger = getLogger(LogCategories.INFRA.MONGO);
try {
OutLinkSchema.index({ shareId: -1 });
OutLinkSchema.index({ teamId: 1, tmbId: 1, appId: 1 });
// Wechat polling recovery: find online channels on startup
OutLinkSchema.index(
{ type: 1, 'app.status': 1 },
{ partialFilterExpression: { type: 'wechat', 'app.status': 'online' } }
);
} catch (error) {
logger.error('Failed to build outlink indexes', { error });
}
export const MongoOutLink = getMongoModel<SchemaType>('outlinks', OutLinkSchema);