mirror of
https://github.com/ragestudio/comty.js.git
synced 2025-06-09 02:24:18 +00:00
merge from local
This commit is contained in:
parent
15f89af37c
commit
99c85b81ef
@ -1,5 +1,5 @@
|
||||
export default async (request) => {
|
||||
if (__comty_shared_state.refreshingToken) {
|
||||
export default async () => {
|
||||
if (__comty_shared_state.refreshingToken === true) {
|
||||
await new Promise((resolve) => {
|
||||
__comty_shared_state.eventBus.once("session:refreshed", resolve)
|
||||
})
|
||||
|
@ -12,13 +12,19 @@ export default async () => {
|
||||
authToken: await SessionModel.token,
|
||||
refreshToken: await SessionModel.refreshToken,
|
||||
}
|
||||
}).catch((error) => {
|
||||
return false
|
||||
})
|
||||
|
||||
if (!response) {
|
||||
throw new Error("Failed to regenerate token, invalid server response.")
|
||||
__comty_shared_state.refreshingToken = false
|
||||
|
||||
throw new Error("Failed to regenerate token.")
|
||||
}
|
||||
|
||||
if (!response.data?.token) {
|
||||
__comty_shared_state.refreshingToken = false
|
||||
|
||||
throw new Error("Failed to regenerate token, invalid server response.")
|
||||
}
|
||||
|
||||
|
16
src/index.js
16
src/index.js
@ -61,25 +61,33 @@ export async function createWebsockets() {
|
||||
// regsister events
|
||||
for (let [key, instance] of Object.entries(instances)) {
|
||||
instance.on("connect", () => {
|
||||
console.debug(`[WS-API][${key}] Connected`)
|
||||
//console.debug(`[WS-API][${key}] Connected`)
|
||||
|
||||
globalThis.__comty_shared_state.eventBus.emit(`${key}:connected`)
|
||||
})
|
||||
|
||||
instance.on("disconnect", () => {
|
||||
console.debug(`[WS-API][${key}] Disconnected`)
|
||||
//console.debug(`[WS-API][${key}] Disconnected`)
|
||||
|
||||
globalThis.__comty_shared_state.eventBus.emit(`${key}:disconnected`)
|
||||
})
|
||||
|
||||
instance.on("reconnect", () => {
|
||||
// console.debug(`[WS-API][${key}] Reconnected`)
|
||||
|
||||
globalThis.__comty_shared_state.eventBus.emit(`${key}:reconnected`)
|
||||
|
||||
reauthenticateWebsockets()
|
||||
})
|
||||
|
||||
instance.on("error", (error) => {
|
||||
console.error(`[WS-API][${key}] Error`, error)
|
||||
//console.error(`[WS-API][${key}] Error`, error)
|
||||
|
||||
globalThis.__comty_shared_state.eventBus.emit(`${key}:error`, error)
|
||||
})
|
||||
|
||||
instance.onAny((event, ...args) => {
|
||||
console.debug(`[WS-API][${key}] Event (${event})`, ...args)
|
||||
//console.debug(`[WS-API][${key}] Event (${event})`, ...args)
|
||||
|
||||
globalThis.__comty_shared_state.eventBus.emit(`${key}:${event}`, ...args)
|
||||
})
|
||||
|
26
src/models/chats/index.js
Normal file
26
src/models/chats/index.js
Normal file
@ -0,0 +1,26 @@
|
||||
import request from "../../request"
|
||||
import SessionModel from "../session"
|
||||
|
||||
export default class ChatsService {
|
||||
static async getChatHistory(chat_id) {
|
||||
if (!chat_id) {
|
||||
throw new Error("chat_id is required")
|
||||
}
|
||||
|
||||
const { data } = await request({
|
||||
method: "GET",
|
||||
url: `/chats/${chat_id}/history`,
|
||||
})
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
static async getRecentChats() {
|
||||
const { data } = await request({
|
||||
method: "GET",
|
||||
url: "/chats/my",
|
||||
})
|
||||
|
||||
return data
|
||||
}
|
||||
}
|
26
src/models/music/getters/myReleases.ts
Normal file
26
src/models/music/getters/myReleases.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import request from "../../../request"
|
||||
|
||||
type Arguments = {
|
||||
limit: Number
|
||||
offset: Number
|
||||
keywords: String
|
||||
}
|
||||
|
||||
export default async ({
|
||||
limit,
|
||||
offset,
|
||||
keywords,
|
||||
}: Arguments) => {
|
||||
const response = await request({
|
||||
method: "GET",
|
||||
url: "/music/releases/self",
|
||||
params: {
|
||||
limit: limit,
|
||||
offset: offset,
|
||||
keywords: keywords,
|
||||
}
|
||||
})
|
||||
|
||||
// @ts-ignore
|
||||
return response.data
|
||||
}
|
31
src/models/music/getters/trackLyrics.ts
Normal file
31
src/models/music/getters/trackLyrics.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import request from "../../../request"
|
||||
|
||||
type RequestOptions = {
|
||||
preferTranslation?: Boolean
|
||||
}
|
||||
|
||||
type RequestParams = {
|
||||
translate_lang?: String
|
||||
}
|
||||
|
||||
export default async (
|
||||
id: String,
|
||||
options: RequestOptions = {
|
||||
preferTranslation: false,
|
||||
}
|
||||
) => {
|
||||
const requestParams: RequestParams = Object()
|
||||
|
||||
if (options.preferTranslation) {
|
||||
requestParams.translate_lang = app.cores.settings.get("app:language")
|
||||
}
|
||||
|
||||
const response = await request({
|
||||
method: "GET",
|
||||
url: `/music/lyrics/${id}`,
|
||||
params: requestParams
|
||||
})
|
||||
|
||||
// @ts-ignore
|
||||
return response.data
|
||||
}
|
@ -54,6 +54,16 @@ export default class MusicModel {
|
||||
*/
|
||||
public static getReleases = Getters.releases
|
||||
|
||||
/**
|
||||
* Retrieves self releases.
|
||||
*
|
||||
* @param {object} options - The options for retrieving my releases.
|
||||
* @param {number} options.limit - The maximum number of releases to retrieve.
|
||||
* @param {number} options.offset - The offset for paginated results.
|
||||
* @return {Promise<Object>} - A promise that resolves to the retrieved releases.
|
||||
*/
|
||||
public static getMyReleases = Getters.myReleases
|
||||
|
||||
/**
|
||||
* Retrieves release data by ID.
|
||||
*
|
||||
@ -77,6 +87,14 @@ export default class MusicModel {
|
||||
*/
|
||||
public static getFeaturedPlaylists = Getters.featuredPlaylists
|
||||
|
||||
/**
|
||||
* Retrieves track lyrics for a given ID.
|
||||
*
|
||||
* @param {string} id - The ID of the track.
|
||||
* @return {Promise<Object>} The track lyrics.
|
||||
*/
|
||||
public static getTrackLyrics = Getters.trackLyrics
|
||||
|
||||
|
||||
|
||||
//!INCOMPLETE
|
||||
|
@ -6,8 +6,16 @@ function getCurrentHostname() {
|
||||
return window?.location?.hostname ?? "localhost"
|
||||
}
|
||||
|
||||
function getCurrentProtocol() {
|
||||
if (typeof window === "undefined") {
|
||||
return "http"
|
||||
}
|
||||
|
||||
return window?.location?.protocol ?? "http:"
|
||||
}
|
||||
|
||||
const envOrigins = {
|
||||
"development": `http://${getCurrentHostname()}:9000`,
|
||||
"development": `${getCurrentProtocol()}//${getCurrentHostname()}:9000`,
|
||||
"indev": "https://indev_api.comty.app",
|
||||
"production": "https://api.comty.app",
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user