Skip to content

Commit

Permalink
fix doc images (#1083)
Browse files Browse the repository at this point in the history
* perf: clear tmp files

* fix doc images

* update docker-compose
  • Loading branch information
c121914yu authored Mar 28, 2024
1 parent 00ace0b commit 0490b83
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 4 deletions.
Binary file added docSite/assets/imgs/gapierTool13.webp
Binary file not shown.
4 changes: 2 additions & 2 deletions files/deploy/fastgpt/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
29 changes: 29 additions & 0 deletions packages/service/common/file/utils.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down Expand Up @@ -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}`);
});
}
});
}
});
};
2 changes: 2 additions & 0 deletions packages/service/common/system/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export const FastGPTProUrl = process.env.PRO_URL ? `${process.env.PRO_URL}/api` : '';

export const isProduction = process.env.NODE_ENV === 'production';
4 changes: 2 additions & 2 deletions projects/app/src/pages/api/common/file/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -38,7 +38,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
});

jsonRes(res, {
data: upLoadResults
data: fileId
});
} catch (error) {
jsonRes(res, {
Expand Down
10 changes: 10 additions & 0 deletions projects/app/src/service/common/system/cron.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
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 = () => {
setCron('*/1 * * * *', () => {
startTrainingQueue();
});
};

export const setClearTmpUploadFilesCron = () => {
clearTmpUploadFiles();
// Clear tmp upload files every ten minutes
setCron('*/10 * * * *', () => {
clearTmpUploadFiles();
});
};

0 comments on commit 0490b83

Please sign in to comment.