feat: add option to customize how often files are automatically deleted
This commit is contained in:
parent
5b1703db68
commit
317c932c2a
2 changed files with 8 additions and 6 deletions
|
|
@ -47,6 +47,7 @@ services:
|
||||||
- JWT_SECRET=aLongAndSecretStringUsedToSignTheJSONWebToken1234 # will use randomUUID() by default
|
- JWT_SECRET=aLongAndSecretStringUsedToSignTheJSONWebToken1234 # will use randomUUID() by default
|
||||||
- HTTP_ALLOWED=false # setting this to true is unsafe, only set this to true locally
|
- HTTP_ALLOWED=false # setting this to true is unsafe, only set this to true locally
|
||||||
- ALLOW_UNAUTHENTICATED=false # allows anyone to use the service without logging in, only set this to true locally
|
- ALLOW_UNAUTHENTICATED=false # allows anyone to use the service without logging in, only set this to true locally
|
||||||
|
- AUTO_DELETE_EVERY_N_HOURS=24 # checks every n hours for files older then n hours and deletes them, set to 0 to disable
|
||||||
volumes:
|
volumes:
|
||||||
- convertx:/app/data
|
- convertx:/app/data
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ const HTTP_ALLOWED =
|
||||||
process.env.HTTP_ALLOWED?.toLowerCase() === "true" || false;
|
process.env.HTTP_ALLOWED?.toLowerCase() === "true" || false;
|
||||||
const ALLOW_UNAUTHENTICATED =
|
const ALLOW_UNAUTHENTICATED =
|
||||||
process.env.ALLOW_UNAUTHENTICATED?.toLowerCase() === "true" || false;
|
process.env.ALLOW_UNAUTHENTICATED?.toLowerCase() === "true" || false;
|
||||||
|
const AUTO_DELETE_EVERY_N_HOURS = process.env.AUTO_DELETE_EVERY_N_HOURS ? Number(process.env.AUTO_DELETE_EVERY_N_HOURS) : 24;
|
||||||
|
|
||||||
// fileNames: fileNames,
|
// fileNames: fileNames,
|
||||||
// filesToConvert: fileNames.length,
|
// filesToConvert: fileNames.length,
|
||||||
|
|
@ -1263,12 +1264,10 @@ console.log(
|
||||||
);
|
);
|
||||||
|
|
||||||
const clearJobs = () => {
|
const clearJobs = () => {
|
||||||
// clear all jobs older than 24 hours
|
|
||||||
// get all files older than 24 hours
|
|
||||||
const jobs = db
|
const jobs = db
|
||||||
.query("SELECT * FROM jobs WHERE date_created < ?")
|
.query("SELECT * FROM jobs WHERE date_created < ?")
|
||||||
.as(Jobs)
|
.as(Jobs)
|
||||||
.all(new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString());
|
.all(new Date(Date.now() - AUTO_DELETE_EVERY_N_HOURS * 60 * 60 * 1000).toISOString());
|
||||||
|
|
||||||
for (const job of jobs) {
|
for (const job of jobs) {
|
||||||
// delete the directories
|
// delete the directories
|
||||||
|
|
@ -1279,7 +1278,9 @@ const clearJobs = () => {
|
||||||
db.query("DELETE FROM jobs WHERE id = ?").run(job.id);
|
db.query("DELETE FROM jobs WHERE id = ?").run(job.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// run every 24 hours
|
setTimeout(clearJobs, AUTO_DELETE_EVERY_N_HOURS * 60 * 60 * 1000);
|
||||||
setTimeout(clearJobs, 24 * 60 * 60 * 1000);
|
|
||||||
};
|
};
|
||||||
clearJobs();
|
|
||||||
|
if (AUTO_DELETE_EVERY_N_HOURS > 0) {
|
||||||
|
clearJobs();
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue