MCPcopy Create free account
hub / github.com/Xchristech2/Zenitsu-Bot / cleanupTempFiles

Function cleanupTempFiles

lib/tempCleanup.js:5–44  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3
4// Utility for cleaning temp files
5function cleanupTempFiles() {
6 const tempDir = path.join(process.cwd(), 'temp');
7
8 if (!fs.existsSync(tempDir)) {
9 return;
10 }
11
12 fs.readdir(tempDir, (err, files) => {
13 if (err) {
14 console.error('Error reading temp directory:', err);
15 return;
16 }
17
18 let cleanedCount = 0;
19 const now = Date.now();
20 const maxAge = 3 * 60 * 60 * 1000; // 3 hours
21
22 files.forEach(file => {
23 const filePath = path.join(tempDir, file);
24
25 fs.stat(filePath, (err, stats) => {
26 if (err) return;
27
28 // Delete files older than 3 hours
29 if (now - stats.mtimeMs > maxAge) {
30 fs.unlink(filePath, (err) => {
31 if (!err) {
32 cleanedCount++;
33 console.log(`🧹 Cleaned temp file: ${file}`);
34 }
35 });
36 }
37 });
38 });
39
40 if (cleanedCount > 0) {
41 console.log(`🧹 Cleaned ${cleanedCount} temp files`);
42 }
43 });
44}
45
46// Cleanup on startup
47cleanupTempFiles();

Callers 1

tempCleanup.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected