feat: config chat file expired time

This commit is contained in:
archer
2025-04-02 17:23:39 +08:00
parent 2f9b83d924
commit dc73f47486
5 changed files with 9 additions and 3 deletions

View File

@@ -50,6 +50,8 @@ LOG_LEVEL=debug
STORE_LOG_LEVEL=warn
# 安全配置
# 对话文件 n 天过期
CHAT_FILE_EXPIRE_TIME=7
# 启动 IP 限流(true),部分接口增加了 ip 限流策略,防止非正常请求操作。
USE_IP_LIMIT=false
# 工作流最大运行次数,避免极端的死循环情况

View File

@@ -28,10 +28,11 @@ const setClearTmpUploadFilesCron = () => {
};
const clearInvalidDataCron = () => {
// Clear files
setCron('0 */1 * * *', async () => {
if (
await checkTimerLock({
timerId: TimerIdEnum.checkInValidDatasetFiles,
timerId: TimerIdEnum.checkExpiredFiles,
lockMinuted: 59
})
) {

View File

@@ -71,8 +71,10 @@ export async function checkInvalidDatasetFiles(start: Date, end: Date) {
export const removeExpiredChatFiles = async () => {
let deleteFileAmount = 0;
const collection = getGFSCollection(BucketNameEnum.chat);
const expireTime = Number(process.env.CHAT_FILE_EXPIRE_TIME || 7);
const where = {
uploadDate: { $lte: addDays(new Date(), -7) }
uploadDate: { $lte: addDays(new Date(), -expireTime) }
};
// get all file _id