swap to generated api code and composables

This commit is contained in:
2025-05-21 16:44:23 +02:00
parent b9e865780a
commit a7a6a9b65d
29 changed files with 3307 additions and 517 deletions

View File

@@ -1,3 +1,5 @@
import type { Apiv1Song, v1CollectionPreview } from '@/generated';
export type Song = {
hash: string;
name: string;
@@ -8,6 +10,20 @@ export type Song = {
mapper: string;
};
const basePath = import.meta.env.BACKEND_URL || 'http://localhost:8080';
export function mapToSong(apiSong: Apiv1Song): Song {
return {
hash: apiSong.md5Hash,
name: apiSong.title,
artist: apiSong.artist,
length: Number(apiSong.totalTime),
url: `${basePath}/api/v1/audio/${btoa(apiSong.folder + "/" + apiSong.audio).replace(/=+$/, '')}`,
previewimage: `${basePath}/api/v1/image/${btoa(apiSong.image === "" || apiSong.image === undefined ? "404.png" : apiSong.image).replace(/=+$/, '')}`,
mapper: apiSong.creator,
};
}
export type CollectionPreview = {
index: number;
name: string;
@@ -15,6 +31,19 @@ export type CollectionPreview = {
previewimage: string;
};
export function mapToCollectionPreview(
apiCollection: v1CollectionPreview,
index: number
): CollectionPreview {
return {
index,
name: apiCollection.name,
length: apiCollection.items,
previewimage: `${basePath}/api/v1/images/${apiCollection.image}`,
};
}
export type Me = {
id: number;
name: string;
@@ -22,3 +51,13 @@ export type Me = {
endpoint: string;
share: boolean;
};
export function mapApiToSongs(apiSongs: Apiv1Song[]): Song[] {
return apiSongs.map(mapToSong);
}
export function mapApiToCollectionPreview(
apiCollections: v1CollectionPreview[]
): CollectionPreview[] {
return apiCollections.map((c, i) => mapToCollectionPreview(c, i));
}