From df328ea035d9f981880e935681f786bf1ee72054 Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Thu, 15 May 2025 13:00:57 +0000 Subject: [PATCH] removed unused models --- src/models/payments/index.js | 17 --- src/models/sync/index.js | 59 ---------- src/models/sync/services/spotify.js | 87 -------------- src/models/sync/services/tidal.js | 172 ---------------------------- src/utils/generateRequest.ts | 52 --------- 5 files changed, 387 deletions(-) delete mode 100644 src/models/payments/index.js delete mode 100755 src/models/sync/index.js delete mode 100755 src/models/sync/services/spotify.js delete mode 100755 src/models/sync/services/tidal.js delete mode 100644 src/utils/generateRequest.ts diff --git a/src/models/payments/index.js b/src/models/payments/index.js deleted file mode 100644 index 307b10c..0000000 --- a/src/models/payments/index.js +++ /dev/null @@ -1,17 +0,0 @@ -import request from "../../request" - -export default class PaymentsModel { - /** - * Fetches the current balance from the server. - * - * @return {object} The balance data received from the server. - */ - static async fetchBalance() { - const response = await request({ - method: "GET", - url: "/payments/balance", - }) - - return response.data.balance - } -} \ No newline at end of file diff --git a/src/models/sync/index.js b/src/models/sync/index.js deleted file mode 100755 index edc04f9..0000000 --- a/src/models/sync/index.js +++ /dev/null @@ -1,59 +0,0 @@ -import spotifyService from "./services/spotify" -import tidalService from "./services/tidal" - -import request from "../../request" - -const namespacesServices = { - spotify: spotifyService, - tidal: tidalService -} - -export default class SyncModel { - static get spotifyCore() { - return namespacesServices.spotify - } - - static get tidalCore() { - return namespacesServices.tidal - } - - static async linkService(namespace) { - const service = namespacesServices[namespace] - - if (!service || typeof service.linkAccount !== "function") { - throw new Error(`Service ${namespace} not found or not accepting linking.`) - } - - return await service.linkAccount() - } - - static async unlinkService(namespace) { - const service = namespacesServices[namespace] - - if (!service || typeof service.unlinkAccount !== "function") { - throw new Error(`Service ${namespace} not found or not accepting unlinking.`) - } - - return await service.unlinkAccount() - } - - static async hasServiceLinked(namespace) { - const service = namespacesServices[namespace] - - if (!service || typeof service.isActive !== "function") { - throw new Error(`Service ${namespace} not found or not accepting linking.`) - } - - return await service.isActive() - } - - static async getLinkedServices() { - const response = await request({ - instance: globalThis.__comty_shared_state.instances["sync"], - method: "GET", - url: "/active_services", - }) - - return response.data - } -} \ No newline at end of file diff --git a/src/models/sync/services/spotify.js b/src/models/sync/services/spotify.js deleted file mode 100755 index 5860e21..0000000 --- a/src/models/sync/services/spotify.js +++ /dev/null @@ -1,87 +0,0 @@ -export default class SpotifySyncModel { - static get spotify_redirect_uri() { - return window.location.origin + "/callbacks/sync/spotify" - } - - static get spotify_authorize_endpoint() { - return "https://accounts.spotify.com/authorize?response_type=code&client_id={{client_id}}&scope={{scope}}&redirect_uri={{redirect_uri}}&response_type=code" - } - - static async authorizeAccount() { - const scopes = [ - "user-read-private", - "user-modify-playback-state", - "user-read-currently-playing", - "user-read-playback-state", - "streaming", - ] - - const { client_id } = await SpotifySyncModel.get_client_id() - - const parsedUrl = SpotifySyncModel.spotify_authorize_endpoint - .replace("{{client_id}}", client_id) - .replace("{{scope}}", scopes.join(" ")) - .replace("{{redirect_uri}}", SpotifySyncModel.spotify_redirect_uri) - - // open on a new tab - window.open(parsedUrl, "_blank") - } - - static async get_client_id() { - const { data } = await app.cores.api.customRequest({ - method: "GET", - url: `/sync/spotify/client_id`, - }) - - return data - } - - static async syncAuthCode(code) { - const { data } = await app.cores.api.customRequest({ - method: "POST", - url: `/sync/spotify/auth`, - data: { - redirect_uri: SpotifySyncModel.spotify_redirect_uri, - code, - }, - }) - - return data - } - - static async unlinkAccount() { - const { data } = await app.cores.api.customRequest({ - method: "POST", - url: `/sync/spotify/unlink`, - }) - - return data - } - - static async isAuthorized() { - const { data } = await app.cores.api.customRequest({ - method: "GET", - url: `/sync/spotify/is_authorized`, - }) - - return data - } - - static async getData() { - const { data } = await app.cores.api.customRequest({ - method: "GET", - url: `/sync/spotify/data`, - }) - - return data - } - - static async getCurrentPlaying() { - const { data } = await app.cores.api.customRequest({ - method: "GET", - url: `/sync/spotify/currently_playing`, - }) - - return data - } -} \ No newline at end of file diff --git a/src/models/sync/services/tidal.js b/src/models/sync/services/tidal.js deleted file mode 100755 index 353c7c0..0000000 --- a/src/models/sync/services/tidal.js +++ /dev/null @@ -1,172 +0,0 @@ -import request from "../../../request" - -export default class TidalService { - static get api_instance() { - return globalThis.__comty_shared_state.instances["sync"] - } - - static async linkAccount() { - if (!window) { - throw new Error("This method is only available in the browser.") - } - - const { data } = await request({ - instance: TidalService.api_instance, - method: "GET", - url: `/services/tidal/create_link`, - }) - - if (data.auth_url) { - window.open(data.auth_url, "_blank") - } - - return data - } - - static async unlinkAccount() { - if (!window) { - throw new Error("This method is only available in the browser.") - } - - const { data } = await request({ - instance: TidalService.api_instance, - method: "POST", - url: `/services/tidal/delete_link`, - }) - - return data - } - - static async isActive() { - if (!window) { - throw new Error("This method is only available in the browser.") - } - - const { data } = await request({ - instance: TidalService.api_instance, - method: "GET", - url: `/services/tidal/is_active`, - }) - - return data - } - - static async getCurrentUser() { - const { data } = await request({ - instance: TidalService.api_instance, - method: "GET", - url: `/services/tidal/current`, - }) - - return data - } - - static async getPlaybackUrl(track_id) { - const { data } = await request({ - instance: TidalService.api_instance, - method: "GET", - url: `/services/tidal/playback/${track_id}`, - }) - - return data - } - - static async getTrackManifest(track_id) { - const { data } = await request({ - instance: TidalService.api_instance, - method: "GET", - url: `/services/tidal/manifest/${track_id}`, - }) - - return data - } - - static async getMyFavoriteTracks({ - limit = 50, - offset = 0, - } = {}) { - const { data } = await request({ - instance: TidalService.api_instance, - method: "GET", - url: `/services/tidal/favorites/tracks`, - params: { - limit, - offset, - }, - }) - - return data - } - - static async getMyFavoritePlaylists({ - limit = 50, - offset = 0, - } = {}) { - const { data } = await request({ - instance: TidalService.api_instance, - method: "GET", - url: `/services/tidal/favorites/playlists`, - params: { - limit, - offset, - }, - }) - - return data - } - - static async getPlaylistData({ - playlist_id, - - resolve_items = false, - limit = 50, - offset = 0, - }) { - const { data } = await request({ - instance: TidalService.api_instance, - method: "GET", - url: `/services/tidal/playlist/${playlist_id}/data`, - params: { - limit, - offset, - resolve_items, - }, - }) - - return data - } - - static async getPlaylistItems({ - playlist_id, - - resolve_items = false, - limit = 50, - offset = 0, - }) { - const { data } = await request({ - instance: TidalService.api_instance, - method: "GET", - url: `/services/tidal/playlist/${playlist_id}/items`, - params: { - limit, - offset, - resolve_items, - }, - }) - - return data - } - - static async toggleTrackLike({ - track_id, - to, - }) { - const { data } = await request({ - instance: TidalService.api_instance, - method: to ? "POST" : "DELETE", - url: `/services/tidal/track/${track_id}/like`, - }) - - return data - } -} \ No newline at end of file diff --git a/src/utils/generateRequest.ts b/src/utils/generateRequest.ts deleted file mode 100644 index 3f62110..0000000 --- a/src/utils/generateRequest.ts +++ /dev/null @@ -1,52 +0,0 @@ -import request from "../request" - -// create a regex to detect params with %% symbol, from the url -const paramMatchRegex = /(%[0-9a-f]{2}%)/g - -export default (method: string = "GET", url: string = "/", params?: object, data?: object) => { - return async function generatedRequest(arg0: any, arg1: any) { - const requestObj = { - method: method, - url: url, - params: params, - data: data, - } - - // search url for params - // example: /namespace/search/[0]/data => /namespace/search/${arguments[0]}/data - // if no url matches, merge params with arg0 and override data in requestObj - if (url.match(paramMatchRegex)) { - requestObj.url = url.replace(paramMatchRegex, (match) => { - console.log(match) - - // replace with arguments - const fnArgumentIndex = "" - - return match - }) - } else { - requestObj.params = { - ...requestObj.params, - ...arg0 - } - requestObj.data = { - ...requestObj.data, - ...arg1 - } - } - - if (typeof requestObj.params === "object" && requestObj.params) { - Object.keys(requestObj.params).forEach((key) => { - if (requestObj.params && typeof requestObj.params[key] === "string") { - - } - }) - } - - - const response = await request(requestObj) - - // @ts-ignore - return response.data - } -} \ No newline at end of file