fix: csv check (#6044)
Some checks are pending
Build FastGPT images in Personal warehouse / get-vars (push) Waiting to run
Build FastGPT images in Personal warehouse / build-fastgpt-images (map[arch:amd64 runs-on:ubuntu-24.04]) (push) Blocked by required conditions
Build FastGPT images in Personal warehouse / build-fastgpt-images (map[arch:arm64 runs-on:ubuntu-24.04-arm]) (push) Blocked by required conditions
Build FastGPT images in Personal warehouse / release-fastgpt-images (push) Blocked by required conditions

* 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:
Archer 2025-12-07 15:02:36 +08:00 committed by GitHub
parent 003e66883c
commit 9d72f238c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 6 deletions

View File

@ -0,0 +1,6 @@
import path from 'path';
export const isCSVFile = (filename: string) => {
const extension = path.extname(filename).toLowerCase();
return extension === '.csv';
};

View File

@ -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({

View File

@ -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({