Fold MediaEngine (media-backend, media-webui) into this repo
Per owner decision: MediaEngine (the Media product family's Go backend and SvelteKit frontend, previously its own repo referenced by 7 thin service repos via git submodule) is folded directly into shared/ as media-backend/ and media-webui/, rather than staying separate. media-backend/go.mod's replace directive now points at ../backend (a true sibling within this repo) instead of a vendored ../shared/backend copy, since there's no more nested vendoring - it's the real thing. Also moved MediaEngine's own CI (media-backend-lint.yml, media-backend-tests.yml) and dev tooling scripts (scripts/media/*, audit/lint/enforce scripts for the media-backend+media-webui content), fixing their path assumptions for the new layout, and dropped scripts/media/sync-shared.mjs (confirmed dead code, and now doubly obsolete since there's no more vendored shared/ subfolder for it to check). Added media:* script aliases to package.json for the moved tooling, namespaced to avoid colliding with this repo's own scripts. Also fixed sync-consumers.ps1's workspace-root resolution to walk up until it finds a directory containing both Original/ and Forks/, instead of assuming shared/ is always a direct child of the workspace root - it broke when shared/ moved from Web/shared to Web/Central/shared earlier in this same restructuring. Removed the now-obsolete Original/MediaEngine entry from its consumer list. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
79d9461769
commit
acde180086
99 files changed
+20488
-1
No files matched your search
@@ -0,0 +1,292 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/state'
|
||||
import { onMount } from 'svelte'
|
||||
import AuthPage from '$lib/components/AuthPage.svelte'
|
||||
import ProjectIcon from '$lib/components/ProjectIcon.svelte'
|
||||
import AboutWorkspace from '$lib/features/AboutWorkspace.svelte'
|
||||
import { AboutDialog, AdminDialog, Header, NotificationStack, PageHeader, ProfileDialog } from '@gabriel20xx/web-ui'
|
||||
import type {
|
||||
AuthLoginInput,
|
||||
AuthSetupInput,
|
||||
ManagedUser,
|
||||
ProfileUpdateInput,
|
||||
UserCreateInput,
|
||||
UserId,
|
||||
UserRole,
|
||||
UserUpdateInput,
|
||||
} from '@gabriel20xx/web-ui'
|
||||
import SettingsDialog from '$lib/components/SettingsDialog.svelte'
|
||||
import { getPanelForPath } from '$lib/app-config'
|
||||
import { pageActions } from '$lib/stores/page-actions.svelte'
|
||||
import { del, get, post, put } from '$lib/api'
|
||||
import '$lib/language.svelte'
|
||||
import type { AppConfig, AuthState, AuthUser } from '$lib/types'
|
||||
import type { Snippet } from 'svelte'
|
||||
|
||||
let { app, children }: { app: AppConfig; children: Snippet } = $props()
|
||||
|
||||
let auth = $state<AuthState>({
|
||||
user: null,
|
||||
authRequired: true,
|
||||
setupRequired: true,
|
||||
loading: true,
|
||||
error: null,
|
||||
})
|
||||
let settingsOpen = $state(false)
|
||||
let aboutOpen = $state(false)
|
||||
let profileOpen = $state(false)
|
||||
let adminOpen = $state(false)
|
||||
|
||||
// Header only renders its profile/settings menu when username is truthy - with login not
|
||||
// required and nobody signed in, auth.user is legitimately null (there's no session to read
|
||||
// it from), which silently hid Settings (and with it, the only UI path back to re-enabling
|
||||
// login) behind a button that never appeared. Falls back to a placeholder identity in that
|
||||
// one case so the menu - and Settings - stays reachable.
|
||||
const displayName = $derived(auth.user?.username || auth.user?.email || (auth.authRequired ? '' : 'Admin'))
|
||||
const homePath = $derived(app.nav[0]?.path || '/')
|
||||
const navItems = $derived(
|
||||
app.nav.map((item) => ({
|
||||
href: item.path,
|
||||
label: item.label,
|
||||
icon: item.icon,
|
||||
description: item.description,
|
||||
})),
|
||||
)
|
||||
const activeNavItem = $derived(
|
||||
app.nav.find((item) => item.panel === getPanelForPath(app, page.url.pathname)) || app.nav[0],
|
||||
)
|
||||
const currentRole = $derived<UserRole>(
|
||||
auth.user?.role === 'superadmin' || auth.user?.role === 'admin' ? auth.user.role : 'user',
|
||||
)
|
||||
const currentUserId = $derived<UserId | undefined>(auth.user?.id)
|
||||
const isAdmin = $derived(currentRole === 'admin' || currentRole === 'superadmin')
|
||||
|
||||
function openSettings() {
|
||||
settingsOpen = true
|
||||
}
|
||||
|
||||
function openAbout() {
|
||||
aboutOpen = true
|
||||
}
|
||||
|
||||
function openProfile() {
|
||||
profileOpen = true
|
||||
}
|
||||
|
||||
function openAdmin() {
|
||||
adminOpen = true
|
||||
}
|
||||
|
||||
function closeSettings() {
|
||||
settingsOpen = false
|
||||
if (page.url.pathname === '/settings') void goto(homePath)
|
||||
}
|
||||
|
||||
function closeAbout() {
|
||||
aboutOpen = false
|
||||
if (page.url.pathname === '/about') void goto(homePath)
|
||||
}
|
||||
|
||||
function currentPageToken() {
|
||||
if (typeof window === 'undefined') return '/'
|
||||
return `${window.location.pathname}${window.location.search}` || '/'
|
||||
}
|
||||
|
||||
async function loadAuth() {
|
||||
try {
|
||||
const data = await get<{ user: AuthUser | null; authRequired?: boolean }>(
|
||||
`/auth/me?page=${encodeURIComponent(currentPageToken())}`,
|
||||
)
|
||||
let setupRequired = false
|
||||
try {
|
||||
const bootstrap = await get<{ adminNeeded?: boolean }>('/auth/bootstrap/admin-needed')
|
||||
setupRequired = bootstrap.adminNeeded === true
|
||||
} catch {
|
||||
// The auth status remains usable if the optional bootstrap check is unavailable.
|
||||
}
|
||||
auth = {
|
||||
user: data.user || null,
|
||||
authRequired: data.authRequired !== false,
|
||||
setupRequired,
|
||||
loading: false,
|
||||
error: null,
|
||||
}
|
||||
} catch (error) {
|
||||
auth = {
|
||||
...auth,
|
||||
loading: false,
|
||||
error: error instanceof Error ? error.message : 'Unable to load authentication state.',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function login(input: AuthLoginInput) {
|
||||
const data = await post<{ user: AuthUser }>('/auth/login', {
|
||||
identifier: input.identifier,
|
||||
password: input.password,
|
||||
totpToken: input.totpToken,
|
||||
})
|
||||
auth = { ...auth, user: data.user, setupRequired: false, loading: false, error: null }
|
||||
}
|
||||
|
||||
async function setup(input: AuthSetupInput) {
|
||||
const data = await post<{ user: AuthUser }>('/auth/signup', {
|
||||
email: input.email,
|
||||
username: input.username,
|
||||
password: input.password,
|
||||
})
|
||||
auth = { ...auth, user: data.user, setupRequired: false, loading: false, error: null }
|
||||
}
|
||||
|
||||
const requestReset = () => post('/auth/reset/request')
|
||||
|
||||
async function confirmReset(code: string) {
|
||||
await post('/auth/reset/confirm', { code })
|
||||
window.location.reload()
|
||||
}
|
||||
|
||||
async function logout() {
|
||||
try {
|
||||
await post('/auth/logout')
|
||||
auth.user = null
|
||||
} catch (error) {
|
||||
auth.error = error instanceof Error ? error.message : 'Logout failed.'
|
||||
}
|
||||
}
|
||||
|
||||
async function updateProfile(input: ProfileUpdateInput) {
|
||||
const data = await put<{ user: AuthUser }>('/auth/me', input)
|
||||
auth = { ...auth, user: data.user, error: null }
|
||||
}
|
||||
|
||||
async function listUsers(): Promise<ManagedUser[]> {
|
||||
return get<ManagedUser[]>('/api/auth/users')
|
||||
}
|
||||
|
||||
async function createUser(input: UserCreateInput): Promise<void | ManagedUser> {
|
||||
return post<ManagedUser>('/api/auth/users', input)
|
||||
}
|
||||
|
||||
async function updateUser(id: UserId, input: UserUpdateInput): Promise<void | ManagedUser> {
|
||||
return put<ManagedUser>(`/api/auth/users/${encodeURIComponent(String(id))}`, input)
|
||||
}
|
||||
|
||||
async function deleteUser(id: UserId): Promise<void> {
|
||||
await del<{ ok: boolean }>(`/api/auth/users/${encodeURIComponent(String(id))}`)
|
||||
}
|
||||
|
||||
async function updateLoginRequired(loginRequired: boolean) {
|
||||
await put<{ loginRequired: boolean }>('/api/auth/access', { loginRequired })
|
||||
auth = { ...auth, authRequired: loginRequired }
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
void loadAuth()
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
if (page.url.pathname === '/settings') settingsOpen = true
|
||||
if (page.url.pathname === '/about') aboutOpen = true
|
||||
})
|
||||
</script>
|
||||
|
||||
{#if auth.loading || auth.error || auth.setupRequired || (auth.authRequired && !auth.user)}
|
||||
<AuthPage
|
||||
{app}
|
||||
setupRequired={auth.setupRequired}
|
||||
loading={auth.loading}
|
||||
error={auth.error || ''}
|
||||
onLogin={login}
|
||||
onSetup={setup}
|
||||
onRequestReset={requestReset}
|
||||
onConfirmReset={confirmReset}
|
||||
/>
|
||||
{:else}
|
||||
<div class="sc-root sc-app-shell min-h-screen bg-bg text-fg mediacollection-shell">
|
||||
<NotificationStack />
|
||||
|
||||
<Header
|
||||
brand={app.name}
|
||||
brandHref={homePath}
|
||||
currentPath={page.url.pathname}
|
||||
faviconHref="/favicon.svg"
|
||||
{navItems}
|
||||
onAbout={openAbout}
|
||||
onAdmin={isAdmin ? openAdmin : undefined}
|
||||
onLogout={logout}
|
||||
onProfile={openProfile}
|
||||
onSettings={openSettings}
|
||||
username={displayName}
|
||||
/>
|
||||
|
||||
<main class="mx-auto w-full max-w-7xl px-4 pt-4 pb-8">
|
||||
<PageHeader
|
||||
title={activeNavItem?.label || app.name}
|
||||
description={activeNavItem?.description || app.description}
|
||||
actions={pageActions.snippet ?? undefined}
|
||||
/>
|
||||
{@render children?.()}
|
||||
</main>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<SettingsDialog bind:open={settingsOpen} onClose={closeSettings} />
|
||||
<AdminDialog
|
||||
bind:open={adminOpen}
|
||||
{currentRole}
|
||||
{currentUserId}
|
||||
onListUsers={listUsers}
|
||||
onCreateUser={createUser}
|
||||
onUpdateUser={updateUser}
|
||||
onDeleteUser={deleteUser}
|
||||
loginRequired={auth.authRequired}
|
||||
onLoginRequiredChange={updateLoginRequired}
|
||||
/>
|
||||
<AboutDialog bind:open={aboutOpen} brand={app.name} description={app.description} onClose={closeAbout}>
|
||||
{#snippet icon()}
|
||||
<ProjectIcon icon={app.icon} class="size-8 text-primary" />
|
||||
{/snippet}
|
||||
<AboutWorkspace />
|
||||
</AboutDialog>
|
||||
<ProfileDialog
|
||||
bind:open={profileOpen}
|
||||
currentEmail={auth.user?.email || ''}
|
||||
currentUsername={auth.user?.username || ''}
|
||||
onSave={updateProfile}
|
||||
/>
|
||||
|
||||
<style>
|
||||
/* The shared component library (header, page title box, dialogs, buttons, ...) otherwise
|
||||
renders in its own generic default palette instead of this app's own branding - remap its
|
||||
--sc-* tokens onto this app's own --color-* palette so every shared component follows suit.
|
||||
--sc-secondary is a subtle tinted-surface color for low-emphasis buttons, a different role
|
||||
than this app's own saturated --color-secondary, so it's derived instead of mapped directly. */
|
||||
:global(.mediacollection-shell) {
|
||||
--sc-bg: var(--color-bg);
|
||||
--sc-surface: var(--color-surface);
|
||||
--sc-surface-raised: var(--color-surface);
|
||||
--sc-surface-hover: var(--color-surface-hover);
|
||||
--sc-border: var(--color-border);
|
||||
--sc-border-strong: var(--color-border);
|
||||
--sc-fg: var(--color-fg);
|
||||
--sc-muted-fg: var(--color-muted-fg);
|
||||
--sc-subtle-fg: var(--color-muted-fg);
|
||||
--sc-primary: var(--color-primary);
|
||||
--sc-primary-hover: var(--color-secondary);
|
||||
--sc-primary-fg: var(--color-primary-fg);
|
||||
--sc-secondary: color-mix(in srgb, var(--color-primary) 12%, var(--color-surface));
|
||||
--sc-secondary-hover: color-mix(in srgb, var(--color-primary) 20%, var(--color-surface));
|
||||
--sc-secondary-fg: var(--color-fg);
|
||||
--sc-accent: var(--color-accent);
|
||||
--sc-accent-fg: var(--color-accent-fg);
|
||||
--sc-danger: var(--color-danger);
|
||||
--sc-danger-hover: color-mix(in srgb, var(--color-danger) 90%, black);
|
||||
--sc-danger-fg: var(--color-danger-fg);
|
||||
--sc-success: var(--color-success);
|
||||
--sc-success-fg: var(--color-success-fg);
|
||||
--sc-warning: var(--color-warning);
|
||||
--sc-warning-fg: var(--color-warning-fg);
|
||||
--sc-ring: var(--color-ring);
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user