feat(web): build the UI as a Next.js static export

In-app links move to /album?id=, /artist?id= and /playlist?id= so every
page can prerender. Server-only files use a .server.ts(x) suffix that
`pnpm build:export` leaves out: route handlers, the proxy, the desktop
server picker, and the /album/<id> share pages with link-preview metadata.
Exports use client-only Convex Auth and redirect in the browser.

Sign-up now checks the setting in the browser. The sign-in link always
shows, and a disabled server replaces the sign-up form with a notice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
joshuafhigginsandClaude Opus 5.5 committed 2026-11-20 00:15:10 -05:00 Verified
1 parent 2a77c92332
commit 3c1191a243
47 files changed
+343 -199

No files matched your search

@@ -1,3 +1,5 @@
// Share links (/album/<id>) land here on the server build, which adds
// link-preview metadata. The app itself links to /album?id=<id>.
import { AlbumPage } from "@/components/album-page"
import { api } from "@otunes/convex/_generated/api"
import { fetchQuery } from "convex/nextjs"
+19
View File
@@ -0,0 +1,19 @@
"use client"
import { useSearchParams } from "next/navigation"
import { AlbumPage } from "@/components/album-page"
import { PageMessage } from "@/components/page-message"
import type { Id } from "@otunes/convex/_generated/dataModel"
export default function Page() {
const searchParams = useSearchParams()
const id = searchParams.get("id")
if (!id) return <PageMessage>Album not found.</PageMessage>
return (
<AlbumPage
albumId={id as Id<"albums">}
highlightedSongId={searchParams.get("s") ?? undefined}
/>
)
}
@@ -1,3 +1,5 @@
// Share links (/artist/<id>) land here on the server build, which adds
// link-preview metadata. The app itself links to /artist?id=<id>.
import { fetchQuery } from "convex/nextjs"
import { convexServerOptions } from "@/lib/convex-server"
import { ArtistPage } from "@/components/artist-page"
+13
View File
@@ -0,0 +1,13 @@
"use client"
import { useSearchParams } from "next/navigation"
import { ArtistPage } from "@/components/artist-page"
import { PageMessage } from "@/components/page-message"
import type { Id } from "@otunes/convex/_generated/dataModel"
export default function Page() {
const id = useSearchParams().get("id")
if (!id) return <PageMessage>Artist not found.</PageMessage>
return <ArtistPage artistId={id as Id<"artists">} />
}
+4
View File
@@ -1,3 +1,4 @@
import { AuthRedirect } from "@/components/auth-redirect"
import { AddToPlaylistProvider } from "@/components/add-to-playlist-provider"
import { DownloadsProvider } from "@/components/downloads-provider"
import { FavoritesProvider } from "@/components/favorites-provider"
@@ -21,6 +22,9 @@ export default function AppLayout({
<AddToPlaylistProvider>
<DownloadsProvider>
<FavoritesProvider>
{process.env.OTUNES_STATIC_EXPORT === "1" && (
<AuthRedirect area="app" />
)}
<AppSidebar />
<div className="flex min-h-svh min-w-0 flex-1">
<SidebarInset className="min-w-0 flex-1">
@@ -1,40 +0,0 @@
import { fetchQuery } from "convex/nextjs"
import { convexServerOptions } from "@/lib/convex-server"
import { api } from "@otunes/convex/_generated/api"
import type { Id } from "@otunes/convex/_generated/dataModel"
import { Metadata } from "next"
interface PageProps {
params: Promise<{ id: string }>
}
export async function generateMetadata({
params,
}: PageProps): Promise<Metadata> {
const { id } = await params
const detail = await fetchQuery(
api.library.browseArtistDetail,
{ id: id as Id<"artists"> },
convexServerOptions()
).catch(() => null)
const selectedArtist = detail?.artist
return {
title: `${selectedArtist ? `${selectedArtist.name}` : "oTunes"}`,
openGraph: {
title: `${selectedArtist ? `${selectedArtist.name}` : "oTunes"}`,
description: "oTunes",
images: selectedArtist
? {
url: `/api/artist/${selectedArtist.id}/cover`,
width: 512,
height: 512,
}
: [],
},
}
}
export default function Page() {
return null
}
@@ -1,3 +1,5 @@
// Share links (/playlist/<id>) land here on the server build, which adds
// link-preview metadata. The app itself links to /playlist?id=<id>.
import { PlaylistPage } from "@/components/playlist-page"
import { api } from "@otunes/convex/_generated/api"
import { convexAuthNextjsToken } from "@convex-dev/auth/nextjs/server"
+13
View File
@@ -0,0 +1,13 @@
"use client"
import { useSearchParams } from "next/navigation"
import { PageMessage } from "@/components/page-message"
import { PlaylistPage } from "@/components/playlist-page"
import type { Id } from "@otunes/convex/_generated/dataModel"
export default function Page() {
const id = useSearchParams().get("id")
if (!id) return <PageMessage>Playlist not found.</PageMessage>
return <PlaylistPage playlistId={id as Id<"playlists">} />
}
+2
View File
@@ -1,3 +1,4 @@
import { AuthRedirect } from "@/components/auth-redirect"
export default function AuthLayout({
children,
}: Readonly<{
@@ -5,6 +6,7 @@ export default function AuthLayout({
}>) {
return (
<div className="flex min-h-svh flex-col items-center justify-center bg-muted/30 p-6">
{process.env.OTUNES_STATIC_EXPORT === "1" && <AuthRedirect area="auth" />}
{children}
</div>
)
+2 -15
View File
@@ -1,18 +1,5 @@
import { fetchQuery } from "convex/nextjs"
import { connection } from "next/server"
import { AuthForm } from "@/components/auth-form"
import { convexServerOptions } from "@/lib/convex-server"
import { api } from "@otunes/convex/_generated/api"
export default async function SignInPage() {
await connection()
const { disableAccountCreation } = await fetchQuery(
api.users.getAppSettings,
{},
convexServerOptions()
)
return (
<AuthForm flow="signIn" accountCreationDisabled={disableAccountCreation} />
)
export default function SignInPage() {
return <AuthForm flow="signIn" />
}
+24 -12
View File
@@ -1,18 +1,30 @@
import { fetchQuery } from "convex/nextjs"
import { connection } from "next/server"
"use client"
import { useQuery } from "convex/react"
import Link from "next/link"
import { AuthForm } from "@/components/auth-form"
import { convexServerOptions } from "@/lib/convex-server"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import { api } from "@otunes/convex/_generated/api"
export default async function SignUpPage() {
await connection()
const { disableAccountCreation } = await fetchQuery(
api.users.getAppSettings,
{},
convexServerOptions()
)
export default function SignUpPage() {
const settings = useQuery(api.users.getAppSettings)
// Render nothing until the setting loads so the form never flashes.
if (settings === undefined) return null
if (!settings.disableAccountCreation) return <AuthForm flow="signUp" />
return (
<AuthForm flow="signUp" accountCreationDisabled={disableAccountCreation} />
<Card className="w-full max-w-sm">
<CardHeader>
<CardTitle className="text-lg">
This server has disabled new signups :(
</CardTitle>
</CardHeader>
<CardContent>
<Button asChild className="w-full">
<Link href="/signin">Back</Link>
</Button>
</CardContent>
</Card>
)
}
File renamed without changes.
+6 -1
View File
@@ -37,8 +37,11 @@ async function hostedUrl() {
}
}
const staticExport = process.env.OTUNES_STATIC_EXPORT === "1"
export async function generateMetadata(): Promise<Metadata> {
const url = await hostedUrl()
// Static exports have no request to read the host from.
const url = staticExport ? undefined : await hostedUrl()
return {
title: "oTunes",
@@ -93,6 +96,8 @@ export default function RootLayout({
<body className={"overflow-x-hidden"}>
{needsServer ? (
content
) : staticExport ? (
<ConvexClientProvider>{content}</ConvexClientProvider>
) : (
<ConvexAuthNextjsServerProvider storageNamespace="otunes">
<ConvexClientProvider convexUrl={process.env.PUBLIC_CONVEX_URL}>
+2
View File
@@ -1,5 +1,7 @@
import type { MetadataRoute } from "next"
export const dynamic = "force-static"
export default function manifest(): MetadataRoute.Manifest {
return {
name: "oTunes",
@@ -1,5 +1,7 @@
"use client"
import { playlistPath } from "@/lib/routes"
import * as React from "react"
import { useConvex, useMutation, useQuery } from "convex/react"
import { useRouter } from "next/navigation"
@@ -256,7 +258,7 @@ export function AddToPlaylistProvider({
setNewPlaylistName("")
setPendingSongIds([])
if (count === 0) {
router.push(`/playlist/${playlistId}`)
router.push(playlistPath(playlistId))
}
} catch (error) {
toast.error(
+5 -3
View File
@@ -1,5 +1,7 @@
"use client"
import { albumPath, artistPath } from "@/lib/routes"
import * as React from "react"
import Image from "next/image"
import Link from "next/link"
@@ -123,7 +125,7 @@ export function AlbumCard({ album }: { album: BrowseAlbum }) {
onMouseEnter={() => setHovered(true)}
onMouseLeave={() => setHovered(false)}
>
<Link className="absolute inset-0" href={"/album/" + album.id}>
<Link className="absolute inset-0" href={albumPath(album.id)}>
<Image
src={albumCoverUrl(album.id)}
alt={album.title}
@@ -186,11 +188,11 @@ export function AlbumCard({ album }: { album: BrowseAlbum }) {
</div>
<div className="min-w-0">
<Link href={"/album/" + album.id} className="hover:underline">
<Link href={albumPath(album.id)} className="hover:underline">
<p className="truncate text-sm font-medium">{album.title}</p>
</Link>
<Link
href={"/artist/" + album.artist.id}
href={artistPath(album.artist.id)}
className="text-muted-foreground decoration-muted-foreground hover:underline"
>
<p className="truncate text-xs">{album.artist.name}</p>
+3 -1
View File
@@ -1,5 +1,7 @@
"use client"
import { artistPath } from "@/lib/routes"
import { PageHeader } from "@/components/library-skeletons"
import * as React from "react"
import Image from "next/image"
@@ -287,7 +289,7 @@ export function AlbumView({
{album.title}
</h1>
<Link
href={"/artist/" + album.artist.id}
href={artistPath(album.artist.id)}
className="inline-block text-lg font-semibold text-primary hover:underline"
>
{album.artist.name}
+62 -14
View File
@@ -1,5 +1,7 @@
"use client"
import { playlistPath } from "@/lib/routes"
import {
ArrowDownToLine,
Disc3,
@@ -14,7 +16,7 @@ import {
Star,
} from "lucide-react"
import { usePathname, useRouter } from "next/navigation"
import { usePathname, useRouter, useSearchParams } from "next/navigation"
import dynamic from "next/dynamic"
import { useAuthActions } from "@convex-dev/auth/react"
@@ -43,6 +45,7 @@ import Image from "next/image"
import Link from "next/link"
import { useTheme } from "next-themes"
import * as React from "react"
import { Suspense } from "react"
import { api } from "@otunes/convex/_generated/api"
import { playlistCoverUrl } from "@/lib/cover-urls"
import { useCachedQuery } from "@/hooks/use-cached-query"
@@ -109,7 +112,7 @@ export function AppSidebar() {
...(sidebarPlaylists?.subscribed ?? []),
].map((playlist) => ({
title: playlist.title,
path: `/playlist/${playlist.id}`,
path: playlistPath(playlist.id),
icon: playlist.cover ? (
// eslint-disable-next-line @next/next/no-img-element -- versioned cover, already sized by the route
<img
@@ -196,18 +199,20 @@ export function AppSidebar() {
<SidebarGroup>
<SidebarGroupLabel>Playlists</SidebarGroupLabel>
<SidebarGroupContent>
<SidebarMenu>
{playlistNav.map((item) => (
<SidebarMenuItem key={item.path}>
<SidebarMenuButton isActive={pathname === item.path} asChild>
<Link href={item.path} onClick={() => setOpenMobile(false)}>
{item.icon}
<span>{item.title}</span>
</Link>
</SidebarMenuButton>
</SidebarMenuItem>
))}
</SidebarMenu>
<Suspense
fallback={
<PlaylistMenu
items={playlistNav}
route={pathname}
onNavigate={() => setOpenMobile(false)}
/>
}
>
<CurrentPlaylistMenu
items={playlistNav}
onNavigate={() => setOpenMobile(false)}
/>
</Suspense>
</SidebarGroupContent>
</SidebarGroup>
</SidebarContent>
@@ -255,3 +260,46 @@ export function AppSidebar() {
</Sidebar>
)
}
type NavItem = { title: string; path: string; icon: React.ReactNode }
// Playlist routes differ only by `?id=`. Reading the query needs a Suspense
// boundary in static exports, so the fallback matches on the path alone.
function CurrentPlaylistMenu(props: {
items: NavItem[]
onNavigate: () => void
}) {
const pathname = usePathname()
const query = useSearchParams().toString()
return (
<PlaylistMenu
{...props}
route={query ? `${pathname}?${query}` : pathname}
/>
)
}
function PlaylistMenu({
items,
route,
onNavigate,
}: {
items: NavItem[]
route: string
onNavigate: () => void
}) {
return (
<SidebarMenu>
{items.map((item) => (
<SidebarMenuItem key={item.path}>
<SidebarMenuButton isActive={route === item.path} asChild>
<Link href={item.path} onClick={onNavigate}>
{item.icon}
<span>{item.title}</span>
</Link>
</SidebarMenuButton>
</SidebarMenuItem>
))}
</SidebarMenu>
)
}
+4 -2
View File
@@ -1,5 +1,7 @@
"use client"
import { artistPath } from "@/lib/routes"
import Image from "next/image"
import Link from "next/link"
@@ -11,7 +13,7 @@ export function ArtistCard({ artist }: { artist: BrowseArtist }) {
<div className="group flex flex-col items-center gap-2">
<Link
className="relative flex aspect-square w-full items-center justify-center overflow-hidden rounded-full ring-1 ring-foreground/10"
href={"/artist/" + artist.id}
href={artistPath(artist.id)}
>
<Image
src={artistCoverUrl(artist.id)}
@@ -22,7 +24,7 @@ export function ArtistCard({ artist }: { artist: BrowseArtist }) {
/>
</Link>
<div className="min-w-0">
<Link href={"/artist/" + artist.id} className="hover:underline">
<Link href={artistPath(artist.id)} className="hover:underline">
<p className="truncate text-center text-sm font-medium">
{artist.name}
</p>
+8 -11
View File
@@ -1,6 +1,6 @@
"use client"
import { usePathname } from "next/navigation"
import { useSearchParams } from "next/navigation"
import { useCallback } from "react"
import { ArtistsView } from "@/components/artists-view"
@@ -8,20 +8,17 @@ import { ArtistsSkeleton, PageHeader } from "@/components/library-skeletons"
import { useCachedQuery } from "@/hooks/use-cached-query"
import { api } from "@otunes/convex/_generated/api"
const ARTISTS_PATH = "/library/artists"
function artistIdFromPathname(pathname: string) {
const [, id] = pathname.slice(ARTISTS_PATH.length).split("/")
return id ? decodeURIComponent(id) : undefined
}
export function ArtistsPage() {
const pathname = usePathname()
const artistId = useSearchParams().get("id") ?? undefined
const artists = useCachedQuery(api.library.browseArtists)
const albums = useCachedQuery(api.library.browseAlbums)
const selectArtist = useCallback((artistId: string) => {
window.history.pushState(null, "", `${ARTISTS_PATH}/${artistId}`)
window.history.pushState(
null,
"",
`/library/artists?${new URLSearchParams({ id: artistId })}`
)
}, [])
return (
@@ -34,7 +31,7 @@ export function ArtistsPage() {
<ArtistsView
artists={artists.flat()}
albums={albums.flat()}
artistId={artistIdFromPathname(pathname)}
artistId={artistId}
onSelectArtist={selectArtist}
/>
)}
+3 -1
View File
@@ -1,5 +1,7 @@
"use client"
import { artistPath } from "@/lib/routes"
import * as React from "react"
import Image from "next/image"
import Link from "next/link"
@@ -155,7 +157,7 @@ export function ArtistsView({
<div className="pb-28">
<div className="flex min-w-0 items-center justify-between gap-4 border-b px-6 py-4">
<Link
href={`/artist/${selectedArtist.id}`}
href={artistPath(selectedArtist.id)}
className="group inline-flex min-w-0 flex-1 items-center gap-1 text-xl font-bold tracking-tight hover:underline"
>
<span className="min-w-0 truncate">{selectedArtist.name}</span>
+52 -72
View File
@@ -53,27 +53,16 @@ const copy: Record<
},
}
export function AuthForm({
flow,
accountCreationDisabled,
}: {
flow: AuthFlow
accountCreationDisabled: boolean
}) {
export function AuthForm({ flow }: { flow: AuthFlow }) {
const { signIn } = useAuthActions()
const router = useRouter()
const [error, setError] = useState<string | null>(null)
const [submitting, setSubmitting] = useState(false)
const text = copy[flow]
const signupsDisabled = flow === "signUp" && accountCreationDisabled
const hideSignUpLink = flow === "signIn" && accountCreationDisabled
async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault()
if (signupsDisabled) {
return
}
setError(null)
setSubmitting(true)
@@ -100,71 +89,62 @@ export function AuthForm({
<CardDescription>{text.description}</CardDescription>
</CardHeader>
<CardContent>
{signupsDisabled ? (
<p className="text-sm text-muted-foreground">
New account registration is currently disabled. Contact an
administrator if you need access.
</p>
) : (
<form onSubmit={handleSubmit}>
<FieldGroup>
{flow === "signUp" && (
<Field>
<FieldLabel htmlFor="name">Name</FieldLabel>
<Input
id="name"
name="name"
type="text"
autoComplete="name"
placeholder="Ada Lovelace"
required
/>
</Field>
)}
<form onSubmit={handleSubmit}>
<FieldGroup>
{flow === "signUp" && (
<Field>
<FieldLabel htmlFor="email">Email</FieldLabel>
<FieldLabel htmlFor="name">Name</FieldLabel>
<Input
id="email"
name="email"
type="email"
autoComplete="email"
placeholder="you@example.com"
id="name"
name="name"
type="text"
autoComplete="name"
placeholder="Ada Lovelace"
required
/>
</Field>
<Field>
<FieldLabel htmlFor="password">Password</FieldLabel>
<Input
id="password"
name="password"
type="password"
autoComplete={
flow === "signIn" ? "current-password" : "new-password"
}
required
/>
</Field>
{error && <FieldError>{error}</FieldError>}
<Field>
<Button type="submit" disabled={submitting}>
{submitting && <Spinner />}
{text.submit}
</Button>
</Field>
{!hideSignUpLink ? (
<p className="text-center text-sm text-muted-foreground">
{text.switchPrompt}{" "}
<Link
href={text.switchHref}
className="text-primary underline-offset-4 hover:underline"
>
{text.switchLabel}
</Link>
</p>
) : null}
</FieldGroup>
</form>
)}
)}
<Field>
<FieldLabel htmlFor="email">Email</FieldLabel>
<Input
id="email"
name="email"
type="email"
autoComplete="email"
placeholder="you@example.com"
required
/>
</Field>
<Field>
<FieldLabel htmlFor="password">Password</FieldLabel>
<Input
id="password"
name="password"
type="password"
autoComplete={
flow === "signIn" ? "current-password" : "new-password"
}
required
/>
</Field>
{error && <FieldError>{error}</FieldError>}
<Field>
<Button type="submit" disabled={submitting}>
{submitting && <Spinner />}
{text.submit}
</Button>
</Field>
<p className="text-center text-sm text-muted-foreground">
{text.switchPrompt}{" "}
<Link
href={text.switchHref}
className="text-primary underline-offset-4 hover:underline"
>
{text.switchLabel}
</Link>
</p>
</FieldGroup>
</form>
</CardContent>
</Card>
)
+27
View File
@@ -0,0 +1,27 @@
"use client"
import { useConvexAuth } from "convex/react"
import { usePathname, useRouter } from "next/navigation"
import { useEffect } from "react"
// Media pages that signed-out visitors can open from share links.
const PUBLIC_PATHS = new Set(["/album", "/artist", "/playlist"])
/**
* Static exports have no proxy, so this keeps signed-out users on the auth
* pages and signed-in users off them. Server builds redirect in proxy.server.ts.
*/
export function AuthRedirect({ area }: { area: "app" | "auth" }) {
const { isAuthenticated, isLoading } = useConvexAuth()
const pathname = usePathname()
const router = useRouter()
useEffect(() => {
if (isLoading) return
if (area === "auth" && isAuthenticated) router.replace("/")
if (area === "app" && !isAuthenticated && !PUBLIC_PATHS.has(pathname))
router.replace("/signin")
}, [area, isAuthenticated, isLoading, pathname, router])
return null
}
+12 -3
View File
@@ -1,6 +1,7 @@
"use client"
import { ConvexAuthNextjsProvider } from "@convex-dev/auth/nextjs"
import { ConvexAuthProvider } from "@convex-dev/auth/react"
import { buildConvexUrl } from "@otunes/convex/server-url"
import { ConvexReactClient } from "convex/react"
import { ReactNode } from "react"
@@ -37,9 +38,17 @@ export function ConvexClientProvider({
convexUrl?: string
children: ReactNode
}) {
return (
<ConvexAuthNextjsProvider client={getConvexClient(convexUrl)}>
<PersistentCacheProvider>{children}</PersistentCacheProvider>{" "}
const client = getConvexClient(convexUrl)
const content = <PersistentCacheProvider>{children}</PersistentCacheProvider>
// Static exports have no Next.js server to hold the session in cookies, so
// tokens live in localStorage, as in the mobile app.
return process.env.OTUNES_STATIC_EXPORT === "1" ? (
<ConvexAuthProvider client={client} storageNamespace="otunes">
{content}
</ConvexAuthProvider>
) : (
<ConvexAuthNextjsProvider client={client}>
{content}
</ConvexAuthNextjsProvider>
)
}
+4 -2
View File
@@ -1,5 +1,7 @@
"use client"
import { albumPath, artistPath } from "@/lib/routes"
import * as React from "react"
import Link from "next/link"
import {
@@ -165,7 +167,7 @@ export function MediaContextMenuItems({
<MediaMenuSeparator />
{artist ? (
<MediaMenuItem asChild className="justify-between">
<Link href={`/artist/${artist.id}`}>
<Link href={artistPath(artist.id)}>
Go to Artist
<MicVocal />
</Link>
@@ -173,7 +175,7 @@ export function MediaContextMenuItems({
) : null}
{album ? (
<MediaMenuItem asChild className="justify-between">
<Link href={`/album/${album.id}`}>
<Link href={albumPath(album.id)}>
Go to Album
<GalleryVerticalEnd />
</Link>
+8 -1
View File
@@ -5,7 +5,14 @@ import { ArrowUpRight } from "lucide-react"
export function OpenAppButton() {
function openApp() {
const link = new URL("otunes://open")
link.searchParams.set("url", window.location.href)
// The app understands share links (/album/<id>), not in-app /album?id=<id>.
const page = new URL(window.location.href)
const id = page.searchParams.get("id")
if (id && /^\/(album|artist|playlist)$/.test(page.pathname)) {
page.pathname += `/${encodeURIComponent(id)}`
page.searchParams.delete("id")
}
link.searchParams.set("url", page.href)
window.location.assign(link.href)
}
+4 -3
View File
@@ -1,3 +1,4 @@
import { albumPath, artistPath } from "@/lib/routes"
import Link from "next/link"
import type { BrowseSong } from "@otunes/convex/types"
@@ -24,7 +25,7 @@ export function PlaybackSongMeta({
)}
>
<Link
href={`/album/${song.album.id}`}
href={albumPath(song.album.id)}
className={cn(
"block truncate text-sm font-medium hover:underline",
inRange && "text-primary-foreground hover:text-primary-foreground/80",
@@ -40,7 +41,7 @@ export function PlaybackSongMeta({
)}
>
<Link
href={`/artist/${song.artist.id}`}
href={artistPath(song.artist.id)}
className={cn(
"hover:underline",
inRange
@@ -54,7 +55,7 @@ export function PlaybackSongMeta({
<>
<span aria-hidden="true"> — </span>
<Link
href={`/album/${song.album.id}`}
href={albumPath(song.album.id)}
className="hover:text-foreground hover:underline"
>
{song.album.title}
+5 -3
View File
@@ -1,5 +1,7 @@
"use client"
import { albumPath, artistPath } from "@/lib/routes"
import * as React from "react"
import Image from "next/image"
import Link from "next/link"
@@ -184,21 +186,21 @@ export function PlayerBar() {
</div>
<div className="min-w-0 flex-1">
<Link
href={`/album/${currentSong.album.id}`}
href={albumPath(currentSong.album.id)}
className="block truncate text-sm font-semibold hover:underline md:text-[13px] md:leading-4"
>
{currentSong.title}
</Link>
<p className="truncate text-xs">
<Link
href={`/artist/${currentSong.artist.id}`}
href={artistPath(currentSong.artist.id)}
className="hover:underline"
>
{currentSong.artist.name}
</Link>
<span aria-hidden> · </span>
<Link
href={`/album/${currentSong.album.id}`}
href={albumPath(currentSong.album.id)}
className="hover:underline"
>
{currentSong.album.title}
+4 -2
View File
@@ -1,5 +1,7 @@
"use client"
import { playlistPath } from "@/lib/routes"
import Image from "next/image"
import Link from "next/link"
@@ -79,7 +81,7 @@ export function PlaylistCard({ playlist }: { playlist: PlaylistSummary }) {
return (
<div className="flex flex-col gap-2">
<div className="group relative aspect-square overflow-hidden rounded-lg ring-1 ring-foreground/10">
<Link className="absolute inset-0" href={"/playlist/" + playlist.id}>
<Link className="absolute inset-0" href={playlistPath(playlist.id)}>
<Image
src={playlistCoverUrl(playlist.id, playlist.cover, 384)}
alt={playlist.title}
@@ -130,7 +132,7 @@ export function PlaylistCard({ playlist }: { playlist: PlaylistSummary }) {
</div>
<div className="min-w-0">
<Link href={"/playlist/" + playlist.id} className="hover:underline">
<Link href={playlistPath(playlist.id)} className="hover:underline">
<p className="truncate text-sm font-medium">{playlist.title}</p>
</Link>
<p className="truncate text-xs text-muted-foreground decoration-muted-foreground">
+5 -3
View File
@@ -2,6 +2,8 @@
import { useDownloads } from "@/components/downloads-provider"
import { useSongDownloadState } from "@/hooks/use-downloads"
import { albumPath, artistPath } from "@/lib/routes"
import Image from "next/image"
import Link from "next/link"
import { useAddToPlaylist } from "@/components/add-to-playlist-provider"
@@ -81,7 +83,7 @@ export function SearchSongItem({ song }: { song: SearchSong }) {
<MediaContextMenuArea menu={menu}>
<div className="group flex items-center gap-3 rounded-lg px-1 py-1.5 transition-colors hover:bg-muted/50">
<Link
href={`/album/${song.album.id}`}
href={albumPath(song.album.id)}
className="relative size-11 shrink-0 overflow-hidden rounded ring-1 ring-foreground/10"
>
<Image
@@ -94,11 +96,11 @@ export function SearchSongItem({ song }: { song: SearchSong }) {
</Link>
<div className="min-w-0 flex-1">
<Link href={`/album/${song.album.id}`} className="hover:underline">
<Link href={albumPath(song.album.id)} className="hover:underline">
<p className="truncate text-sm font-medium">{song.title}</p>
</Link>
<Link
href={`/artist/${song.artist.id}`}
href={artistPath(song.artist.id)}
className="text-muted-foreground hover:text-foreground hover:underline"
>
<p className="truncate text-sm">{song.artist.name}</p>
@@ -1,5 +1,7 @@
"use client"
import { albumPath, artistPath } from "@/lib/routes"
import Image from "next/image"
import Link from "next/link"
@@ -12,11 +14,11 @@ export type TopResult = SearchTopResultItem
function resultHref(result: TopResult) {
switch (result.kind) {
case "song":
return `/album/${result.item.album.id}`
return albumPath(result.item.album.id)
case "album":
return `/album/${result.item.id}`
return albumPath(result.item.id)
case "artist":
return `/artist/${result.item.id}`
return artistPath(result.item.id)
}
}
+4 -2
View File
@@ -1,5 +1,7 @@
"use client"
import { albumPath, artistPath } from "@/lib/routes"
import * as React from "react"
import Image from "next/image"
import Link from "next/link"
@@ -398,7 +400,7 @@ function TrackRowComponent({
</div>
<div className={LIBRARY_COLUMN}>
<Link
href={"/artist/" + song.artist.id}
href={artistPath(song.artist.id)}
className={linkClass}
onClick={(event) => event.stopPropagation()}
>
@@ -407,7 +409,7 @@ function TrackRowComponent({
</div>
<div className={LIBRARY_COLUMN}>
<Link
href={"/album/" + song.album.id}
href={albumPath(song.album.id)}
className={linkClass}
onClick={(event) => event.stopPropagation()}
>
+17
View File
@@ -0,0 +1,17 @@
// In-app routes pass ids as query parameters so the UI can be a static export.
// Share links keep the `/album/<id>` form (see mediaShareUrl), which only the
// server build serves, with link-preview metadata.
export function albumPath(albumId: string, songId?: string) {
const query = new URLSearchParams({ id: albumId })
if (songId) query.set("s", songId)
return `/album?${query}`
}
export function artistPath(artistId: string) {
return `/artist?${new URLSearchParams({ id: artistId })}`
}
export function playlistPath(playlistId: string) {
return `/playlist?${new URLSearchParams({ id: playlistId })}`
}
+13 -3
View File
@@ -1,9 +1,19 @@
import path from "node:path"
import type { NextConfig } from "next"
const desktop = process.env.OTUNES_DESKTOP_BUILD === "1"
// `pnpm build:export` writes the UI as static files to `out`. It leaves out
// server-only files (`*.server.ts[x]`): route handlers, the proxy, share-link
// metadata pages and the desktop server picker.
const staticExport = process.env.OTUNES_STATIC_EXPORT === "1"
const nextConfig: NextConfig = {
output: "standalone",
distDir: process.env.OTUNES_DESKTOP_BUILD === "1" ? ".next-desktop" : ".next",
output: staticExport ? "export" : "standalone",
distDir: staticExport ? "out" : desktop ? ".next-desktop" : ".next",
pageExtensions: staticExport
? ["tsx", "ts"]
: ["server.tsx", "server.ts", "tsx", "ts"],
env: { OTUNES_STATIC_EXPORT: staticExport ? "1" : "" },
outputFileTracingRoot: path.join(__dirname, "../../"),
experimental: {
// Failed navigations wait for the connection instead of reloading the
@@ -16,7 +26,7 @@ const nextConfig: NextConfig = {
},
},
images: {
unoptimized: process.env.OTUNES_DESKTOP_BUILD === "1",
unoptimized: desktop || staticExport,
minimumCacheTTL: 60,
dangerouslyAllowSVG: true,
contentDispositionType: "attachment",
+1
View File
@@ -5,6 +5,7 @@
"scripts": {
"dev": "next dev",
"build": "next build",
"build:export": "OTUNES_STATIC_EXPORT=1 next build",
"start": "next start",
"lint": "eslint .",
"typecheck": "tsc --noEmit"
@@ -17,9 +17,11 @@ const isPublic = createRouteMatcher([
"/api/playlist/:id/cover",
// Mobile clients load avatars without the web auth cookie.
"/api/user/:id/avatar",
"/album",
"/album/:id",
"/artist",
"/artist/:id",
"/library/artists/:id",
"/playlist",
"/playlist/:id",
])