diff --git a/docSite/assets/imgs/gapierTool13.webp b/docSite/assets/imgs/gapierTool13.webp new file mode 100644 index 000000000000..cd3ae8edd9de Binary files /dev/null and b/docSite/assets/imgs/gapierTool13.webp differ diff --git a/files/deploy/fastgpt/docker-compose.yml b/files/deploy/fastgpt/docker-compose.yml index 9914dbdc9d75..1bf01495eb38 100644 --- a/files/deploy/fastgpt/docker-compose.yml +++ b/files/deploy/fastgpt/docker-compose.yml @@ -66,8 +66,8 @@ services: wait $! fastgpt: container_name: fastgpt - image: registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:v4.6.9 # git - # image: registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:v4.6.9 # 阿里云 + image: registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:v4.7 # git + # image: registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:v4.7 # 阿里云 ports: - 3000:3000 networks: diff --git a/packages/service/common/file/utils.ts b/packages/service/common/file/utils.ts index 47d956932994..bf3b50cbfa78 100644 --- a/packages/service/common/file/utils.ts +++ b/packages/service/common/file/utils.ts @@ -1,4 +1,6 @@ +import { isProduction } from '../system/constants'; import fs from 'fs'; +import path from 'path'; export const removeFilesByPaths = (paths: string[]) => { paths.forEach((path) => { @@ -42,3 +44,30 @@ export const clearDirFiles = (dirPath: string) => { } }); }; + +export const clearTmpUploadFiles = () => { + if (!isProduction) return; + const tmpPath = '/tmp'; + + fs.readdir(tmpPath, (err, files) => { + if (err) return; + + for (const file of files) { + if (file === 'v8-compile-cache-0') continue; + + const filePath = path.join(tmpPath, file); + + fs.stat(filePath, (err, stats) => { + if (err) return; + + // 如果文件是在1小时前上传的,则认为是临时文件并删除它 + if (Date.now() - stats.mtime.getTime() > 1 * 60 * 60 * 1000) { + fs.unlink(filePath, (err) => { + if (err) return; + console.log(`Deleted temp file: ${filePath}`); + }); + } + }); + } + }); +}; diff --git a/packages/service/common/system/constants.ts b/packages/service/common/system/constants.ts index 1fe15f292acf..af250cfdc4f1 100644 --- a/packages/service/common/system/constants.ts +++ b/packages/service/common/system/constants.ts @@ -1 +1,3 @@ export const FastGPTProUrl = process.env.PRO_URL ? `${process.env.PRO_URL}/api` : ''; + +export const isProduction = process.env.NODE_ENV === 'production'; diff --git a/projects/app/src/pages/api/common/file/upload.ts b/projects/app/src/pages/api/common/file/upload.ts index efa9b2ad791c..0563b8b5ca6a 100644 --- a/projects/app/src/pages/api/common/file/upload.ts +++ b/projects/app/src/pages/api/common/file/upload.ts @@ -27,7 +27,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< throw new Error('bucketName is empty'); } - const upLoadResults = await uploadFile({ + const fileId = await uploadFile({ teamId, tmbId, bucketName, @@ -38,7 +38,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< }); jsonRes(res, { - data: upLoadResults + data: fileId }); } catch (error) { jsonRes(res, { diff --git a/projects/app/src/service/common/system/cron.ts b/projects/app/src/service/common/system/cron.ts index 8ab3ad580579..f3f9234fe4e8 100644 --- a/projects/app/src/service/common/system/cron.ts +++ b/projects/app/src/service/common/system/cron.ts @@ -1,8 +1,10 @@ import { setCron } from '@fastgpt/service/common/system/cron'; import { startTrainingQueue } from '@/service/core/dataset/training/utils'; +import { clearTmpUploadFiles } from '@fastgpt/service/common/file/utils'; export const startCron = () => { setTrainingQueueCron(); + setClearTmpUploadFilesCron(); }; export const setTrainingQueueCron = () => { @@ -10,3 +12,11 @@ export const setTrainingQueueCron = () => { startTrainingQueue(); }); }; + +export const setClearTmpUploadFilesCron = () => { + clearTmpUploadFiles(); + // Clear tmp upload files every ten minutes + setCron('*/10 * * * *', () => { + clearTmpUploadFiles(); + }); +};