Skip to content

Commit

Permalink
Fix export dataset (#1436)
Browse files Browse the repository at this point in the history
* fix: export dataset

* remove file buffer
  • Loading branch information
c121914yu authored May 10, 2024
1 parent 435b2fb commit d70efe1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@fastgpt/service/common/response';
import { connectToDatabase } from '@/service/mongo';
import {
delFileByFileIdList,
readFileContentFromMongo
} from '@fastgpt/service/common/file/gridfs/controller';
import { readFileContentFromMongo } from '@fastgpt/service/common/file/gridfs/controller';
import { authDataset } from '@fastgpt/service/support/permission/auth/dataset';
import { FileIdCreateDatasetCollectionParams } from '@fastgpt/global/core/dataset/api';
import { createOneCollection } from '@fastgpt/service/core/dataset/collection/controller';
Expand All @@ -24,6 +21,7 @@ import { UsageSourceEnum } from '@fastgpt/global/support/wallet/usage/constants'
import { getLLMModel, getVectorModel } from '@fastgpt/service/core/ai/model';
import { hashStr } from '@fastgpt/global/common/string/tools';
import { startTrainingQueue } from '@/service/core/dataset/training/utils';
import { MongoRawTextBuffer } from '@fastgpt/service/common/buffer/rawText/schema';

export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
const {
Expand Down Expand Up @@ -139,6 +137,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
return collectionId;
});

// remove buffer
await MongoRawTextBuffer.deleteOne({ sourceId: fileId });

startTrainingQueue(true);

jsonRes(res);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@fastgpt/service/common/response';
import { connectToDatabase } from '@/service/mongo';
import { authDataset } from '@fastgpt/service/support/permission/auth/dataset';
import { checkExportDatasetLimit } from '@fastgpt/service/support/user/utils';
import { NextAPI } from '@/service/middle/entry';

export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
try {
await connectToDatabase();
const { datasetId } = req.query as {
datasetId: string;
};
async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
const { datasetId } = req.query as {
datasetId: string;
};

if (!datasetId) {
throw new Error('datasetId is required');
}

// 凭证校验
const { teamId } = await authDataset({ req, authToken: true, datasetId, per: 'w' });
if (!datasetId) {
throw new Error('datasetId is required');
}

await checkExportDatasetLimit({
teamId,
limitMinutes: global.feConfigs?.limit?.exportDatasetLimitMinutes
});
// 凭证校验
const { teamId } = await authDataset({ req, authToken: true, datasetId, per: 'w' });

jsonRes(res);
} catch (err) {
res.status(500);
jsonRes(res, {
code: 500,
error: err
});
}
await checkExportDatasetLimit({
teamId,
limitMinutes: global.feConfigs?.limit?.exportDatasetLimitMinutes
});
}

export default NextAPI(handler);
3 changes: 2 additions & 1 deletion projects/app/src/service/middle/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export const NextAPI = (...args: NextApiHandler[]): NextApiHandler => {
response = await handler(req, res);
}

if (!res.writableFinished) {
const contentType = res.getHeader('Content-Type');
if ((!contentType || contentType === 'application/json') && !res.writableFinished) {
return jsonRes(res, {
code: 200,
data: response
Expand Down

0 comments on commit d70efe1

Please sign in to comment.