mirror of
https://github.com/labring/FastGPT.git
synced 2025-08-02 12:48:30 +00:00
31 lines
789 B
TypeScript
31 lines
789 B
TypeScript
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
import { jsonRes } from '@/service/response';
|
|
import { connectToDatabase } from '@/service/mongo';
|
|
import { authUser } from '@fastgpt/service/support/user/auth';
|
|
import { GridFSStorage } from '@/service/lib/gridfs';
|
|
|
|
export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
|
|
try {
|
|
await connectToDatabase();
|
|
|
|
const { fileId } = req.query as { fileId: string };
|
|
|
|
if (!fileId) {
|
|
throw new Error('fileId is empty');
|
|
}
|
|
|
|
const { userId } = await authUser({ req, authToken: true });
|
|
|
|
const gridFs = new GridFSStorage('dataset', userId);
|
|
|
|
await gridFs.delete(fileId);
|
|
|
|
jsonRes(res);
|
|
} catch (error) {
|
|
jsonRes(res, {
|
|
code: 500,
|
|
error
|
|
});
|
|
}
|
|
}
|