mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 21:13:50 +00:00
v4.5.2 (#439)
This commit is contained in:
25
packages/service/common/file/image/controller.ts
Normal file
25
packages/service/common/file/image/controller.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { imageBaseUrl } from './constant';
|
||||
import { MongoImage } from './schema';
|
||||
|
||||
export function getMongoImgUrl(id: string) {
|
||||
return `${imageBaseUrl}${id}`;
|
||||
}
|
||||
|
||||
export async function uploadMongoImg({ base64Img, userId }: { base64Img: string; userId: string }) {
|
||||
const base64Data = base64Img.split(',')[1];
|
||||
|
||||
const { _id } = await MongoImage.create({
|
||||
userId,
|
||||
binary: Buffer.from(base64Data, 'base64')
|
||||
});
|
||||
|
||||
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;
|
||||
}
|
Reference in New Issue
Block a user