mirror of
https://codeberg.org/lucida/lucida.git
synced 2026-11-12 22:57:22 -05:00
20 lines
693 B
TypeScript
20 lines
693 B
TypeScript
import { fetch } from 'undici'
|
|
import { BarcodeAlbumType, LookupType } from '../../types.js'
|
|
import { AcceptableAlbumTypes, RawError, RawUPCAlbum, UPC } from './constants.js'
|
|
import { parseAlbum, parseError } from './parse.js'
|
|
|
|
export async function getTrack(tag: string, type: BarcodeAlbumType) {
|
|
if (!AcceptableAlbumTypes.includes(type)) throw new Error('Cannot use this type with Deezer.')
|
|
|
|
switch (type) {
|
|
case 'upc': {
|
|
const data = (await (await fetch(UPC.replace('{upc}', tag))).json()) as any
|
|
|
|
if (data?.id) return parseAlbum(data as RawUPCAlbum)
|
|
else throw new Error(parseError(data as RawError))
|
|
}
|
|
}
|
|
}
|
|
|
|
export async function getAlbum(tag: string, type: LookupType) {}
|