Добавить панель системы и временный внешний доступ

This commit is contained in:
Никита
2026-11-10 11:25:50 +03:00
parent 0e0efe5614
commit a81c0bad34
19 changed files with 383 additions and 8 deletions
+18 -5
View File
@@ -1,3 +1,4 @@
import { operationsSession } from '/operations.js';
import { attachmentSession } from '/attachments.js';
import { recordRequest, updateSessionInfo, updateHistoryInfo } from "/diagnostics.js";
@@ -104,6 +105,7 @@ async function enterSession(session) {
state.epoch++;
state.session = session;
attachmentSession(session.token);
operationsSession(session.token);
clearAttachedDrafts();
updateSessionInfo({ name: session.user.display_name, expiresAt: session.expires_at });
updateHistoryInfo(null);
@@ -140,6 +142,7 @@ function endSession(message = "") {
state.epoch++;
state.session = null;
attachmentSession(null);
operationsSession(null);
clearAttachedDrafts();
updateSessionInfo(null);
updateHistoryInfo(null);
@@ -570,13 +573,21 @@ $("new-chat-form").addEventListener("submit", async event => {
const form = event.currentTarget, token = state.session?.token;
const title = $("new-chat-title").value.trim();
if (!title || Array.from(title).length > 100) return notice("chat-dialog-notice", "Название должно содержать от 1 до 100 символов.");
const ids = $("new-chat-members").value.split(/[\s,;]+/u).filter(Boolean);
if (ids.some(id => !/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(id)))
return notice("chat-dialog-notice", "Проверьте ID участников: нужен полный ID из профиля.");
const members = [...new Set([state.session.user.id, ...ids.map(id => id.toLowerCase())])];
if (members.length > 100) return notice("chat-dialog-notice", "В чате может быть не более 100 участников.");
const entries = $("new-chat-members").value.split(/[\s,;]+/u).filter(Boolean);
if(entries.length>99)return notice("chat-dialog-notice","Не более 99 приглашений за раз.");
setFormBusy(form, true); notice("chat-dialog-notice", "");
try {
const ids=[];
for(const entry of entries) {
if(/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(entry))ids.push(entry.toLowerCase());
else {
const username=entry.replace(/^@/,'').toLowerCase();
if(!/^[a-z0-9_]{3,32}$/.test(username))throw new Error('Введите логин или полный ID участника.');
const user=await request('/api/ui/users/'+encodeURIComponent(username));ids.push(user.id);
}
}
if(token!==state.session?.token)return;
const members=[...new Set([state.session.user.id,...ids])];
const chat = await request("/api/v1/chats", { method: "POST", body: { title, member_ids: members } });
if (token !== state.session?.token) return;
$("new-chat-dialog").close(); state.chats.push(chat); renderChats();
@@ -632,11 +643,13 @@ async function resume() {
if (!session?.token || !session.user || !(new Date(session.expires_at).getTime() > Date.now())) return endSession();
state.session = session;
attachmentSession(session.token);
operationsSession(session.token);
const user = await request("/api/v1/users/me");
await enterSession({ ...session, user });
} catch (error) {
state.session = null;
attachmentSession(null);
operationsSession(null);
clearAttachedDrafts();
if (error instanceof ApiError) notice("auth-notice", error.message);
else { try { sessionStorage.removeItem(storageKey); } catch { /* storage unavailable */ } }