From 60ba6cf2c642152580c919749732f4264b64f71b Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Tue, 30 May 2023 01:09:58 +0000 Subject: [PATCH] use music api instance --- .../comty.js/src/models/playlists/index.js | 85 ++++++++++++++----- 1 file changed, 66 insertions(+), 19 deletions(-) diff --git a/packages/comty.js/src/models/playlists/index.js b/packages/comty.js/src/models/playlists/index.js index 0cf52343..51c4ddac 100755 --- a/packages/comty.js/src/models/playlists/index.js +++ b/packages/comty.js/src/models/playlists/index.js @@ -1,48 +1,95 @@ import request from "../../handlers/request" export default class PlaylistsModel { + static get api_instance() { + return globalThis.__comty_shared_state.instances["music"] + } + static putPlaylist = async (payload) => { if (!payload) { throw new Error("Payload is required") } const { data } = await request({ + instance: PlaylistsModel.api_instance, method: "PUT", - url: `/playlist`, + url: `/playlists/playlist`, data: payload, }) return data } - static getPlaylist = async (id) => { - const { data } = await request({ - method: "GET", - url: `/playlist/data/${id}`, - }) - - return data - } - - static getMyReleases = async () => { - const { data } = await request({ - method: "GET", - url: `/playlist/self`, - }) - - return data - } - static deletePlaylist = async (id) => { if (!id) { throw new Error("ID is required") } const { data } = await request({ + instance: PlaylistsModel.api_instance, method: "DELETE", url: `/playlist/${id}`, }) return data } + + static getTrack = async (id) => { + const { data } = await request({ + instance: PlaylistsModel.api_instance, + method: "GET", + url: `/tracks/${id}/data`, + }) + + return data + } + + static getTracks = async (ids) => { + const { data } = await request({ + instance: PlaylistsModel.api_instance, + method: "GET", + url: `/tracks/many`, + params: { + ids, + } + }) + + return data + } + + static getPlaylist = async (id) => { + const { data } = await request({ + instance: PlaylistsModel.api_instance, + method: "GET", + url: `/playlists/${id}/data`, + }) + + return data + } + + static search = async (keywords) => { + const { data } = await request({ + instance: PlaylistsModel.api_instance, + method: "GET", + url: `/playlists/search`, + params: { + keywords, + } + }) + + return data + } + + static getMyReleases = async (keywords) => { + const { data } = await request({ + instance: PlaylistsModel.api_instance, + method: "GET", + url: `/playlists/self`, + params: { + keywords, + } + }) + + return data + } } \ No newline at end of file