feat: store bookmark last-opened timestamps only in DB
This commit is contained in:
@@ -28,6 +28,9 @@ const MIN_TEXT_HASH_LENGTH = 120;
|
||||
const MIN_SIMILAR_TEXT_LENGTH = 60;
|
||||
const MAX_BOOKMARK_LABEL_LENGTH = 120;
|
||||
const MAX_BOOKMARK_QUERY_LENGTH = 200;
|
||||
const DEFAULT_BOOKMARK_ID = 'default-search';
|
||||
const DEFAULT_BOOKMARK_LABEL = 'Gewinnspiel / gewinnen / verlosen';
|
||||
const DEFAULT_BOOKMARK_QUERY = '';
|
||||
const DAILY_BOOKMARK_TITLE_MAX_LENGTH = 160;
|
||||
const DAILY_BOOKMARK_URL_MAX_LENGTH = 800;
|
||||
const DAILY_BOOKMARK_NOTES_MAX_LENGTH = 800;
|
||||
@@ -917,18 +920,26 @@ function normalizeBookmarkLabel(value, fallback = '') {
|
||||
return label;
|
||||
}
|
||||
|
||||
function isDefaultBookmarkQuery(value) {
|
||||
return typeof value === 'string' && !value.trim();
|
||||
}
|
||||
|
||||
function serializeBookmark(row) {
|
||||
if (!row) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const isDefault = isDefaultBookmarkQuery(row.query);
|
||||
|
||||
return {
|
||||
id: row.id,
|
||||
label: row.label,
|
||||
query: row.query,
|
||||
created_at: sqliteTimestampToUTC(row.created_at),
|
||||
updated_at: sqliteTimestampToUTC(row.updated_at),
|
||||
last_clicked_at: sqliteTimestampToUTC(row.last_clicked_at)
|
||||
last_clicked_at: sqliteTimestampToUTC(row.last_clicked_at),
|
||||
is_default: isDefault,
|
||||
deletable: !isDefault
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1657,6 +1668,11 @@ const insertBookmarkStmt = db.prepare(`
|
||||
VALUES (?, ?, ?)
|
||||
`);
|
||||
|
||||
const ensureDefaultBookmarkStmt = db.prepare(`
|
||||
INSERT OR IGNORE INTO bookmarks (id, label, query)
|
||||
VALUES (?, ?, ?)
|
||||
`);
|
||||
|
||||
const deleteBookmarkStmt = db.prepare(`
|
||||
DELETE FROM bookmarks
|
||||
WHERE id = ?
|
||||
@@ -1669,6 +1685,8 @@ const updateBookmarkLastClickedStmt = db.prepare(`
|
||||
WHERE id = ?
|
||||
`);
|
||||
|
||||
ensureDefaultBookmarkStmt.run(DEFAULT_BOOKMARK_ID, DEFAULT_BOOKMARK_LABEL, DEFAULT_BOOKMARK_QUERY);
|
||||
|
||||
db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS daily_bookmarks (
|
||||
id TEXT PRIMARY KEY,
|
||||
@@ -4555,6 +4573,14 @@ app.delete('/api/bookmarks/:bookmarkId', (req, res) => {
|
||||
}
|
||||
|
||||
try {
|
||||
const existing = getBookmarkByIdStmt.get(bookmarkId);
|
||||
if (!existing) {
|
||||
return res.status(404).json({ error: 'Bookmark nicht gefunden' });
|
||||
}
|
||||
if (isDefaultBookmarkQuery(existing.query)) {
|
||||
return res.status(403).json({ error: 'Standard-Bookmark kann nicht gelöscht werden' });
|
||||
}
|
||||
|
||||
const result = deleteBookmarkStmt.run(bookmarkId);
|
||||
if (!result.changes) {
|
||||
return res.status(404).json({ error: 'Bookmark nicht gefunden' });
|
||||
|
||||
Reference in New Issue
Block a user