Files
FastGPT/packages/service/common/file/image/controller.ts
Archer c5664c7e90 feat: vision model (#489)
* mongo init

* perf: mongo connect

* perf: tts

perf: whisper and tts

peref: tts whisper permission

log

reabase (#488)

* perf: modal

* i18n

* perf: schema lean

* feat: vision model format

* perf: tts loading

* perf: static data

* perf: tts

* feat: image

* perf: image

* perf: upload image and title

* perf: image size

* doc

* perf: color

* doc

* speaking can not select file

* doc
2023-11-18 15:42:35 +08:00

40 lines
856 B
TypeScript

import { imageBaseUrl } from './constant';
import { MongoImage } from './schema';
export function getMongoImgUrl(id: string) {
return `${imageBaseUrl}${id}`;
}
export const maxImgSize = 1024 * 1024 * 12;
export async function uploadMongoImg({
base64Img,
teamId,
expiredTime
}: {
base64Img: string;
teamId: string;
expiredTime?: Date;
}) {
if (base64Img.length > maxImgSize) {
return Promise.reject('Image too large');
}
const base64Data = base64Img.split(',')[1];
const { _id } = await MongoImage.create({
teamId,
binary: Buffer.from(base64Data, 'base64'),
expiredTime
});
return getMongoImgUrl(String(_id));
}
export async function readMongoImg({ id }: { id: string }) {
const data = await MongoImage.findById(id);
if (!data) {
return Promise.reject('Image not found');
}
return data?.binary;
}