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
+4
View File
@@ -232,9 +232,11 @@ CREATE TABLE IF NOT EXISTS user_notes (
tags TEXT NOT NULL DEFAULT '',
color VARCHAR(7) NOT NULL DEFAULT '#2563eb',
sort_order INT NOT NULL DEFAULT 0,
ai_status VARCHAR(20) NOT NULL DEFAULT 'none',
created_at TIMESTAMPTZ DEFAULT now(),
updated_at TIMESTAMPTZ DEFAULT now()
);
CREATE INDEX IF NOT EXISTS idx_user_notes_pending ON user_notes(ai_status, id) WHERE ai_status = 'pending';
CREATE TABLE IF NOT EXISTS sessions (
id SERIAL PRIMARY KEY,
@@ -432,6 +434,8 @@ ON CONFLICT (key) DO NOTHING;
INSERT INTO settings (key, value) VALUES ('lesson_ai_enabled', 'true')
ON CONFLICT (key) DO NOTHING;
INSERT INTO settings (key, value) VALUES ('notes_ai_enabled', 'true')
ON CONFLICT (key) DO NOTHING;
INSERT INTO settings (key, value) VALUES ('lesson_ai_prompt', 'Ты — редактор сообщений тьютора детской IT-школы.
Переработай исходный текст занятия так, чтобы он звучал естественно и грамотно, как будто его написал живой тьютор родителю, а не нейросеть.
+3
View File
@@ -190,6 +190,9 @@ CREATE TABLE IF NOT EXISTS user_notes (
);
ALTER TABLE user_notes ADD COLUMN IF NOT EXISTS sort_order INT NOT NULL DEFAULT 0;
ALTER TABLE user_notes ADD COLUMN IF NOT EXISTS ai_status VARCHAR(20) NOT NULL DEFAULT 'none';
CREATE INDEX IF NOT EXISTS idx_user_notes_pending ON user_notes(ai_status, id) WHERE ai_status = 'pending';
INSERT INTO settings (key, value) VALUES ('notes_ai_enabled', 'true') ON CONFLICT (key) DO NOTHING;
CREATE TABLE IF NOT EXISTS api_keys (
id SERIAL PRIMARY KEY,