- admin config group "Bug reports": Gitea address, repository, token (secret),
and "Check the connection" — the repository must answer, take issues and
be PRIVATE (a report carries its reporter's log); checked on every send too
- POST /api/debug-sessions/{id}/issue sends the SAVED draft: create the issue,
upload each file on its own request (the measured API), then show the
screenshots inline; progress is kept in the draft, so a send that stops
half-way keeps its issue and the retry sends only what is missing; 5 new
issues an hour per user; audited as issue_create
- the composer: Create issue (only where a tracker is set up, naming the
repository), a partial-send banner with retry, and a Preview — the tracker's
own rendering in a sandboxed frame, or the zip's markdown without one
- the recorder's refusals answer in the localized family (debug_session_*,
screenshot_*, issue(s)_*), not bare codes the UI could only call generic
- a tracker refusal logs the status only: its message can quote the title back
90 lines
4.1 KiB
TypeScript
90 lines
4.1 KiB
TypeScript
// The signed-in account & session: the bootstrap `me` probe, multi-account switch/list, sign-out,
|
|
// app version, and preference save. Only touches core's req.
|
|
import { req } from "./core";
|
|
import type { DebugSession, DiagnosticsState } from "./diagnostics";
|
|
|
|
export interface Me {
|
|
id: number;
|
|
email: string;
|
|
display_name: string | null;
|
|
avatar_url: string | null;
|
|
role: string;
|
|
is_demo: boolean;
|
|
/** The latest sign-in on any device (ISO), or null when none is recorded. */
|
|
last_login_at: string | null;
|
|
has_google: boolean;
|
|
/** The address Google answers with, ONLY when it differs from `email` — the backend does that
|
|
* comparison, so a surface can render this whenever it is present. Someone who registered as
|
|
* `me+siftlode@gmail.com` keeps that address; this is the other one that also signs them in. */
|
|
google_email: string | null;
|
|
has_password: boolean;
|
|
google_enabled: boolean;
|
|
plex_enabled: boolean;
|
|
can_read: boolean;
|
|
can_write: boolean;
|
|
pending_invites: number;
|
|
/** Admin-only: sign-ups an admin still has to let in — approved BEFORE they registered, so nothing
|
|
* ever reached the Access-requests queue and its badge read zero (roadmap UX-25). Counted apart
|
|
* from pending_invites because they are different facts, and widening one number silently would
|
|
* change what an existing field means. */
|
|
pending_activations: number;
|
|
/** Admin-only: false when SMTP is incomplete, so every outbound message is silently skipped. */
|
|
email_configured: boolean;
|
|
preferences: Record<string, unknown>;
|
|
/** The consented diagnostics level in force and when it lapses (E22 S5). */
|
|
diagnostics: DiagnosticsState;
|
|
/** The debug session recording right now, if any (E16) — a reload resumes it. */
|
|
debug_session: DebugSession | null;
|
|
/** Where a bug report goes — the tracker's repository — or null: download only (E16 S4). */
|
|
issues: { repo: string } | null;
|
|
}
|
|
|
|
/** The `nav.role.*` key an account is shown under. Demo isn't a real role (it's a flag on a `user`
|
|
* row), so it comes first. */
|
|
export function roleKey(a: Pick<Me, "is_demo" | "role">): "admin" | "user" | "demo" {
|
|
return a.is_demo ? "demo" : a.role === "admin" ? "admin" : "user";
|
|
}
|
|
|
|
/** What an account is called on screen: its display name, else the local part of its email. */
|
|
export function displayName(a: { display_name: string | null; email: string }): string {
|
|
return a.display_name ?? a.email.split("@")[0]!;
|
|
}
|
|
|
|
export interface Account {
|
|
id: number;
|
|
email: string;
|
|
display_name: string | null;
|
|
avatar_url: string | null;
|
|
active: boolean;
|
|
}
|
|
|
|
export interface VersionInfo {
|
|
app_version: string;
|
|
git_sha: string;
|
|
build_date: string | null;
|
|
db_revision: string | null;
|
|
}
|
|
|
|
export const accountApi = {
|
|
// Bootstrap probe: 200 always. Returns the user when signed in, or null when logged out
|
|
// (the endpoint answers `{authenticated:false}` rather than 401, so the public landing never
|
|
// logs a failed request to the console). React Query treats the null as data, not an error.
|
|
me: async (): Promise<Me | null> => {
|
|
// Always 200: `{ authenticated: false }` when logged out, else the full Me + `authenticated`.
|
|
const r = await req<{ authenticated: boolean } & Partial<Me>>("/api/me");
|
|
return r.authenticated ? (r as Me) : null;
|
|
},
|
|
accounts: (): Promise<Account[]> => req("/api/me/accounts"),
|
|
deleteAccount: (): Promise<{ deleted: boolean }> => req("/api/me/account", { method: "DELETE" }),
|
|
switchAccount: (userId: number): Promise<{ ok: boolean; user_id: number }> =>
|
|
req("/api/me/switch", { method: "POST", body: JSON.stringify({ user_id: userId }) }),
|
|
// Signs the current tab's active account out of the browser wallet (per-tab aware via the
|
|
// X-Siftlode-Account header that req() attaches).
|
|
logout: (): Promise<{ ok: boolean; switched: boolean }> =>
|
|
req("/auth/logout", { method: "POST" }),
|
|
version: (): Promise<VersionInfo> => req("/api/version"),
|
|
// Overwriting preferences is idempotent, so let it retry on a transient gateway blip.
|
|
savePrefs: (p: Record<string, unknown>) =>
|
|
req("/api/me/preferences", { method: "PUT", body: JSON.stringify(p) }, { idempotent: true }),
|
|
};
|