mirror of
https://github.com/ragestudio/comty.js.git
synced 2025-06-09 02:24:18 +00:00
removed unused models
This commit is contained in:
parent
94c8d7383e
commit
df328ea035
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user