scripts/utils/navidrome.ts

33 lines
805 B
TypeScript
Raw Permalink Normal View History

2025-01-14 05:38:00 +03:00
import { z } from 'zod'
import { ffetch as ffetchBase } from './fetch.ts'
import { getEnv } from './misc.ts'
export const navidromeFfetch = ffetchBase.extend({
baseUrl: getEnv('NAVIDROME_ENDPOINT'),
headers: {
'x-nd-authorization': `Bearer ${getEnv('NAVIDROME_TOKEN')}`,
},
})
export const NavidromeSong = z.object({
id: z.string(),
title: z.string(),
album: z.string(),
albumArtist: z.string(),
artist: z.string(),
path: z.string(),
duration: z.number(),
})
export type NavidromeSong = z.infer<typeof NavidromeSong>
export function fetchSongs(offset: number, pageSize: number) {
return navidromeFfetch('/api/song', {
query: {
_start: offset,
_end: offset + pageSize,
_order: 'ASC',
_sort: 'title',
},
}).parsedJson(z.array(NavidromeSong))
}