summaryrefslogtreecommitdiff
path: root/server/js/paths.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/js/paths.js')
-rw-r--r--server/js/paths.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/server/js/paths.js b/server/js/paths.js
new file mode 100644
index 0000000..ee10807
--- /dev/null
+++ b/server/js/paths.js
@@ -0,0 +1,37 @@
+"use strict";
+
+const fs = require('fs');
+const path = require('path');
+const os = require('os');
+
+function ensureFolder(folder)
+{
+ if (!fs.existsSync(folder))
+ {
+ fs.mkdirSync(folder, { recursive: true });
+ }
+ return folder;
+}
+
+const envPaths = {
+ 'linux': function () {
+ return {
+ HOME: os.homedir(),
+ DATA: process.env.XDG_DATA_HOME || ensureFolder(path.join(os.homedir(), '.local', 'share')),
+ CONFIG: process.env.XDG_CONFIG_HOME || ensureFolder(path.join(os.homedir(), '.config')),
+ CACHE: process.env.XDG_CACHE_HOME || ensureFolder(path.join(os.homedir(), '.cache'))
+ }
+ },
+
+ 'win32': function () {
+ return {
+ HOME: os.homedir(),
+ DATA: process.env.APPDATA || ensureFolder(path.join(os.homedir(), 'AppData', 'Roaming')),
+ CONFIG: process.env.APPDATA || ensureFolder(path.join(os.homedir(), 'AppData', 'Roaming')),
+ CACHE: process.env.TEMP || process.env.TMP || ensureFolder(path.join(process.env.LOCALAPPDATA, 'Temp'))
+ }
+ }
+
+} [os.platform()]();
+
+module.exports = {ensureFolder, envPaths}; \ No newline at end of file