mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-18 01:16:01 +00:00
4.6.7 fix (#752)
This commit is contained in:
@@ -46,8 +46,17 @@ export async function readMongoImg({ id }: { id: string }) {
|
||||
return data?.binary;
|
||||
}
|
||||
|
||||
export async function delImgByRelatedId(relateIds: string[]) {
|
||||
export async function delImgByRelatedId({
|
||||
teamId,
|
||||
relateIds
|
||||
}: {
|
||||
teamId: string;
|
||||
relateIds: string[];
|
||||
}) {
|
||||
if (relateIds.length === 0) return;
|
||||
|
||||
return MongoImage.deleteMany({
|
||||
teamId,
|
||||
'metadata.relatedId': { $in: relateIds.map((id) => String(id)) }
|
||||
});
|
||||
}
|
||||
|
@@ -34,9 +34,8 @@ const ImageSchema = new Schema({
|
||||
try {
|
||||
ImageSchema.index({ expiredTime: 1 }, { expireAfterSeconds: 60 });
|
||||
ImageSchema.index({ type: 1 });
|
||||
ImageSchema.index({ teamId: 1 });
|
||||
ImageSchema.index({ createTime: 1 });
|
||||
ImageSchema.index({ 'metadata.relatedId': 1 });
|
||||
ImageSchema.index({ teamId: 1, 'metadata.relatedId': 1 });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
@@ -28,12 +28,16 @@ export const getUploadModel = ({ maxSize = 500 }: { maxSize?: number }) => {
|
||||
// },
|
||||
filename: async (req, file, cb) => {
|
||||
const { ext } = path.parse(decodeURIComponent(file.originalname));
|
||||
cb(null, `${getNanoid(32)}${ext}`);
|
||||
cb(null, `${getNanoid()}${ext}`);
|
||||
}
|
||||
})
|
||||
}).single('file');
|
||||
|
||||
async doUpload<T = Record<string, any>>(req: NextApiRequest, res: NextApiResponse) {
|
||||
async doUpload<T = Record<string, any>>(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse,
|
||||
originBuckerName?: `${BucketNameEnum}`
|
||||
) {
|
||||
return new Promise<{
|
||||
file: FileType;
|
||||
metadata: Record<string, any>;
|
||||
@@ -47,7 +51,7 @@ export const getUploadModel = ({ maxSize = 500 }: { maxSize?: number }) => {
|
||||
}
|
||||
|
||||
// check bucket name
|
||||
const bucketName = req.body?.bucketName as `${BucketNameEnum}`;
|
||||
const bucketName = (req.body?.bucketName || originBuckerName) as `${BucketNameEnum}`;
|
||||
if (bucketName && !bucketNameMap[bucketName]) {
|
||||
return reject('BucketName is invalid');
|
||||
}
|
||||
|
Reference in New Issue
Block a user