implement sync server models

This commit is contained in:
SrGooglo 2023-07-27 00:11:31 +00:00
parent d344653e57
commit 2caafab4e4
5 changed files with 157 additions and 11 deletions

View File

@ -14,4 +14,24 @@ export default class MusicModel {
return data
}
static search = async (keywords, {
limit = 5,
offset = 0,
useTidal = false,
}) => {
const { data } = await request({
instance: MusicModel.api_instance,
method: "GET",
url: `/search`,
params: {
keywords,
limit,
offset,
useTidal,
}
})
return data
}
}

View File

@ -1,11 +1,47 @@
import SpotifySyncModel from "./cores/spotifyCore"
import spotifyService from "./services/spotify"
import tidalService from "./services/tidal"
const namespacesServices = {
spotify: spotifyService,
tidal: tidalService
}
export default class SyncModel {
static get bridge() {
return window.app?.cores.api.withEndpoints()
static get spotifyCore() {
return namespacesServices.spotify
}
static get spotifyCore() {
return SpotifySyncModel
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()
}
}

View File

@ -0,0 +1,83 @@
import request from "../../../handlers/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
}
}

View File

@ -24,6 +24,7 @@ const envOrigins = {
marketplace: `http://${getCurrentHostname()}:3040`,
music: `http://${getCurrentHostname()}:3050`,
files: `http://${getCurrentHostname()}:3060`,
sync: `http://${getCurrentHostname()}:3070`,
},
"indev": {
default: `https://indev_api.comty.app/main`,
@ -32,6 +33,7 @@ const envOrigins = {
marketplace: `https://indev_api.comty.app/marketplace`,
music: `https://indev_api.comty.app/music`,
files: `https://indev_api.comty.app/files`,
sync: `https://indev_api.comty.app/sync`,
},
"production": {
default: "https://api.comty.app",
@ -40,6 +42,7 @@ const envOrigins = {
marketplace: `https://marketplace_api.comty.app`,
music: `https://music_api.comty.app`,
files: `https://files_api.comty.app`,
sync: `https://sync_api.comty.app`,
}
}
@ -67,5 +70,9 @@ export default {
files: {
origin: composeRemote("files"),
hasWebsocket: false,
},
sync: {
origin: composeRemote("sync"),
hasWebsocket: false,
}
}