trptk/lib/release.ts
2026-02-24 17:14:07 +01:00

65 lines
1.8 KiB
TypeScript

import type { SanityImageSource } from "@sanity/image-url";
import { AiFillSpotify, AiFillAmazonCircle, AiFillApple } from "react-icons/ai";
import { BiLogoDeezer } from "react-icons/bi";
import { LuAudioLines } from "react-icons/lu";
import { QobuzIcon } from "@/components/icons/QobuzIcon";
import { SiTidal } from "react-icons/si";
export type Release = {
name?: string;
albumArtist?: string;
label: string;
catalogNo?: string;
releaseDate?: string;
slug?: string;
albumCover?: SanityImageSource;
officialUrl?: string;
spotifyUrl?: string;
appleMusicUrl?: string;
deezerUrl?: string;
amazonMusicUrl?: string;
tidalUrl?: string;
qobuzUrl?: string;
};
export const ICONS = {
studio: LuAudioLines,
spotify: AiFillSpotify,
apple: AiFillApple,
deezer: BiLogoDeezer,
amazon: AiFillAmazonCircle,
tidal: SiTidal,
qobuz: QobuzIcon,
} as const;
export type IconKey = keyof typeof ICONS;
export type StreamingLink = {
label: string;
url: string;
icon: IconKey;
};
function isValidHttpUrl(url: unknown): url is string {
return typeof url === "string" && url.startsWith("http");
}
type StreamingLinkMaybe = Omit<StreamingLink, "url"> & { url?: string };
function isStreamingLink(l: StreamingLinkMaybe): l is StreamingLink {
return isValidHttpUrl(l.url);
}
export function buildLinks(r: Release): StreamingLink[] {
const list: StreamingLinkMaybe[] = [
{ label: "official", url: r.officialUrl, icon: "studio" },
{ label: "Spotify", url: r.spotifyUrl, icon: "spotify" },
{ label: "Apple Music", url: r.appleMusicUrl, icon: "apple" },
{ label: "Deezer", url: r.deezerUrl, icon: "deezer" },
{ label: "Amazon Music", url: r.amazonMusicUrl, icon: "amazon" },
{ label: "Tidal", url: r.tidalUrl, icon: "tidal" },
{ label: "Qobuz", url: r.qobuzUrl, icon: "qobuz" },
];
return list.filter(isStreamingLink);
}