From 232caf8a4eabd02d1ec8fc3f8f310cf9442760bc Mon Sep 17 00:00:00 2001 From: Glenn de Haan Date: Fri, 13 Feb 2026 18:50:42 +0100 Subject: [PATCH] Implemented `TASK_CLEANUP_UNUSED_DAYS` environment variable. Implemented custom unused cleanup timing. Updated README.md --- README.md | 7 +++++-- modules/variables.js | 1 + utils/cleanup.js | 5 +++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 61e976e..327eb90 100644 --- a/README.md +++ b/README.md @@ -172,8 +172,10 @@ services: TRANSLATION_DEBUG: 'false' # Enables/disables an automated task to clean up expired vouchers from UniFi TASK_CLEANUP_EXPIRED: 'false' - # Enables/disables an automated task to clean up unused vouchers (Vouchers unused a day after creation) from UniFi + # Enables/disables an automated task to clean up unused vouchers from UniFi TASK_CLEANUP_UNUSED: 'false' + # Specifies the amount of days to wait before removing the unused vouchers + TASK_CLEANUP_UNUSED_DAYS: '1' # Optional volume mapping to override assets volumes: - ./branding:/kiosk @@ -237,7 +239,8 @@ The structure of the file should use lowercase versions of the environment varia "translation_hidden_languages": "", "translation_debug": false, "task_cleanup_expired": false, - "task_cleanup_unused": false + "task_cleanup_unused": false, + "task_cleanup_unused_days": 1 } ``` diff --git a/modules/variables.js b/modules/variables.js index 22f62b8..f3d186d 100644 --- a/modules/variables.js +++ b/modules/variables.js @@ -55,6 +55,7 @@ module.exports = { translationDebug: config('translation_debug') || (process.env.TRANSLATION_DEBUG === 'true') || false, taskCleanupExpired: config('task_cleanup_expired') || (process.env.TASK_CLEANUP_EXPIRED === 'true') || false, taskCleanupUnused: config('task_cleanup_unused') || (process.env.TASK_CLEANUP_UNUSED === 'true') || false, + taskCleanupUnusedDays: config('task_cleanup_unused_days') || process.env.TASK_CLEANUP_UNUSED_DAYS || 1, gitTag: process.env.GIT_TAG || 'master', gitBuild: fs.existsSync('/etc/unifi_voucher_site_build') ? fs.readFileSync('/etc/unifi_voucher_site_build', 'utf-8') : 'Development' }; diff --git a/utils/cleanup.js b/utils/cleanup.js index b50ec5a..c9698bc 100644 --- a/utils/cleanup.js +++ b/utils/cleanup.js @@ -4,6 +4,7 @@ const cache = require('../modules/cache'); const log = require('../modules/log'); const unifi = require('../modules/unifi'); +const variables = require('../modules/variables'); /** * Import own utils @@ -39,7 +40,7 @@ module.exports = { }, /** - * Function to clean up unused voucher that are still active after a day + * Function to clean up unused voucher that are still active after defined day(s) * * @returns {Promise} */ @@ -48,7 +49,7 @@ module.exports = { const vouchers = cache.vouchers.filter((voucher) => { const today = new Date(); const voucherDate = new Date(voucher.createdAt); - voucherDate.setDate(voucherDate.getDate() + 1); + voucherDate.setDate(voucherDate.getDate() + parseInt(variables.taskCleanupUnusedDays)); return voucherDate.getTime() < today.getTime(); });