mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 14:16:01 +00:00
25 lines
635 B
JavaScript
25 lines
635 B
JavaScript
const fs = require('fs-extra');
|
|
const path = require('path');
|
|
const ageSeconds = 3600;
|
|
|
|
async function cleanDirectory(directory) {
|
|
const files = await fs.readdir(directory);
|
|
const now = new Date().getTime();
|
|
|
|
for (const file of files) {
|
|
const full = path.join(directory, file);
|
|
const stat = await fs.stat(full);
|
|
const mtime = stat.mtime.getTime();
|
|
const expirationTime = mtime + ageSeconds * 1000;
|
|
if (now > expirationTime) {
|
|
if (stat.isDirectory()) {
|
|
await fs.rmdir(full, { recursive: true });
|
|
} else {
|
|
await fs.unlink(full);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = cleanDirectory;
|