(feat): clearing up both photo and video after 1 day and on process' start
This commit is contained in:
+7
-4
@@ -72,7 +72,6 @@ import {YouTubeDownload} from "./commands/youtube-download";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import {setInterval} from "node:timers";
|
||||
import {clearUpVideoFolder} from "./util/files";
|
||||
import {OpenAI} from "openai";
|
||||
import {OpenAIChat} from "./commands/openai-chat";
|
||||
import {OpenAIListModels} from "./commands/openai-list-models";
|
||||
@@ -80,6 +79,7 @@ import {OpenAIGetModel} from "./commands/openai-get-model";
|
||||
import {OpenAISetModel} from "./commands/openai-set-model";
|
||||
import {Info} from "./commands/info";
|
||||
import {OpenAIGenImage} from "./commands/openai-gen-image";
|
||||
import {clearUpFolderFromOldFiles} from "./util/files";
|
||||
|
||||
process.setUncaughtExceptionCaptureCallback(logError);
|
||||
|
||||
@@ -239,12 +239,15 @@ async function main() {
|
||||
midnight.setDate(now.getDate() + 1);
|
||||
|
||||
const diff = midnight.getTime() - now.getTime();
|
||||
console.log("Clearing up videos will be started in " + diff + "ms");
|
||||
console.log("Clearing up videos and photos will be started in " + diff + "ms");
|
||||
|
||||
clearUpFolderFromOldFiles(videoDir);
|
||||
clearUpFolderFromOldFiles(photoDir);
|
||||
delay(diff).then(() => {
|
||||
setInterval(() => {
|
||||
console.log("Started clearing up videos");
|
||||
clearUpVideoFolder();
|
||||
console.log("Started clearing up videos and photos");
|
||||
clearUpFolderFromOldFiles(videoDir);
|
||||
clearUpFolderFromOldFiles(photoDir);
|
||||
}, 1000 * 60 * 60 * 24);
|
||||
});
|
||||
|
||||
|
||||
+7
-6
@@ -1,10 +1,9 @@
|
||||
import {logError} from "./utils";
|
||||
import fs from "node:fs";
|
||||
import {videoDir} from "../index";
|
||||
import path from "node:path";
|
||||
|
||||
export function clearUpVideoFolder() {
|
||||
fs.readdir(videoDir, (err, files) => {
|
||||
export function clearUpFolderFromOldFiles(folder: string) {
|
||||
fs.readdir(folder, (err, files) => {
|
||||
if (err) {
|
||||
logError(err);
|
||||
return;
|
||||
@@ -13,7 +12,7 @@ export function clearUpVideoFolder() {
|
||||
const filenamesToDelete: string[] = [];
|
||||
|
||||
files.forEach((filename, index) => {
|
||||
fs.stat(path.join(videoDir, filename), (err, stats) => {
|
||||
fs.stat(path.join(folder, filename), (err, stats) => {
|
||||
if (err) {
|
||||
logError(err);
|
||||
} else {
|
||||
@@ -29,8 +28,10 @@ export function clearUpVideoFolder() {
|
||||
console.log("filenamesToDelete", filenamesToDelete);
|
||||
if (filenamesToDelete.length) {
|
||||
filenamesToDelete.forEach((filename) => {
|
||||
const fullPath = path.join(videoDir, filename);
|
||||
fs.rm(fullPath, logError);
|
||||
const fullPath = path.join(folder, filename);
|
||||
fs.rm(fullPath, (e) => {
|
||||
if (e) logError(e);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user