feat: addex type declaration
This commit is contained in:
@@ -1,42 +1,45 @@
|
||||
import axios from 'axios'
|
||||
import type { Album, Artist, SearchResult, Track, TrackDetail } from './types'
|
||||
|
||||
const API_BASE = import.meta.env.VITE_API_BASE_URL ?? ''
|
||||
export const API_ROOT = `${API_BASE}/api`
|
||||
|
||||
const apiKey = import.meta.env.VITE_API_KEY
|
||||
const API_KEY = import.meta.env.VITE_API_KEY
|
||||
|
||||
export const furumiApi = axios.create({
|
||||
baseURL: API_ROOT,
|
||||
headers: apiKey ? { 'x-api-key': apiKey } : {},
|
||||
headers: API_KEY ? { 'x-api-key': API_KEY } : {},
|
||||
})
|
||||
|
||||
export async function getArtists() {
|
||||
const res = await furumiApi.get('/artists').catch(() => null)
|
||||
export async function getArtists(): Promise<Artist[] | null> {
|
||||
const res = await furumiApi.get<Artist[]>('/artists').catch(() => null)
|
||||
return res?.data ?? null
|
||||
}
|
||||
|
||||
export async function getArtistAlbums(artistSlug: string) {
|
||||
const res = await furumiApi.get(`/artists/${artistSlug}/albums`).catch(() => null)
|
||||
export async function getArtistAlbums(artistSlug: string): Promise<Album[] | null> {
|
||||
const res = await furumiApi.get<Album[]>(`/artists/${artistSlug}/albums`).catch(() => null)
|
||||
return res?.data ?? null
|
||||
}
|
||||
|
||||
export async function getAlbumTracks(albumSlug: string) {
|
||||
const res = await furumiApi.get(`/albums/${albumSlug}`).catch(() => null)
|
||||
export async function getAlbumTracks(albumSlug: string): Promise<Track[] | null> {
|
||||
const res = await furumiApi.get<Track[]>(`/albums/${albumSlug}`).catch(() => null)
|
||||
return res?.data ?? null
|
||||
}
|
||||
|
||||
export async function getArtistTracks(artistSlug: string) {
|
||||
const res = await furumiApi.get(`/artists/${artistSlug}/tracks`).catch(() => null)
|
||||
export async function getArtistTracks(artistSlug: string): Promise<Track[] | null> {
|
||||
const res = await furumiApi.get<Track[]>(`/artists/${artistSlug}/tracks`).catch(() => null)
|
||||
return res?.data ?? null
|
||||
}
|
||||
|
||||
export async function searchTracks(query: string) {
|
||||
const res = await furumiApi.get(`/search?q=${encodeURIComponent(query)}`).catch(() => null)
|
||||
export async function searchTracks(query: string): Promise<SearchResult[] | null> {
|
||||
const res = await furumiApi
|
||||
.get<SearchResult[]>(`/search?q=${encodeURIComponent(query)}`)
|
||||
.catch(() => null)
|
||||
return res?.data ?? null
|
||||
}
|
||||
|
||||
export async function getTrackInfo(trackSlug: string) {
|
||||
const res = await furumiApi.get(`/tracks/${trackSlug}`).catch(() => null)
|
||||
export async function getTrackInfo(trackSlug: string): Promise<TrackDetail | null> {
|
||||
const res = await furumiApi.get<TrackDetail>(`/tracks/${trackSlug}`).catch(() => null)
|
||||
return res?.data ?? null
|
||||
}
|
||||
|
||||
|
||||
42
furumi-node-player/client/src/types.ts
Normal file
42
furumi-node-player/client/src/types.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
// API entity types (see PLAYER-API.md)
|
||||
|
||||
export interface Artist {
|
||||
slug: string
|
||||
name: string
|
||||
album_count: number
|
||||
track_count: number
|
||||
}
|
||||
|
||||
export interface Album {
|
||||
slug: string
|
||||
name: string
|
||||
year: number | null
|
||||
track_count: number
|
||||
has_cover: boolean
|
||||
}
|
||||
|
||||
export interface Track {
|
||||
slug: string
|
||||
title: string
|
||||
track_number: number | null
|
||||
duration_secs: number
|
||||
artist_name: string
|
||||
album_name: string | null
|
||||
album_slug: string | null
|
||||
genre: string | null
|
||||
}
|
||||
|
||||
export interface TrackDetail extends Track {
|
||||
storage_path: string
|
||||
artist_slug: string
|
||||
album_year: number | null
|
||||
}
|
||||
|
||||
export type SearchResultType = 'artist' | 'album' | 'track'
|
||||
|
||||
export interface SearchResult {
|
||||
result_type: SearchResultType
|
||||
slug: string
|
||||
name: string
|
||||
detail: string | null
|
||||
}
|
||||
Reference in New Issue
Block a user