From 677e5c439b35a2c7b9306d3e45ca5c3b6b3812a9 Mon Sep 17 00:00:00 2001 From: TheGeneralist <180094941+thegeneralist01@users.noreply.github.com> Date: Fri, 26 Jun 2026 17:17:40 +0200 Subject: [PATCH] =?UTF-8?q?feat(settings):=20frontend=20=E2=80=94=20api.js?= =?UTF-8?q?=20helpers=20for=20profile,=20tokens,=20and=20instance=20settin?= =?UTF-8?q?gs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/api.js | 56 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/frontend/src/api.js b/frontend/src/api.js index aa5695a..334fbf6 100644 --- a/frontend/src/api.js +++ b/frontend/src/api.js @@ -112,6 +112,62 @@ export async function fetchMe() { return r.json(); } +// ── Profile & settings helpers ─────────────────────────────────────────────── + +export async function updateProfile(displayName) { + const res = await fetch('/api/auth/me', { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ display_name: displayName }), + }); + if (!res.ok) throw new Error(await res.text()); +} + +export async function changePassword(currentPassword, newPassword) { + const res = await fetch('/api/auth/me', { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ current_password: currentPassword, new_password: newPassword }), + }); + if (!res.ok) { + let msg = await res.text(); + try { msg = JSON.parse(msg).error ?? msg; } catch {} + throw new Error(msg); + } +} + +export async function listTokens() { + return getJson('/api/auth/tokens'); +} + +export async function createToken(name) { + const res = await fetch('/api/auth/tokens', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ name }), + }); + if (!res.ok) throw new Error(await res.text()); + return res.json(); +} + +export async function deleteToken(tokenUid) { + const res = await fetch(`/api/auth/tokens/${tokenUid}`, { method: 'DELETE' }); + if (!res.ok) throw new Error(await res.text()); +} + +export async function getInstanceSettings() { + return getJson('/api/admin/instance-settings'); +} + +export async function updateInstanceSettings(patch) { + const res = await fetch('/api/admin/instance-settings', { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(patch), + }); + if (!res.ok) throw new Error(await res.text()); +} + // ── Admin helpers ───────────────────────────────────────────────────────────── export async function listAdminUsers() {