Watch Stores mit Offen-Spalte
This commit is contained in:
40
services/storeStatusStore.js
Normal file
40
services/storeStatusStore.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const STORE_STATUS_FILE = path.join(__dirname, '..', 'config', 'store-watch-status.json');
|
||||
|
||||
function ensureDir() {
|
||||
const dir = path.dirname(STORE_STATUS_FILE);
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
}
|
||||
}
|
||||
|
||||
function readStoreStatus() {
|
||||
ensureDir();
|
||||
if (!fs.existsSync(STORE_STATUS_FILE)) {
|
||||
fs.writeFileSync(STORE_STATUS_FILE, JSON.stringify({}, null, 2));
|
||||
return {};
|
||||
}
|
||||
try {
|
||||
const raw = fs.readFileSync(STORE_STATUS_FILE, 'utf8');
|
||||
const parsed = JSON.parse(raw);
|
||||
if (parsed && typeof parsed === 'object') {
|
||||
return parsed;
|
||||
}
|
||||
return {};
|
||||
} catch (error) {
|
||||
console.error('[STORE-STATUS] Konnte Cache nicht lesen:', error.message);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
function writeStoreStatus(cache = {}) {
|
||||
ensureDir();
|
||||
fs.writeFileSync(STORE_STATUS_FILE, JSON.stringify(cache, null, 2));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
readStoreStatus,
|
||||
writeStoreStatus
|
||||
};
|
||||
Reference in New Issue
Block a user