mirror of
https://github.com/JuLi0n21/pwa-player.git
synced 2026-04-19 23:40:05 +00:00
swap to generated api code and composables
This commit is contained in:
@@ -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));
|
||||
}
|
||||
Reference in New Issue
Block a user