41 lines
978 B
JavaScript
41 lines
978 B
JavaScript
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
|
|
};
|