feat: require calendar title configuration

This commit is contained in:
leon
2026-10-08 00:38:57 +02:00
parent 67d5d5bb36
commit 3d1a08aa11
6 changed files with 28 additions and 2 deletions

View File

@@ -12,7 +12,10 @@ const db = new DatabaseSync(path.join(dataDirectory, manifest.id + '.sqlite'));
db.exec('CREATE TABLE IF NOT EXISTS events (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id TEXT NOT NULL, title TEXT NOT NULL CHECK(length(title)<=120), event_date TEXT NOT NULL, notes TEXT NOT NULL DEFAULT "" CHECK(length(notes)<=1000), created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP)');
const listEvents = db.prepare('SELECT id,title,event_date,notes FROM events WHERE user_id=? AND event_date>=? AND event_date<? ORDER BY event_date,title');
const insertEvent = db.prepare('INSERT INTO events(user_id,title,event_date,notes) VALUES(?,?,?,?)');
const html = fs.readFileSync(path.join(__dirname, '..', 'frontend', 'index.html'));
const calendarTitle = process.env.CALENDAR_TITLE?.trim();
if (!calendarTitle) throw new Error('CALENDAR_TITLE muss gesetzt werden');
const escapeHtml = (value) => value.replace(/[&<>"']/g, (character) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '\"': '&quot;', "'": '&#39;' })[character]);
const html = fs.readFileSync(path.join(__dirname, '..', 'frontend', 'index.html'), 'utf8').replaceAll('Mein Kalender', escapeHtml(calendarTitle));
function json(res, status, value) { res.writeHead(status, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' }); res.end(JSON.stringify(value)); }
async function bodyJson(req) { let data=''; for await (const chunk of req) { data+=chunk; if(data.length>16384) throw new Error('too large'); } return JSON.parse(data||'{}'); }
const server = createModuleServer({manifest,logger,routes:async(req,res,{path:pathname,url,identity})=>{