mirror of
https://github.com/labring/FastGPT.git
synced 2026-01-14 06:03:34 +08:00
fix: csv check (#6044)
* fix: csv check * fix: template * Update packages/global/common/file/utils.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
6
packages/global/common/file/utils.ts
Normal file
6
packages/global/common/file/utils.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import path from 'path';
|
||||
|
||||
export const isCSVFile = (filename: string) => {
|
||||
const extension = path.extname(filename).toLowerCase();
|
||||
return extension === '.csv';
|
||||
};
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
} from '@fastgpt/global/core/dataset/constants';
|
||||
import { i18nT } from '@fastgpt/web/i18n/utils';
|
||||
import { uploadFile } from '@fastgpt/service/common/file/gridfs/controller';
|
||||
import { getFileS3Key } from '@fastgpt/service/common/s3/utils';
|
||||
import { isCSVFile } from '@fastgpt/global/common/file/utils';
|
||||
|
||||
export type backupQuery = {};
|
||||
|
||||
@@ -31,8 +31,8 @@ async function handler(req: ApiRequestProps<backupBody, backupQuery>, res: ApiRe
|
||||
const { file, data } = await upload.getUploadFile<{ datasetId: string }>(req, res);
|
||||
filePaths.push(file.path);
|
||||
|
||||
if (file.mimetype !== 'text/csv') {
|
||||
throw new Error('File must be a CSV file');
|
||||
if (!isCSVFile(file.originalname)) {
|
||||
return Promise.reject('File must be a CSV file');
|
||||
}
|
||||
|
||||
const { teamId, tmbId, dataset } = await authDataset({
|
||||
|
||||
@@ -12,8 +12,8 @@ import {
|
||||
DatasetCollectionTypeEnum
|
||||
} from '@fastgpt/global/core/dataset/constants';
|
||||
import { i18nT } from '@fastgpt/web/i18n/utils';
|
||||
import { isCSVFile } from '@fastgpt/global/common/file/utils';
|
||||
import { uploadFile } from '@fastgpt/service/common/file/gridfs/controller';
|
||||
import { getFileS3Key } from '@fastgpt/service/common/s3/utils';
|
||||
|
||||
export type templateImportQuery = {};
|
||||
|
||||
@@ -34,8 +34,8 @@ async function handler(
|
||||
const { file, data } = await upload.getUploadFile<templateImportBody>(req, res);
|
||||
filePaths.push(file.path);
|
||||
|
||||
if (file.mimetype !== 'text/csv') {
|
||||
throw new Error('File must be a CSV file');
|
||||
if (!isCSVFile(file.originalname)) {
|
||||
return Promise.reject('File must be a CSV file');
|
||||
}
|
||||
|
||||
const { teamId, tmbId, dataset } = await authDataset({
|
||||
|
||||
Reference in New Issue
Block a user