4.6.7-alpha commit (#743)

Co-authored-by: Archer <545436317@qq.com>
Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com>
This commit is contained in:
Archer
2024-01-19 11:17:28 +08:00
committed by GitHub
parent 8ee7407c4c
commit c031e6dcc9
324 changed files with 8509 additions and 4757 deletions

View File

@@ -1,5 +1,4 @@
import fs from 'fs';
import { tmpFileDirPath } from './constants';
export const removeFilesByPaths = (paths: string[]) => {
paths.forEach((path) => {
@@ -10,24 +9,3 @@ export const removeFilesByPaths = (paths: string[]) => {
});
});
};
/* cron job. check expired tmp files */
export const checkExpiredTmpFiles = () => {
// get all file name
const files = fs.readdirSync(tmpFileDirPath).map((name) => {
const timestampStr = name.split('-')[0];
const expiredTimestamp = timestampStr ? Number(timestampStr) : 0;
return {
filename: name,
expiredTimestamp,
path: `${tmpFileDirPath}/${name}`
};
});
// count expiredFiles
const expiredFiles = files.filter((item) => item.expiredTimestamp < Date.now());
// remove expiredFiles
removeFilesByPaths(expiredFiles.map((item) => item.path));
};