Files
wehub-resource-sync 2114b14ee0
Sync main into demo / sync (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:35:26 +08:00

23 lines
789 B
TypeScript

import type { SpotifyTrack } from '../types';
const APPLE_ARTWORK_SIZE_RE = /\/(\d+)x(\d+)(bb)?(?=\.[a-z0-9]+(?:\?|$))/i;
export function resizeAppleArtworkUrl(raw: string | undefined, size: number): string {
if (!raw) return '';
return raw.replace(APPLE_ARTWORK_SIZE_RE, `/${size}x${size}$3`);
}
export function inferLargeArtworkUrl(raw: string | undefined): string {
if (!raw) return '';
const resized = resizeAppleArtworkUrl(raw, 1000);
return resized === raw ? '' : resized;
}
export function getTrackCover(track: Pick<SpotifyTrack, 'cover'> | null | undefined): string {
return track?.cover || '';
}
export function getTrackCoverLarge(track: Pick<SpotifyTrack, 'cover' | 'coverLarge'> | null | undefined): string {
return track?.coverLarge || track?.cover || '';
}