mirror of
https://github.com/labring/FastGPT.git
synced 2025-08-03 13:38:00 +00:00
v4.4.7-2 (#388)
This commit is contained in:
22
projects/app/src/service/dataset/auth.ts
Normal file
22
projects/app/src/service/dataset/auth.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { isSpecialFileId } from '@fastgpt/core/dataset/utils';
|
||||
import { GridFSStorage } from '../lib/gridfs';
|
||||
import { Types } from 'mongoose';
|
||||
|
||||
export async function authFileIdValid(fileId?: string) {
|
||||
if (!fileId) return true;
|
||||
if (isSpecialFileId(fileId)) return true;
|
||||
try {
|
||||
// find file
|
||||
const gridFs = new GridFSStorage('dataset', '');
|
||||
const collection = gridFs.Collection();
|
||||
const file = await collection.findOne(
|
||||
{ _id: new Types.ObjectId(fileId) },
|
||||
{ projection: { _id: 1 } }
|
||||
);
|
||||
if (!file) {
|
||||
return Promise.reject('Invalid fileId');
|
||||
}
|
||||
} catch (error) {
|
||||
return Promise.reject('Invalid fileId');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user