From 00bc03f25759f6ad8e538c7b58aa0c10b0f437b7 Mon Sep 17 00:00:00 2001
From: rokiden <cheto@bk.ru>
Date: Fri, 22 Sep 2023 20:27:31 +0600
Subject: [PATCH] Added BACKUP_DIR env

---
 .env                    | 3 +++
 docs/developing.md      | 1 +
 services/save-config.js | 4 +++-
 3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/.env b/.env
index d7024eb2..c7953212 100644
--- a/.env
+++ b/.env
@@ -35,3 +35,6 @@
 
 # Again, set automatically using package.json during build time
 # VUE_APP_VERSION=2.0.0
+
+# Directory for conf.yml backups
+# BACKUP_DIR=./public/
\ No newline at end of file
diff --git a/docs/developing.md b/docs/developing.md
index 4571385a..281f86f9 100644
--- a/docs/developing.md
+++ b/docs/developing.md
@@ -80,6 +80,7 @@ You can set variables either in your environment, or using the [`.env`](https://
 - `INTEGRITY` - Should enable SRI for build script and link resources
 - `IS_DOCKER` - Computed automatically on build. Indicates if running in container
 - `VUE_APP_VERSION` - Again, set automatically using package.json during build time
+- `BACKUP_DIR` - Directory for conf.yml backups
 
 ### Environment Modes
 
diff --git a/services/save-config.js b/services/save-config.js
index c73cecba..1af0d299 100644
--- a/services/save-config.js
+++ b/services/save-config.js
@@ -5,6 +5,7 @@
  * Finally, it will call a function with the status message
  */
 const fsPromises = require('fs').promises;
+const path = require('path');
 
 module.exports = async (newConfig, render) => {
   /* Either returns nothing (if using default path), or strips navigational characters from path */
@@ -24,7 +25,8 @@ module.exports = async (newConfig, render) => {
   };
 
   // Make the full file name and path to save the backup config file
-  const backupFilePath = `${settings.defaultLocation}${usersFileName || settings.filename}-`
+  const backupFilePath = path.normalize(process.env.BACKUP_DIR || settings.defaultLocation) 
+    + `/${usersFileName || settings.filename}-`
     + `${Math.round(new Date() / 1000)}${settings.backupDenominator}`;
 
   // The path where the main conf.yml should be read and saved to