feat(profile): personal account page with own-profile editing
Add public/profile.html + public/js/profile.js: hash-routed page with
tabs for personal data, password, AI models, prompts and branches
(admin-only), plus clickable counters for the user's own work.
Server:
- users gains email/phone/avatar (init.sql, migration.sql, ensureUserTables)
- GET /api/users/:id — self or admin, returns created_at and branch_ids
- GET /api/users/:id/stats — entries/shorts/feedbacks/lessons/groups counts
- PUT /api/users/:id/profile — name/email/phone/password, audit user.profile.update
- POST /api/users/:id/avatar — upload.single('photo'), audit user.avatar.update
- safeUser() now exposes email/phone/avatar/created_at
- users.avatar added to sweepOrphanedUploads and BROKEN_IMAGE_SOURCES
- getPersonalAiModels()/resolveUserAiProfile() for personal AI profiles;
POST /api/shorts/ai-correct resolves them and 400s on unknown profile
Frontend:
- sidebar entry "Профиль"; .btn-secondary/.btn-xs/.muted in admin.css
- profile.js saves AI and prompt tabs as two independent PUTs
- feedback.js and shorts.js now fill model selects from
GET /api/ai/profiles/options by role (admin sees system profiles,
tutor sees native + own models) so the choice is actually persisted
Docs: AGENTS.md 3h updated, new section 3p.
This commit is contained in:
+31
-16
@@ -201,6 +201,25 @@
|
||||
if (!Array.isArray(myModels)) myModels = [];
|
||||
}
|
||||
|
||||
function myModelsOptgroup() {
|
||||
const grp = document.createElement('optgroup');
|
||||
grp.label = 'Мои модели';
|
||||
myModels.forEach(m => {
|
||||
const o = document.createElement('option');
|
||||
o.value = m.id;
|
||||
o.textContent = m.name;
|
||||
grp.appendChild(o);
|
||||
});
|
||||
return grp;
|
||||
}
|
||||
|
||||
function nativeOption(label) {
|
||||
const o = document.createElement('option');
|
||||
o.value = 'native';
|
||||
o.textContent = label;
|
||||
return o;
|
||||
}
|
||||
|
||||
function renderModelsList() {
|
||||
const el = document.getElementById('fbModelsList');
|
||||
if (!el) return;
|
||||
@@ -686,26 +705,22 @@
|
||||
const sel = document.getElementById('fbModel');
|
||||
if (!sel) return;
|
||||
const keep = sel.value;
|
||||
const nativeLabel = d.native?.model ? `Нативная — ${d.native.model}` : 'Нативная (llama.cpp)';
|
||||
sel.innerHTML = '';
|
||||
if (myModels.length) {
|
||||
const mine = document.createElement('optgroup');
|
||||
mine.label = 'Мои модели';
|
||||
myModels.forEach(m => {
|
||||
const o = document.createElement('option');
|
||||
o.value = m.id;
|
||||
o.textContent = m.name;
|
||||
mine.appendChild(o);
|
||||
});
|
||||
sel.appendChild(mine);
|
||||
if (isAdmin()) {
|
||||
if (myModels.length) sel.appendChild(myModelsOptgroup());
|
||||
const sys = document.createElement('optgroup');
|
||||
sys.label = 'Системные';
|
||||
sys.appendChild(nativeOption(nativeLabel));
|
||||
(d.profiles || []).forEach(p => { const o = document.createElement('option'); o.value = p.id; o.textContent = p.name; sys.appendChild(o); });
|
||||
sel.appendChild(sys);
|
||||
} else {
|
||||
sel.appendChild(nativeOption(nativeLabel));
|
||||
if (myModels.length) sel.appendChild(myModelsOptgroup());
|
||||
}
|
||||
const sys = document.createElement('optgroup');
|
||||
sys.label = 'Системные';
|
||||
const nativeOpt = document.createElement('option'); nativeOpt.value = 'native'; nativeOpt.textContent = 'Нативная (llama.cpp)'; sys.appendChild(nativeOpt);
|
||||
(d.profiles||[]).forEach(p => { const o = document.createElement('option'); o.value = p.id; o.textContent = p.name; sys.appendChild(o); });
|
||||
sel.appendChild(sys);
|
||||
aiActive = d.active || 'native';
|
||||
if (keep && [...sel.options].some(o => o.value === keep)) sel.value = keep;
|
||||
else sel.value = aiActive;
|
||||
else sel.value = [...sel.options].some(o => o.value === aiActive) ? aiActive : 'native';
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+54
-7
@@ -468,20 +468,67 @@ async function delShorts(id) {
|
||||
|
||||
let shortsAiBusy = false;
|
||||
|
||||
async function loadShortsAiModels() {
|
||||
const [mineRes, optRes] = await Promise.allSettled([
|
||||
fetch(`${API}/api/user-settings`, { headers: hdr() }),
|
||||
fetch(`${API}/api/ai/profiles/options`, { headers: hdr() })
|
||||
]);
|
||||
const result = { native: 'Нативная', active: 'native', profiles: [], personal: [] };
|
||||
if (optRes.status === 'fulfilled' && optRes.value.ok) {
|
||||
const d = await optRes.value.json().catch(() => ({}));
|
||||
if (d.native?.model) result.native = `Нативная — ${d.native.model}`;
|
||||
result.active = d.active || 'native';
|
||||
if (Array.isArray(d.profiles)) result.profiles = d.profiles;
|
||||
}
|
||||
if (mineRes.status === 'fulfilled' && mineRes.value.ok) {
|
||||
const d = await mineRes.value.json().catch(() => ({}));
|
||||
let arr = [];
|
||||
try { arr = JSON.parse(d.settings?.feedback_models || '[]'); } catch (e) { arr = []; }
|
||||
if (Array.isArray(arr)) result.personal = arr.filter(m => m && m.id);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function shortsAiNativeOption(label) {
|
||||
const o = document.createElement('option');
|
||||
o.value = 'native';
|
||||
o.textContent = label;
|
||||
return o;
|
||||
}
|
||||
|
||||
function shortsAiOptgroup(label, items) {
|
||||
const grp = document.createElement('optgroup');
|
||||
grp.label = label;
|
||||
items.forEach(m => {
|
||||
const o = document.createElement('option');
|
||||
o.value = m.id;
|
||||
o.textContent = [m.name, m.model].filter(Boolean).join(' — ');
|
||||
grp.appendChild(o);
|
||||
});
|
||||
return grp;
|
||||
}
|
||||
|
||||
async function openShortsAi() {
|
||||
const src = document.getElementById('aiSourceText');
|
||||
src.value = document.getElementById('shortsLines').value;
|
||||
document.getElementById('aiSuggestion').textContent = '';
|
||||
document.getElementById('aiCorrectModal').classList.add('open');
|
||||
const sel = document.getElementById('aiModelSelect');
|
||||
const keep = sel.value;
|
||||
try {
|
||||
const res = await fetch(`${API}/api/ai/profiles/options`, { headers: hdr() });
|
||||
if (!res.ok) throw new Error('Профили недоступны');
|
||||
const data = await res.json();
|
||||
const profiles = data.profiles || [];
|
||||
sel.innerHTML = `<option value="native">Нативная — ${esc(data.native?.model || '')}</option>` +
|
||||
profiles.map(p => `<option value="${esc(p.id)}">${esc(p.name)} — ${esc(p.model)}</option>`).join('');
|
||||
sel.value = data.active || 'native';
|
||||
const models = await loadShortsAiModels();
|
||||
sel.innerHTML = '';
|
||||
if (isAdmin()) {
|
||||
if (models.personal.length) sel.appendChild(shortsAiOptgroup('Мои модели', models.personal));
|
||||
const sys = shortsAiOptgroup('Системные', models.profiles);
|
||||
sys.insertBefore(shortsAiNativeOption(models.native), sys.firstChild);
|
||||
sel.appendChild(sys);
|
||||
} else {
|
||||
sel.appendChild(shortsAiNativeOption(models.native));
|
||||
if (models.personal.length) sel.appendChild(shortsAiOptgroup('Мои модели', models.personal));
|
||||
}
|
||||
sel.value = keep && [...sel.options].some(o => o.value === keep) ? keep
|
||||
: ([...sel.options].some(o => o.value === models.active) ? models.active : 'native');
|
||||
} catch (e) {
|
||||
sel.innerHTML = '<option value="native">Нативная</option>';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user