4.6.7 first pr (#726)

This commit is contained in:
Archer
2024-01-10 23:35:04 +08:00
committed by GitHub
parent 414b693303
commit 006ad17c6a
186 changed files with 2996 additions and 1838 deletions

View File

@@ -1 +0,0 @@
export const imageBaseUrl = '/api/system/img/';

View File

@@ -1,5 +1,5 @@
import { UploadImgProps } from '@fastgpt/global/common/file/api';
import { imageBaseUrl } from './constant';
import { imageBaseUrl } from '@fastgpt/global/common/file/image/constants';
import { MongoImage } from './schema';
export function getMongoImgUrl(id: string) {
@@ -8,10 +8,13 @@ export function getMongoImgUrl(id: string) {
export const maxImgSize = 1024 * 1024 * 12;
export async function uploadMongoImg({
type,
base64Img,
teamId,
expiredTime,
metadata
metadata,
shareId
}: UploadImgProps & {
teamId: string;
}) {
@@ -20,12 +23,16 @@ export async function uploadMongoImg({
}
const base64Data = base64Img.split(',')[1];
const binary = Buffer.from(base64Data, 'base64');
const { _id } = await MongoImage.create({
type,
teamId,
binary: Buffer.from(base64Data, 'base64'),
binary,
expiredTime: expiredTime,
metadata
metadata,
shareId
});
return getMongoImgUrl(String(_id));

View File

@@ -1,5 +1,7 @@
import { TeamCollectionName } from '@fastgpt/global/support/user/team/constant';
import { connectionMongo, 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({
@@ -12,12 +14,18 @@ const ImageSchema = new Schema({
type: Date,
default: () => new Date()
},
binary: {
type: Buffer
},
expiredTime: {
type: Date
},
binary: {
type: Buffer
},
type: {
type: String,
enum: Object.keys(mongoImageTypeMap),
required: true
},
metadata: {
type: Object
}
@@ -25,14 +33,13 @@ const ImageSchema = new Schema({
try {
ImageSchema.index({ expiredTime: 1 }, { expireAfterSeconds: 60 });
ImageSchema.index({ type: 1 });
ImageSchema.index({ teamId: 1 });
} catch (error) {
console.log(error);
}
export const MongoImage: Model<{
teamId: string;
binary: Buffer;
metadata?: { fileId?: string };
}> = models['image'] || model('image', ImageSchema);
export const MongoImage: Model<MongoImageSchemaType> =
models['image'] || model('image', ImageSchema);
MongoImage.syncIndexes();