87 lines
3.4 KiB
Svelte
87 lines
3.4 KiB
Svelte
<script lang="ts">
|
|||
|
|
import { page } from '$app/state'
|
||
|
|
import { getAppConfig, getPanelForPath, getPathForPanel } from '$lib/app-config'
|
||
|
|
import AnalyzerWorkspace from '$lib/features/AnalyzerWorkspace.svelte'
|
||
|
|
import ConfigWorkspace from '$lib/features/ConfigWorkspace.svelte'
|
||
|
|
import DesktopWorkspace from '$lib/features/DesktopWorkspace.svelte'
|
||
|
|
import FeedWorkspace from '$lib/features/FeedWorkspace.svelte'
|
||
|
|
import KioskWorkspace from '$lib/features/KioskWorkspace.svelte'
|
||
|
|
import MediaTypePipeline from '$lib/features/MediaTypePipeline.svelte'
|
||
|
|
import ModeratorWorkspace from '$lib/features/ModeratorWorkspace.svelte'
|
||
|
|
import ServantWorkspace from '$lib/features/ServantWorkspace.svelte'
|
||
|
|
import TagsWorkspace from '$lib/features/TagsWorkspace.svelte'
|
||
|
|
import VideoPage from '$lib/features/VideoPage.svelte'
|
||
|
|
import ToolsWorkspace from '$lib/features/ToolsWorkspace.svelte'
|
||
|
|
import ViewerWorkspace from '$lib/features/ViewerWorkspace.svelte'
|
||
|
|
|
||
|
|
const analyzerMediaTypePanels: Record<
|
||
|
|
string,
|
||
|
|
{ mediaType: 'image' | 'video' | 'audio' | 'funscript'; label: string }
|
||
|
|
> = {
|
||
|
|
images: { mediaType: 'image', label: 'Images' },
|
||
|
|
videos: { mediaType: 'video', label: 'Videos' },
|
||
|
|
audios: { mediaType: 'audio', label: 'Audios' },
|
||
|
|
funscripts: { mediaType: 'funscript', label: 'Funscripts' },
|
||
|
|
}
|
||
|
|
|
||
|
|
const app = getAppConfig(__MEDIA_APP__)
|
||
|
|
const requestedPanel = $derived(page.url.searchParams.get('panel') || getPanelForPath(app, page.url.pathname))
|
||
|
|
const panel = $derived(app.id === 'viewer' && requestedPanel === 'search' ? 'library' : requestedPanel)
|
||
|
|
const videoId = $derived(app.id === 'viewer' ? getVideoId(page.url.pathname) : '')
|
||
|
|
|
||
|
|
function getVideoId(pathname: string) {
|
||
|
|
const match = pathname.match(/^\/video\/([^/]+)\/?$/i)
|
||
|
|
if (!match?.[1]) return ''
|
||
|
|
try {
|
||
|
|
return decodeURIComponent(match[1])
|
||
|
|
} catch {
|
||
|
|
return ''
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$effect(() => {
|
||
|
|
const legacyPanel = page.url.searchParams.get('panel')
|
||
|
|
if (typeof window === 'undefined' || !legacyPanel || !app.nav.some((item) => item.panel === legacyPanel)) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
const query = Array.from(page.url.searchParams.entries())
|
||
|
|
.filter(([key]) => key !== 'panel')
|
||
|
|
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
|
||
|
|
.join('&')
|
||
|
|
const target = `${getPathForPanel(app, legacyPanel)}${query ? `?${query}` : ''}`
|
||
|
|
const current = `${page.url.pathname}${page.url.search}`
|
||
|
|
if (target !== current) {
|
||
|
|
window.location.replace(target)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
</script>
|
||
|
|
|
||
|
|
{#if app.id === 'viewer' && videoId}
|
||
|
|
<VideoPage id={videoId} />
|
||
|
|
{:else if app.id === 'viewer' && panel === 'view'}
|
||
|
|
<FeedWorkspace />
|
||
|
|
{:else if app.id === 'viewer' && panel === 'tags'}
|
||
|
|
<TagsWorkspace />
|
||
|
|
{:else if app.id === 'viewer'}
|
||
|
|
<ViewerWorkspace {panel} />
|
||
|
|
{:else if app.id === 'analyzer' && panel in analyzerMediaTypePanels}
|
||
|
|
<MediaTypePipeline
|
||
|
|
mediaType={analyzerMediaTypePanels[panel].mediaType}
|
||
|
|
label={analyzerMediaTypePanels[panel].label}
|
||
|
|
/>
|
||
|
|
{:else if app.id === 'tools'}
|
||
|
|
<ToolsWorkspace {panel} />
|
||
|
|
{:else if app.id === 'analyzer'}
|
||
|
|
<AnalyzerWorkspace {panel} />
|
||
|
|
{:else if app.id === 'config'}
|
||
|
|
<ConfigWorkspace {panel} />
|
||
|
|
{:else if app.id === 'moderator'}
|
||
|
|
<ModeratorWorkspace {panel} />
|
||
|
|
{:else if app.id === 'kiosk'}
|
||
|
|
<KioskWorkspace {panel} />
|
||
|
|
{:else if app.id === 'servant'}
|
||
|
|
<ServantWorkspace {panel} />
|
||
|
|
{:else}
|
||
|
|
<DesktopWorkspace {panel} />
|
||
|
|
{/if}
|