v0.9.4 bugs fixes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jama-backend",
|
||||
"version": "0.9.3",
|
||||
"version": "0.9.4",
|
||||
"description": "TeamChat backend server",
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -28,9 +28,14 @@ function getDb() {
|
||||
} else {
|
||||
console.warn('[DB] WARNING: DB_KEY not set — database is unencrypted');
|
||||
}
|
||||
db.pragma('journal_mode = WAL');
|
||||
const journalMode = db.pragma('journal_mode = WAL', { simple: true });
|
||||
if (journalMode !== 'wal') {
|
||||
console.warn(`[DB] WARNING: journal_mode is '${journalMode}', expected 'wal' — performance may be degraded`);
|
||||
}
|
||||
db.pragma('synchronous = NORMAL'); // safe with WAL, faster than FULL
|
||||
db.pragma('cache_size = -8000'); // 8MB page cache
|
||||
db.pragma('foreign_keys = ON');
|
||||
console.log(`[DB] Opened database at ${DB_PATH}`);
|
||||
console.log(`[DB] Opened database at ${DB_PATH} (journal=${journalMode})`);
|
||||
}
|
||||
return db;
|
||||
}
|
||||
|
||||
@@ -70,12 +70,10 @@ router.post('/subscribe', authMiddleware, (req, res) => {
|
||||
return res.status(400).json({ error: 'Invalid subscription' });
|
||||
}
|
||||
const db = getDb();
|
||||
// Use DELETE+INSERT to avoid relying on any specific UNIQUE constraint
|
||||
// (existing DBs may have different schemas for this table)
|
||||
const delStmt = db.prepare('DELETE FROM push_subscriptions WHERE endpoint = ?');
|
||||
const insStmt = db.prepare('INSERT INTO push_subscriptions (user_id, endpoint, p256dh, auth) VALUES (?, ?, ?, ?)');
|
||||
delStmt.run(endpoint);
|
||||
insStmt.run(req.user.id, endpoint, keys.p256dh, keys.auth);
|
||||
const device = req.device || 'desktop';
|
||||
// Delete any existing subscription for this user+device or this endpoint, then insert fresh
|
||||
db.prepare('DELETE FROM push_subscriptions WHERE endpoint = ? OR (user_id = ? AND device = ?)').run(endpoint, req.user.id, device);
|
||||
db.prepare('INSERT INTO push_subscriptions (user_id, device, endpoint, p256dh, auth) VALUES (?, ?, ?, ?, ?)').run(req.user.id, device, endpoint, keys.p256dh, keys.auth);
|
||||
res.json({ success: true });
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user