mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 07:15:47 +00:00
33 lines
981 B
TypeScript
33 lines
981 B
TypeScript
import type { SubsonicSong } from '../../api/subsonicTypes';
|
|
import type { DeviceSyncSource } from '@/features/deviceSync';
|
|
import {
|
|
resolveAlbum,
|
|
resolveArtist,
|
|
resolveMediaServerId,
|
|
resolvePlaylist,
|
|
} from '../offline/offlineMediaResolve';
|
|
|
|
export async function fetchTracksForSource(source: DeviceSyncSource): Promise<SubsonicSong[]> {
|
|
const serverId = resolveMediaServerId();
|
|
if (!serverId) return [];
|
|
|
|
if (source.type === 'playlist') {
|
|
const result = await resolvePlaylist(serverId, source.id);
|
|
return result?.songs ?? [];
|
|
}
|
|
if (source.type === 'album') {
|
|
const result = await resolveAlbum(serverId, source.id);
|
|
return result?.songs ?? [];
|
|
}
|
|
|
|
const artistData = await resolveArtist(serverId, source.id);
|
|
if (!artistData) return [];
|
|
|
|
const results = await Promise.all(
|
|
artistData.albums.map(a =>
|
|
resolveAlbum(serverId, a.id).then(r => r?.songs ?? []).catch(() => [] as SubsonicSong[]),
|
|
),
|
|
);
|
|
return results.flat();
|
|
}
|