aktueller Stand

This commit is contained in:
root
2025-11-09 13:50:17 +01:00
parent 81e7f94817
commit dc95156793
16 changed files with 2152 additions and 1148 deletions

48
services/configStore.js Normal file
View File

@@ -0,0 +1,48 @@
const fs = require('fs');
const path = require('path');
const defaultConfig = require('../data/defaultConfig');
const CONFIG_DIR = path.join(__dirname, '..', 'config');
function ensureDir() {
if (!fs.existsSync(CONFIG_DIR)) {
fs.mkdirSync(CONFIG_DIR, { recursive: true });
}
}
function getConfigPath(profileId = 'shared') {
return path.join(CONFIG_DIR, `${profileId}-pickup-config.json`);
}
function hydrateConfigFile(profileId) {
ensureDir();
const filePath = getConfigPath(profileId);
if (!fs.existsSync(filePath)) {
fs.writeFileSync(filePath, JSON.stringify(defaultConfig, null, 2));
}
return filePath;
}
function readConfig(profileId) {
const filePath = hydrateConfigFile(profileId);
try {
const raw = fs.readFileSync(filePath, 'utf8');
const parsed = JSON.parse(raw);
return Array.isArray(parsed) ? parsed : [];
} catch (err) {
console.error(`Failed to read config for ${profileId}:`, err);
return [];
}
}
function writeConfig(profileId, payload) {
const filePath = hydrateConfigFile(profileId);
fs.writeFileSync(filePath, JSON.stringify(payload, null, 2));
return filePath;
}
module.exports = {
readConfig,
writeConfig,
getConfigPath
};