32 lines
805 B
TypeScript
32 lines
805 B
TypeScript
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))
|
|
}
|