From 3c1191a2437f7c3adc7f3c03e8b11a4987d19b35 Mon Sep 17 00:00:00 2001 From: Joshua Higgins Date: Thu, 19 Nov 2026 12:53:33 -0500 Subject: [PATCH] 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/ 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 --- .../{page.tsx => page.server.tsx} | 0 .../album/[id]/{page.tsx => page.server.tsx} | 2 + .../app/(app)/album/{[id] => }/loading.tsx | 0 apps/web/app/(app)/album/page.tsx | 19 +++ .../artist/[id]/{page.tsx => page.server.tsx} | 2 + .../app/(app)/artist/{[id] => }/loading.tsx | 0 apps/web/app/(app)/artist/page.tsx | 13 ++ apps/web/app/(app)/layout.tsx | 4 + .../app/(app)/library/artists/[id]/page.tsx | 40 ------ .../[id]/{page.tsx => page.server.tsx} | 2 + .../app/(app)/playlist/{[id] => }/loading.tsx | 0 apps/web/app/(app)/playlist/page.tsx | 13 ++ apps/web/app/(auth)/layout.tsx | 2 + apps/web/app/(auth)/signin/page.tsx | 17 +-- apps/web/app/(auth)/signup/page.tsx | 36 +++-- .../[id]/cover/{route.ts => route.server.ts} | 0 .../[id]/cover/{route.ts => route.server.ts} | 0 .../[id]/cover/{route.ts => route.server.ts} | 0 .../play/hls/{route.ts => route.server.ts} | 0 .../[segment]/{route.ts => route.server.ts} | 0 .../[id]/play/{route.ts => route.server.ts} | 0 .../[id]/avatar/{route.ts => route.server.ts} | 0 .../app/desktop/{page.tsx => page.server.tsx} | 0 apps/web/app/layout.tsx | 7 +- apps/web/app/manifest.ts | 2 + .../components/add-to-playlist-provider.tsx | 4 +- apps/web/components/album-card.tsx | 8 +- apps/web/components/album-view.tsx | 4 +- apps/web/components/app-sidebar.tsx | 76 +++++++++-- apps/web/components/artist-card.tsx | 6 +- apps/web/components/artists-page.tsx | 19 ++- apps/web/components/artists-view.tsx | 4 +- apps/web/components/auth-form.tsx | 124 ++++++++---------- apps/web/components/auth-redirect.tsx | 27 ++++ .../web/components/convex-client-provider.tsx | 15 ++- apps/web/components/media-context-menu.tsx | 6 +- apps/web/components/open-app-button.tsx | 9 +- apps/web/components/playback-song-meta.tsx | 7 +- apps/web/components/player-bar.tsx | 8 +- apps/web/components/playlist-card.tsx | 6 +- apps/web/components/search-song-item.tsx | 8 +- .../web/components/search-top-result-card.tsx | 8 +- apps/web/components/track-row.tsx | 6 +- apps/web/lib/routes.ts | 17 +++ apps/web/next.config.ts | 16 ++- apps/web/package.json | 1 + apps/web/{proxy.ts => proxy.server.ts} | 4 +- 47 files changed, 343 insertions(+), 199 deletions(-) rename apps/web/app/(app)/[...not-found]/{page.tsx => page.server.tsx} (100%) rename apps/web/app/(app)/album/[id]/{page.tsx => page.server.tsx} (92%) rename apps/web/app/(app)/album/{[id] => }/loading.tsx (100%) create mode 100644 apps/web/app/(app)/album/page.tsx rename apps/web/app/(app)/artist/[id]/{page.tsx => page.server.tsx} (89%) rename apps/web/app/(app)/artist/{[id] => }/loading.tsx (100%) create mode 100644 apps/web/app/(app)/artist/page.tsx delete mode 100644 apps/web/app/(app)/library/artists/[id]/page.tsx rename apps/web/app/(app)/playlist/[id]/{page.tsx => page.server.tsx} (90%) rename apps/web/app/(app)/playlist/{[id] => }/loading.tsx (100%) create mode 100644 apps/web/app/(app)/playlist/page.tsx rename apps/web/app/api/album/[id]/cover/{route.ts => route.server.ts} (100%) rename apps/web/app/api/artist/[id]/cover/{route.ts => route.server.ts} (100%) rename apps/web/app/api/playlist/[id]/cover/{route.ts => route.server.ts} (100%) rename apps/web/app/api/song/[id]/play/hls/{route.ts => route.server.ts} (100%) rename apps/web/app/api/song/[id]/play/hls/segment/[segment]/{route.ts => route.server.ts} (100%) rename apps/web/app/api/song/[id]/play/{route.ts => route.server.ts} (100%) rename apps/web/app/api/user/[id]/avatar/{route.ts => route.server.ts} (100%) rename apps/web/app/desktop/{page.tsx => page.server.tsx} (100%) create mode 100644 apps/web/components/auth-redirect.tsx create mode 100644 apps/web/lib/routes.ts rename apps/web/{proxy.ts => proxy.server.ts} (97%) diff --git a/apps/web/app/(app)/[...not-found]/page.tsx b/apps/web/app/(app)/[...not-found]/page.server.tsx similarity index 100% rename from apps/web/app/(app)/[...not-found]/page.tsx rename to apps/web/app/(app)/[...not-found]/page.server.tsx diff --git a/apps/web/app/(app)/album/[id]/page.tsx b/apps/web/app/(app)/album/[id]/page.server.tsx similarity index 92% rename from apps/web/app/(app)/album/[id]/page.tsx rename to apps/web/app/(app)/album/[id]/page.server.tsx index 95fef40..918c48d 100644 --- a/apps/web/app/(app)/album/[id]/page.tsx +++ b/apps/web/app/(app)/album/[id]/page.server.tsx @@ -1,3 +1,5 @@ +// Share links (/album/) land here on the server build, which adds +// link-preview metadata. The app itself links to /album?id=. import { AlbumPage } from "@/components/album-page" import { api } from "@otunes/convex/_generated/api" import { fetchQuery } from "convex/nextjs" diff --git a/apps/web/app/(app)/album/[id]/loading.tsx b/apps/web/app/(app)/album/loading.tsx similarity index 100% rename from apps/web/app/(app)/album/[id]/loading.tsx rename to apps/web/app/(app)/album/loading.tsx diff --git a/apps/web/app/(app)/album/page.tsx b/apps/web/app/(app)/album/page.tsx new file mode 100644 index 0000000..0be8203 --- /dev/null +++ b/apps/web/app/(app)/album/page.tsx @@ -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 Album not found. + return ( + } + highlightedSongId={searchParams.get("s") ?? undefined} + /> + ) +} diff --git a/apps/web/app/(app)/artist/[id]/page.tsx b/apps/web/app/(app)/artist/[id]/page.server.tsx similarity index 89% rename from apps/web/app/(app)/artist/[id]/page.tsx rename to apps/web/app/(app)/artist/[id]/page.server.tsx index ecd256a..a7747cf 100644 --- a/apps/web/app/(app)/artist/[id]/page.tsx +++ b/apps/web/app/(app)/artist/[id]/page.server.tsx @@ -1,3 +1,5 @@ +// Share links (/artist/) land here on the server build, which adds +// link-preview metadata. The app itself links to /artist?id=. import { fetchQuery } from "convex/nextjs" import { convexServerOptions } from "@/lib/convex-server" import { ArtistPage } from "@/components/artist-page" diff --git a/apps/web/app/(app)/artist/[id]/loading.tsx b/apps/web/app/(app)/artist/loading.tsx similarity index 100% rename from apps/web/app/(app)/artist/[id]/loading.tsx rename to apps/web/app/(app)/artist/loading.tsx diff --git a/apps/web/app/(app)/artist/page.tsx b/apps/web/app/(app)/artist/page.tsx new file mode 100644 index 0000000..c1bc33d --- /dev/null +++ b/apps/web/app/(app)/artist/page.tsx @@ -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 Artist not found. + return } /> +} diff --git a/apps/web/app/(app)/layout.tsx b/apps/web/app/(app)/layout.tsx index 02a758a..932b5da 100644 --- a/apps/web/app/(app)/layout.tsx +++ b/apps/web/app/(app)/layout.tsx @@ -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({ + {process.env.OTUNES_STATIC_EXPORT === "1" && ( + + )}
diff --git a/apps/web/app/(app)/library/artists/[id]/page.tsx b/apps/web/app/(app)/library/artists/[id]/page.tsx deleted file mode 100644 index 862ad7b..0000000 --- a/apps/web/app/(app)/library/artists/[id]/page.tsx +++ /dev/null @@ -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 { - 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 -} diff --git a/apps/web/app/(app)/playlist/[id]/page.tsx b/apps/web/app/(app)/playlist/[id]/page.server.tsx similarity index 90% rename from apps/web/app/(app)/playlist/[id]/page.tsx rename to apps/web/app/(app)/playlist/[id]/page.server.tsx index ab5d59d..c4a7c61 100644 --- a/apps/web/app/(app)/playlist/[id]/page.tsx +++ b/apps/web/app/(app)/playlist/[id]/page.server.tsx @@ -1,3 +1,5 @@ +// Share links (/playlist/) land here on the server build, which adds +// link-preview metadata. The app itself links to /playlist?id=. import { PlaylistPage } from "@/components/playlist-page" import { api } from "@otunes/convex/_generated/api" import { convexAuthNextjsToken } from "@convex-dev/auth/nextjs/server" diff --git a/apps/web/app/(app)/playlist/[id]/loading.tsx b/apps/web/app/(app)/playlist/loading.tsx similarity index 100% rename from apps/web/app/(app)/playlist/[id]/loading.tsx rename to apps/web/app/(app)/playlist/loading.tsx diff --git a/apps/web/app/(app)/playlist/page.tsx b/apps/web/app/(app)/playlist/page.tsx new file mode 100644 index 0000000..28bb809 --- /dev/null +++ b/apps/web/app/(app)/playlist/page.tsx @@ -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 Playlist not found. + return } /> +} diff --git a/apps/web/app/(auth)/layout.tsx b/apps/web/app/(auth)/layout.tsx index 9dd93a3..da80a68 100644 --- a/apps/web/app/(auth)/layout.tsx +++ b/apps/web/app/(auth)/layout.tsx @@ -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 (
+ {process.env.OTUNES_STATIC_EXPORT === "1" && } {children}
) diff --git a/apps/web/app/(auth)/signin/page.tsx b/apps/web/app/(auth)/signin/page.tsx index 211e168..18c311b 100644 --- a/apps/web/app/(auth)/signin/page.tsx +++ b/apps/web/app/(auth)/signin/page.tsx @@ -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 ( - - ) +export default function SignInPage() { + return } diff --git a/apps/web/app/(auth)/signup/page.tsx b/apps/web/app/(auth)/signup/page.tsx index 93a13ba..a72b053 100644 --- a/apps/web/app/(auth)/signup/page.tsx +++ b/apps/web/app/(auth)/signup/page.tsx @@ -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 return ( - + + + + This server has disabled new signups :( + + + + + + ) } diff --git a/apps/web/app/api/album/[id]/cover/route.ts b/apps/web/app/api/album/[id]/cover/route.server.ts similarity index 100% rename from apps/web/app/api/album/[id]/cover/route.ts rename to apps/web/app/api/album/[id]/cover/route.server.ts diff --git a/apps/web/app/api/artist/[id]/cover/route.ts b/apps/web/app/api/artist/[id]/cover/route.server.ts similarity index 100% rename from apps/web/app/api/artist/[id]/cover/route.ts rename to apps/web/app/api/artist/[id]/cover/route.server.ts diff --git a/apps/web/app/api/playlist/[id]/cover/route.ts b/apps/web/app/api/playlist/[id]/cover/route.server.ts similarity index 100% rename from apps/web/app/api/playlist/[id]/cover/route.ts rename to apps/web/app/api/playlist/[id]/cover/route.server.ts diff --git a/apps/web/app/api/song/[id]/play/hls/route.ts b/apps/web/app/api/song/[id]/play/hls/route.server.ts similarity index 100% rename from apps/web/app/api/song/[id]/play/hls/route.ts rename to apps/web/app/api/song/[id]/play/hls/route.server.ts diff --git a/apps/web/app/api/song/[id]/play/hls/segment/[segment]/route.ts b/apps/web/app/api/song/[id]/play/hls/segment/[segment]/route.server.ts similarity index 100% rename from apps/web/app/api/song/[id]/play/hls/segment/[segment]/route.ts rename to apps/web/app/api/song/[id]/play/hls/segment/[segment]/route.server.ts diff --git a/apps/web/app/api/song/[id]/play/route.ts b/apps/web/app/api/song/[id]/play/route.server.ts similarity index 100% rename from apps/web/app/api/song/[id]/play/route.ts rename to apps/web/app/api/song/[id]/play/route.server.ts diff --git a/apps/web/app/api/user/[id]/avatar/route.ts b/apps/web/app/api/user/[id]/avatar/route.server.ts similarity index 100% rename from apps/web/app/api/user/[id]/avatar/route.ts rename to apps/web/app/api/user/[id]/avatar/route.server.ts diff --git a/apps/web/app/desktop/page.tsx b/apps/web/app/desktop/page.server.tsx similarity index 100% rename from apps/web/app/desktop/page.tsx rename to apps/web/app/desktop/page.server.tsx diff --git a/apps/web/app/layout.tsx b/apps/web/app/layout.tsx index c136902..00e94e8 100644 --- a/apps/web/app/layout.tsx +++ b/apps/web/app/layout.tsx @@ -37,8 +37,11 @@ async function hostedUrl() { } } +const staticExport = process.env.OTUNES_STATIC_EXPORT === "1" + export async function generateMetadata(): Promise { - 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({ {needsServer ? ( content + ) : staticExport ? ( + {content} ) : ( diff --git a/apps/web/app/manifest.ts b/apps/web/app/manifest.ts index 8388694..34d8c30 100644 --- a/apps/web/app/manifest.ts +++ b/apps/web/app/manifest.ts @@ -1,5 +1,7 @@ import type { MetadataRoute } from "next" +export const dynamic = "force-static" + export default function manifest(): MetadataRoute.Manifest { return { name: "oTunes", diff --git a/apps/web/components/add-to-playlist-provider.tsx b/apps/web/components/add-to-playlist-provider.tsx index 5cc1ad8..d81133c 100644 --- a/apps/web/components/add-to-playlist-provider.tsx +++ b/apps/web/components/add-to-playlist-provider.tsx @@ -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( diff --git a/apps/web/components/album-card.tsx b/apps/web/components/album-card.tsx index 082516a..28b4987 100644 --- a/apps/web/components/album-card.tsx +++ b/apps/web/components/album-card.tsx @@ -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)} > - + {album.title}
- +

{album.title}

{album.artist.name}

diff --git a/apps/web/components/album-view.tsx b/apps/web/components/album-view.tsx index 34ec288..cfaa3e7 100644 --- a/apps/web/components/album-view.tsx +++ b/apps/web/components/album-view.tsx @@ -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} {album.artist.name} diff --git a/apps/web/components/app-sidebar.tsx b/apps/web/components/app-sidebar.tsx index e8c9729..b8f948e 100644 --- a/apps/web/components/app-sidebar.tsx +++ b/apps/web/components/app-sidebar.tsx @@ -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 Playlists - - {playlistNav.map((item) => ( - - - setOpenMobile(false)}> - {item.icon} - {item.title} - - - - ))} - + setOpenMobile(false)} + /> + } + > + setOpenMobile(false)} + /> + @@ -255,3 +260,46 @@ export function AppSidebar() { ) } + +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 ( + + ) +} + +function PlaylistMenu({ + items, + route, + onNavigate, +}: { + items: NavItem[] + route: string + onNavigate: () => void +}) { + return ( + + {items.map((item) => ( + + + + {item.icon} + {item.title} + + + + ))} + + ) +} diff --git a/apps/web/components/artist-card.tsx b/apps/web/components/artist-card.tsx index c66a788..d5d9c11 100644 --- a/apps/web/components/artist-card.tsx +++ b/apps/web/components/artist-card.tsx @@ -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 }) {
- +

{artist.name}

diff --git a/apps/web/components/artists-page.tsx b/apps/web/components/artists-page.tsx index 744ab95..ae89d11 100644 --- a/apps/web/components/artists-page.tsx +++ b/apps/web/components/artists-page.tsx @@ -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() { )} diff --git a/apps/web/components/artists-view.tsx b/apps/web/components/artists-view.tsx index f10b361..46e71df 100644 --- a/apps/web/components/artists-view.tsx +++ b/apps/web/components/artists-view.tsx @@ -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({
{selectedArtist.name} diff --git a/apps/web/components/auth-form.tsx b/apps/web/components/auth-form.tsx index 65d6a38..bcab4be 100644 --- a/apps/web/components/auth-form.tsx +++ b/apps/web/components/auth-form.tsx @@ -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(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) { event.preventDefault() - if (signupsDisabled) { - return - } setError(null) setSubmitting(true) @@ -100,71 +89,62 @@ export function AuthForm({ {text.description} - {signupsDisabled ? ( -

- New account registration is currently disabled. Contact an - administrator if you need access. -

- ) : ( -
- - {flow === "signUp" && ( - - Name - - - )} + + + {flow === "signUp" && ( - Email + Name - - Password - - - {error && {error}} - - - - {!hideSignUpLink ? ( -

- {text.switchPrompt}{" "} - - {text.switchLabel} - -

- ) : null} -
- - )} + )} + + Email + + + + Password + + + {error && {error}} + + + +

+ {text.switchPrompt}{" "} + + {text.switchLabel} + +

+
+
) diff --git a/apps/web/components/auth-redirect.tsx b/apps/web/components/auth-redirect.tsx new file mode 100644 index 0000000..e10d668 --- /dev/null +++ b/apps/web/components/auth-redirect.tsx @@ -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 +} diff --git a/apps/web/components/convex-client-provider.tsx b/apps/web/components/convex-client-provider.tsx index 5f9416c..f03a625 100644 --- a/apps/web/components/convex-client-provider.tsx +++ b/apps/web/components/convex-client-provider.tsx @@ -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 ( - - {children}{" "} + const client = getConvexClient(convexUrl) + const content = {children} + // 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" ? ( + + {content} + + ) : ( + + {content} ) } diff --git a/apps/web/components/media-context-menu.tsx b/apps/web/components/media-context-menu.tsx index aa1610b..5e8b77a 100644 --- a/apps/web/components/media-context-menu.tsx +++ b/apps/web/components/media-context-menu.tsx @@ -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({ {artist ? ( - + Go to Artist @@ -173,7 +175,7 @@ export function MediaContextMenuItems({ ) : null} {album ? ( - + Go to Album diff --git a/apps/web/components/open-app-button.tsx b/apps/web/components/open-app-button.tsx index 32fff6f..7c2d029 100644 --- a/apps/web/components/open-app-button.tsx +++ b/apps/web/components/open-app-button.tsx @@ -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/), not in-app /album?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) } diff --git a/apps/web/components/playback-song-meta.tsx b/apps/web/components/playback-song-meta.tsx index 4e10831..6de3566 100644 --- a/apps/web/components/playback-song-meta.tsx +++ b/apps/web/components/playback-song-meta.tsx @@ -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({ )} > {song.album.title} diff --git a/apps/web/components/player-bar.tsx b/apps/web/components/player-bar.tsx index 764bca0..ed5ec8e 100644 --- a/apps/web/components/player-bar.tsx +++ b/apps/web/components/player-bar.tsx @@ -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() {
{currentSong.title}

{currentSong.artist.name} · {currentSong.album.title} diff --git a/apps/web/components/playlist-card.tsx b/apps/web/components/playlist-card.tsx index 2b1e71c..d815064 100644 --- a/apps/web/components/playlist-card.tsx +++ b/apps/web/components/playlist-card.tsx @@ -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 (

- + {playlist.title}
- +

{playlist.title}

diff --git a/apps/web/components/search-song-item.tsx b/apps/web/components/search-song-item.tsx index 94100c1..30cfc78 100644 --- a/apps/web/components/search-song-item.tsx +++ b/apps/web/components/search-song-item.tsx @@ -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 }) {

- +

{song.title}

{song.artist.name}

diff --git a/apps/web/components/search-top-result-card.tsx b/apps/web/components/search-top-result-card.tsx index 0d9065c..a3bcc8b 100644 --- a/apps/web/components/search-top-result-card.tsx +++ b/apps/web/components/search-top-result-card.tsx @@ -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) } } diff --git a/apps/web/components/track-row.tsx b/apps/web/components/track-row.tsx index c732512..d8ae7a8 100644 --- a/apps/web/components/track-row.tsx +++ b/apps/web/components/track-row.tsx @@ -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({
event.stopPropagation()} > @@ -407,7 +409,7 @@ function TrackRowComponent({
event.stopPropagation()} > diff --git a/apps/web/lib/routes.ts b/apps/web/lib/routes.ts new file mode 100644 index 0000000..c040b66 --- /dev/null +++ b/apps/web/lib/routes.ts @@ -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/` 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 })}` +} diff --git a/apps/web/next.config.ts b/apps/web/next.config.ts index a83c4ef..9e0ef15 100644 --- a/apps/web/next.config.ts +++ b/apps/web/next.config.ts @@ -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", diff --git a/apps/web/package.json b/apps/web/package.json index f943371..fd2af4e 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -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" diff --git a/apps/web/proxy.ts b/apps/web/proxy.server.ts similarity index 97% rename from apps/web/proxy.ts rename to apps/web/proxy.server.ts index dfed5a5..68a09a4 100644 --- a/apps/web/proxy.ts +++ b/apps/web/proxy.server.ts @@ -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", ])