notes: AI titles for new notes, personal-only access, modal polish

- new note created without a title gets one generated by a background
  worker (createNoteTitleWorker, ai_status column, wake channel,
  notes_changed SSE event, settings toggle notes_ai_enabled)
- notes are strictly personal: list/update/delete/reorder always scoped
  to req.user.id, admin no longer sees other users' notes (403)
- notes modal: focus goes to the text body, random color for new notes,
  ctrl+enter hint, tags hint styling, empty-title 400 fix (optText)
- backup/restore: user_notes.ai_status normalized and restored
This commit is contained in:
dev
2026-10-08 21:47:37 +03:00
parent f226c3f144
commit b5d1fd0948
10 changed files with 427 additions and 34 deletions
+10
View File
@@ -179,6 +179,14 @@ function reqAiStatus(v, fallback) {
return AI_STATUSES.has(s) ? s : fallback;
}
function normalizeAiStatus(v) {
if (v === null || v === undefined) return 'none';
const s = String(v);
if (s === 'none' || s === 'pending') return s;
if (s === 'processing') return 'pending';
return ['done', 'skipped', 'error'].includes(s) ? s : 'none';
}
const PROFILE_HREF_RE = /^(https?:\/\/|mailto:|tel:|\/|#)/i;
const PROFILE_EMAIL_RE = /^[\w.+-]+@[\w-]+\.[\w.-]{2,}$/;
@@ -557,6 +565,7 @@ function normalizeRestoreData(data) {
tags: optText(x.tags, 50000) || '',
color: optText(x.color, 7) || '#2563eb',
sort_order: optInt(x.sort_order, -10000000, 10000000) ?? 0,
ai_status: normalizeAiStatus(x.ai_status),
created_at: optTs(x.created_at),
updated_at: optTs(x.updated_at),
}));
@@ -575,6 +584,7 @@ module.exports = {
optInt,
reqStr,
optStr,
optText,
optTs,
reqTs,
optDate,