musicControl.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import api from "./baseApi.ts"
  2. import {Order, Page, ResponseData} from "@/types/apiTypes.ts";
  3. import {Music_Actions} from "@/apis/ApiAction.ts";
  4. import {MusicInfo, MusicScanSetting, PlayList} from "@/types/musicType.ts";
  5. import {promises} from "fs-extra";
  6. export async function musicAppStart()
  7. {
  8. let [_callId, promise] = api.sendQuery(Music_Actions.music_app_start, {});
  9. let response = await promise;
  10. return response;
  11. }
  12. export async function fetchPlayList(): Promise< ResponseData<PlayList[]> >
  13. {
  14. let [_callId, promise] = api.sendQuery(Music_Actions.play_list_fetch, {});
  15. let response = await promise;
  16. return response;
  17. }
  18. export async function selectScanDir(defaultPath: string): Promise< ResponseData<string> >
  19. {
  20. let [_callId, promise] = api.sendQuery(Music_Actions.scan_music_select, defaultPath, -1, true);
  21. return await promise;
  22. }
  23. export async function addScanDir(scanSetting: MusicScanSetting)
  24. {
  25. let [_callId, promise] = api.sendQuery(Music_Actions.scan_music_add, scanSetting);
  26. return await promise;
  27. }
  28. export async function updateScanConfig(scanConfig: MusicScanSetting)
  29. {
  30. let [_callId, promise] = api.sendQuery(Music_Actions.scan_music_update, scanConfig);
  31. return await promise;
  32. }
  33. export async function fetchScanConfig() : Promise<ResponseData<MusicScanSetting[]>>
  34. {
  35. let [_callId, promise] = api.sendQuery(Music_Actions.scan_settings, {});
  36. return await promise;
  37. }
  38. export async function deleteScanConfig(id: number) : Promise<ResponseData<boolean>>
  39. {
  40. let [_callId, promise] = api.sendQuery(Music_Actions.scan_music_delete, id);
  41. return await promise;
  42. }
  43. export async function fetchScanMusic(scanId: number, page: number = 1, size: number = 10,
  44. key: string = '',
  45. sort: string = 'id',
  46. order: Order = Order.desc): Promise<ResponseData<Page<MusicInfo[]>>>
  47. {
  48. let [_callId, promise] = api.sendQuery(Music_Actions.scan_music_fetch,
  49. {data: scanId, page, size, sort, order, key} as Page<number>);
  50. return await promise as ResponseData<Page<MusicInfo[]>>;
  51. }
  52. export async function api_likeMusic(musicId: number): Promise<ResponseData<boolean>>
  53. {
  54. let [_callId, promise] = api.sendQuery(Music_Actions.like_music, musicId);
  55. return await promise;
  56. }