Extracts a new backend/authproxy package for the AuthGuard-proxy helper
functions (session cookie handling, input normalization, error
translation) that Bitmagnet/GameStream/media-backend/AutoCode/
CollabTable/PubliSafe/SimpleCollection/SyncServer/UnraidMonitor/
OutdoorGames were each independently reimplementing, and repoints all
of them onto it.
Extends packages/web-ui's Button/Badge with the variants media-webui
needed (outline, icon size, primary badge) and promotes EmptyState/
SectionTitle/Metric/StatusWidget/StatusDialog into the shared library,
then migrates media-webui off its own diverged ui/{button,card,badge,
metric} components and local duplicates of the promoted components
onto @gabriel20xx/web-ui, so media-webui is a proper consumer of the
same design system every other project already uses instead of a
parallel fork.
Also removes the dead `desktop`/MediaDesktop service variant from
media-backend and media-webui (MediaDesktop is an Electron client that
never actually runs this stack).
114 lines
3.8 KiB
Svelte
114 lines
3.8 KiB
Svelte
<script lang="ts">
|
|
import { page } from '$app/state'
|
|
import { Film, Music2, Play } from '@lucide/svelte'
|
|
import { get } from '$lib/api'
|
|
import { Badge, Button, Card, EmptyState } from '@gabriel20xx/web-ui'
|
|
|
|
interface FeedItem {
|
|
mediaKey?: string
|
|
url?: string
|
|
thumbnail?: string
|
|
name?: string
|
|
filename?: string
|
|
mediaType?: string
|
|
title?: string | null
|
|
category?: string | null
|
|
}
|
|
|
|
let item = $state<FeedItem | null>(null)
|
|
let loading = $state(true)
|
|
let error = $state('')
|
|
let reloadToken = $state(0)
|
|
let loadSequence = 0
|
|
|
|
const exactMedia = $derived(page.url.searchParams.get('video')?.trim() || '')
|
|
|
|
async function loadFeed(exact: string) {
|
|
const sequence = ++loadSequence
|
|
loading = true
|
|
error = ''
|
|
|
|
try {
|
|
const query = exact ? `?exact=${encodeURIComponent(exact)}` : ''
|
|
const response = await get<{ data?: FeedItem }>(`/api/media/random/all${query}`)
|
|
if (sequence !== loadSequence) return
|
|
item = response.data || null
|
|
if (!item) error = 'No media found.'
|
|
} catch (reason) {
|
|
if (sequence !== loadSequence) return
|
|
item = null
|
|
error = reason instanceof Error ? reason.message : 'Unable to load the media feed.'
|
|
} finally {
|
|
if (sequence === loadSequence) loading = false
|
|
}
|
|
}
|
|
|
|
$effect(() => {
|
|
const exact = exactMedia
|
|
const token = reloadToken
|
|
void token
|
|
void loadFeed(exact)
|
|
})
|
|
|
|
function nextItem() {
|
|
if (exactMedia) window.location.href = '/feed'
|
|
else reloadToken += 1
|
|
}
|
|
|
|
function isImage(media: FeedItem) {
|
|
return media.mediaType === 'static' || media.mediaType === 'image'
|
|
}
|
|
</script>
|
|
|
|
<div>
|
|
{#if loading}
|
|
<div class="media-shimmer mx-auto h-[min(70dvh,48rem)] max-w-4xl rounded-xl border border-border"></div>
|
|
{:else if error}
|
|
<div class="rounded-md border border-danger/30 bg-danger/10 px-4 py-3 text-sm text-danger">{error}</div>
|
|
{:else if !item}
|
|
<EmptyState title="No media found" message="The feed will appear once media has been indexed." />
|
|
{:else}
|
|
<Card class="mx-auto max-w-4xl overflow-hidden p-0">
|
|
<div class="relative flex min-h-[min(70dvh,48rem)] items-center justify-center overflow-hidden bg-black">
|
|
{#if isImage(item)}
|
|
<img
|
|
src={item.url || item.thumbnail || ''}
|
|
alt={item.title || item.name || item.filename || 'Media'}
|
|
class="max-h-[min(70dvh,48rem)] max-w-full object-contain"
|
|
/>
|
|
{:else if item.url}
|
|
<video
|
|
src={item.url}
|
|
poster={item.thumbnail}
|
|
controls
|
|
autoplay
|
|
playsinline
|
|
class="max-h-[min(70dvh,48rem)] max-w-full object-contain"
|
|
>
|
|
<track kind="captions" srclang="en" label="Captions" src="data:text/vtt,WEBVTT" />
|
|
</video>
|
|
{:else}
|
|
<div class="flex flex-col items-center gap-3 text-muted-fg">
|
|
{#if item.mediaType === 'audio'}<Music2 class="size-12" />{:else}<Film class="size-12" />{/if}
|
|
<span>Preview unavailable</span>
|
|
</div>
|
|
{/if}
|
|
</div>
|
|
|
|
<div class="flex flex-col gap-3 border-t border-border p-4 sm:flex-row sm:items-center sm:justify-between">
|
|
<div class="min-w-0">
|
|
<p class="truncate text-sm font-medium text-fg">
|
|
{item.title || item.name || item.filename || 'Untitled media'}
|
|
</p>
|
|
<div class="mt-1 flex flex-wrap items-center gap-2 text-xs text-muted-fg">
|
|
{#if item.mediaType}<Badge>{item.mediaType}</Badge>{/if}
|
|
{#if item.category}<span>{item.category}</span>{/if}
|
|
{#if item.filename}<span class="truncate">{item.filename}</span>{/if}
|
|
</div>
|
|
</div>
|
|
<Button size="sm" onclick={() => void nextItem()} disabled={loading}><Play />Next item</Button>
|
|
</div>
|
|
</Card>
|
|
{/if}
|
|
</div>
|