import 'package:dio/dio.dart'; import 'package:music_web_player/config.dart'; class MusicEntry { final int id; final String artist; final String title; const MusicEntry({ required this.id, required this.artist, required this.title, }); String get coverCacheKey => "cover-$id"; } typedef MusicsList = List; class API { /// Get the list of music static Future getList() async { final response = await Dio().get(config.apiURL + "/list", options: Options(headers: {"Token": config.apiToken})); if (response.statusCode != 200) { throw Exception("Request failed with status ${response.statusCode} !"); } return response.data .map((r) => MusicEntry(id: r["id"], artist: r["artist"], title: r["title"])) .toList() .cast(); } } extension MusicEntryAPIExt on MusicEntry { String get coverURL => "${config.apiURL}/cover/$id"; String get musicURL => "${config.apiURL}/download/$id?token=${config.apiToken}"; }