Files
FastGPT/packages/service/common/file/image/schema.ts
Archer f6c5695df4 Optimize base64 storage in files to support concurrent storage (#2856)
* fix: variables check

* remove log

* perf: file img saved

* update doc
2024-10-08 12:58:33 +08:00

45 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { TeamCollectionName } from '@fastgpt/global/support/user/team/constant';
import { connectionMongo, getMongoModel, type Model } from '../../mongo';
import { MongoImageSchemaType } from '@fastgpt/global/common/file/image/type.d';
import { mongoImageTypeMap } from '@fastgpt/global/common/file/image/constants';
const { Schema, model, models } = connectionMongo;
const ImageSchema = new Schema({
teamId: {
type: Schema.Types.ObjectId,
ref: TeamCollectionName,
required: true
},
createTime: {
type: Date,
default: () => new Date()
},
expiredTime: {
type: Date
},
binary: {
type: Buffer
},
type: {
type: String,
enum: Object.keys(mongoImageTypeMap),
required: true
},
metadata: {
type: Object
}
});
try {
// tts expired60 Minutes
ImageSchema.index({ expiredTime: 1 }, { expireAfterSeconds: 60 * 60 });
ImageSchema.index({ type: 1 });
ImageSchema.index({ createTime: 1 });
// delete related img
ImageSchema.index({ teamId: 1, 'metadata.relatedId': 1 });
} catch (error) {
console.log(error);
}
export const MongoImage = getMongoModel<MongoImageSchemaType>('image', ImageSchema);