mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +00:00
use new api model
This commit is contained in:
parent
791ff3b089
commit
fb72644374
@ -40,7 +40,7 @@ export default {
|
||||
const [serverManifest, setServerManifest] = React.useState(null)
|
||||
|
||||
const checkServerVersion = async () => {
|
||||
const serverManifest = await app.cores.api.customRequest("main")
|
||||
const serverManifest = await app.cores.api.customRequest()
|
||||
|
||||
setServerManifest(serverManifest.data)
|
||||
}
|
||||
|
@ -518,19 +518,7 @@ class ComtyApp extends React.Component {
|
||||
const initializationTasks = [
|
||||
async () => {
|
||||
try {
|
||||
// get remotes origins from config
|
||||
const defaultRemotes = config.remotes
|
||||
|
||||
// get storaged remotes origins
|
||||
const storedRemotes = await app.cores.settings.get("remotes") ?? {}
|
||||
|
||||
// mount main api bridge
|
||||
await this.props.cores.ApiCore.attachBridge("main", {
|
||||
origin: storedRemotes.mainApi ?? defaultRemotes.mainApi,
|
||||
locked: true,
|
||||
})
|
||||
|
||||
await this.props.cores.ApiCore.namespaces["main"].initialize()
|
||||
await this.props.cores.ApiCore.attach()
|
||||
|
||||
app.eventBus.emit("app.initialization.api_success")
|
||||
} catch (error) {
|
||||
|
@ -71,7 +71,7 @@ export default class UserDataManager extends React.Component {
|
||||
loading: false,
|
||||
}
|
||||
|
||||
api = window.app.cores.api.withEndpoints("main")
|
||||
api = window.app.cores.api.withEndpoints()
|
||||
|
||||
componentDidMount = async () => {
|
||||
if (!this.props.user && this.props.userId) {
|
||||
|
@ -12,7 +12,7 @@ export default class UserRolesManager extends React.Component {
|
||||
roles: null,
|
||||
}
|
||||
|
||||
api = window.app.cores.api.withEndpoints("main")
|
||||
api = window.app.cores.api.withEndpoints()
|
||||
|
||||
componentDidMount = async () => {
|
||||
await this.fetchRoles()
|
||||
|
@ -104,12 +104,13 @@ export default (props) => {
|
||||
}
|
||||
|
||||
const listenEvents = () => {
|
||||
window.app.cores.api.namespaces["main"].listenEvent(`post.new.comment.${props.post_id}`, (comment) => {
|
||||
app.cores.api.listenEvent(`post.new.comment.${props.post_id}`, (comment) => {
|
||||
setComments((comments) => {
|
||||
return [comment, ...comments]
|
||||
})
|
||||
})
|
||||
window.app.cores.api.namespaces["main"].listenEvent(`post.delete.comment.${props.post_id}`, (comment_id) => {
|
||||
|
||||
app.cores.api.listenEvent(`post.delete.comment.${props.post_id}`, (comment_id) => {
|
||||
setComments((comments) => {
|
||||
return comments.filter((comment) => comment._id !== comment_id)
|
||||
})
|
||||
@ -117,8 +118,8 @@ export default (props) => {
|
||||
}
|
||||
|
||||
const unlistenEvents = () => {
|
||||
window.app.cores.api.namespaces["main"].unlistenEvent(`post.new.comment.${props.post_id}`)
|
||||
window.app.cores.api.namespaces["main"].unlistenEvent(`post.delete.comment.${props.post_id}`)
|
||||
app.cores.api.unlistenEvent(`post.new.comment.${props.post_id}`)
|
||||
app.cores.api.unlistenEvent(`post.delete.comment.${props.post_id}`)
|
||||
}
|
||||
|
||||
React.useEffect(() => {
|
||||
|
@ -35,12 +35,12 @@ export default (props) => {
|
||||
fetchConnectedFriends()
|
||||
|
||||
for (const [event, callback] of Object.entries(wsEvents)) {
|
||||
window.app.cores.api.namespaces["main"].listenEvent(event, callback)
|
||||
app.cores.api.listenEvent(event, callback)
|
||||
}
|
||||
|
||||
return () => {
|
||||
for (const [event, callback] of Object.entries(wsEvents)) {
|
||||
window.app.cores.api.namespaces["main"].unlistenEvent(event, callback)
|
||||
app.cores.api.unlistenEvent(event, callback)
|
||||
}
|
||||
}
|
||||
}, [])
|
||||
|
@ -8,7 +8,7 @@ export default React.memo((props) => {
|
||||
const [featuredEvents, setFeaturedEvents] = React.useState([])
|
||||
|
||||
const fetchFeaturedEvents = React.useCallback(async () => {
|
||||
let { data } = await app.cores.api.customRequest("main", {
|
||||
let { data } = await app.cores.api.customRequest({
|
||||
url: "/featured_events",
|
||||
method: "GET"
|
||||
}).catch((err) => {
|
||||
|
@ -12,7 +12,7 @@ export default class ImageUploader extends React.Component {
|
||||
urlList: [],
|
||||
}
|
||||
|
||||
api = window.app.cores.api.withEndpoints("main")
|
||||
api = window.app.cores.api.withEndpoints()
|
||||
|
||||
handleChange = ({ fileList }) => {
|
||||
this.setState({ fileList })
|
||||
|
@ -103,8 +103,7 @@ export default class PostCard extends React.Component {
|
||||
app.eventBus.on(`post.${this.state.data._id}.update`, this.onClickEdit)
|
||||
|
||||
// first listen to post changes
|
||||
//window.app.cores.api.namespaces["main"].listenEvent(`post.dataUpdate.${data._id}`, onDataUpdate)
|
||||
window.app.cores.api.namespaces["main"].listenEvent(`post.${this.state.data._id}.likes.update`, this.onLikesUpdate)
|
||||
app.cores.api.listenEvent(`post.${this.state.data._id}.likes.update`, this.onLikesUpdate)
|
||||
|
||||
this.setState({
|
||||
isSelf: app.cores.permissions.checkUserIdIsSelf(this.state.data.user_id),
|
||||
@ -117,8 +116,7 @@ export default class PostCard extends React.Component {
|
||||
app.eventBus.off(`post.${this.state.data._id}.update`, this.onClickEdit)
|
||||
|
||||
// remove the listener
|
||||
//window.app.cores.api.namespaces["main"].unlistenEvent(`post.dataUpdate.${data._id}`, onDataUpdate)
|
||||
window.app.cores.api.namespaces["main"].listenEvent(`post.${this.state.data._id}.likes.update`, this.onLikesUpdate)
|
||||
app.cores.api.listenEvent(`post.${this.state.data._id}.likes.update`, this.onLikesUpdate)
|
||||
}
|
||||
|
||||
componentDidCatch = (error, info) => {
|
||||
|
@ -18,7 +18,7 @@ const DEFAULT_POST_POLICY = {
|
||||
}
|
||||
|
||||
export default (props) => {
|
||||
const api = window.app.cores.api.withEndpoints("main")
|
||||
const api = window.app.cores.api.withEndpoints()
|
||||
|
||||
const creatorRef = React.useRef(null)
|
||||
|
||||
|
@ -13,7 +13,7 @@ export default (props) => {
|
||||
|
||||
formData.append("files", req.file)
|
||||
|
||||
const response = await window.app.cores.api.customRequest("main", {
|
||||
const response = await window.app.cores.api.customRequest( {
|
||||
url: "/upload",
|
||||
method: "POST",
|
||||
data: formData
|
||||
|
@ -90,7 +90,7 @@ const steps = [
|
||||
return
|
||||
}
|
||||
|
||||
const request = await app.cores.api.customRequest("main", {
|
||||
const request = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: "/user/username-available",
|
||||
params: {
|
||||
@ -308,7 +308,7 @@ const steps = [
|
||||
const timer = setTimeout(async () => {
|
||||
if (!validFormat) return
|
||||
|
||||
const request = await app.cores.api.customRequest("main", {
|
||||
const request = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: "/user/email-available",
|
||||
params: {
|
||||
|
@ -14,7 +14,7 @@ export default class UserSelector extends React.Component {
|
||||
searchValue: null,
|
||||
}
|
||||
|
||||
api = window.app.cores.api.withEndpoints("main")
|
||||
api = window.app.cores.api.withEndpoints()
|
||||
|
||||
componentDidMount = async () => {
|
||||
this.toogleLoading(true)
|
||||
|
@ -49,39 +49,54 @@ function generateWSFunctionHandler(socket, type = "listen") {
|
||||
|
||||
export default class ApiCore extends Core {
|
||||
static namespace = "api"
|
||||
static depends = ["settings"]
|
||||
|
||||
excludedExpiredExceptionURL = ["/session/regenerate"]
|
||||
|
||||
onExpiredExceptionEvent = false
|
||||
|
||||
namespaces = Object()
|
||||
instance = null
|
||||
|
||||
public = {
|
||||
namespaces: this.namespaces,
|
||||
customRequest: this.customRequest,
|
||||
request: this.request,
|
||||
withEndpoints: this.withEndpoints,
|
||||
attachBridge: this.attachBridge,
|
||||
detachBridge: this.detachBridge,
|
||||
createBridge: this.createBridge,
|
||||
autenticateWS: this.autenticateWS,
|
||||
instance: function () {
|
||||
return this.instance
|
||||
}.bind(this),
|
||||
customRequest: this.customRequest.bind(this),
|
||||
request: this.request.bind(this),
|
||||
withEndpoints: this.withEndpoints.bind(this),
|
||||
attach: this.attach.bind(this),
|
||||
createBridge: this.createBridge.bind(this),
|
||||
autenticateWS: this.autenticateWS.bind(this),
|
||||
listenEvent: this.listenEvent.bind(this),
|
||||
unlistenEvent: this.unlistenEvent.bind(this),
|
||||
}
|
||||
|
||||
async attach() {
|
||||
// get remotes origins from config
|
||||
const defaultRemotes = config.remotes
|
||||
|
||||
// get storaged remotes origins
|
||||
const storedRemotes = await app.cores.settings.get("remotes") ?? {}
|
||||
|
||||
const origin = storedRemotes.mainApi ?? defaultRemotes.mainApi
|
||||
|
||||
this.instance = this.createBridge({
|
||||
origin,
|
||||
})
|
||||
|
||||
await this.instance.initialize()
|
||||
|
||||
console.debug(`[API] Attached to ${origin}`, this.instance)
|
||||
|
||||
return this.instance
|
||||
}
|
||||
|
||||
async customRequest(
|
||||
namepace = undefined,
|
||||
payload = {
|
||||
method: "GET",
|
||||
},
|
||||
...args
|
||||
) {
|
||||
if (typeof namepace === "undefined") {
|
||||
throw new Error("Namespace must be defined")
|
||||
}
|
||||
|
||||
if (typeof this.namespaces[namepace] === "undefined") {
|
||||
throw new Error("Namespace not found")
|
||||
}
|
||||
|
||||
if (typeof payload === "string") {
|
||||
payload = {
|
||||
url: payload,
|
||||
@ -101,31 +116,15 @@ export default class ApiCore extends Core {
|
||||
console.warn("Making a request with no session token")
|
||||
}
|
||||
|
||||
return await this.namespaces[namepace].httpInterface(payload, ...args)
|
||||
return await this.instance.httpInterface(payload, ...args)
|
||||
}
|
||||
|
||||
request(namespace = "main", method, endpoint, ...args) {
|
||||
if (!this.namespaces[namespace]) {
|
||||
throw new Error(`Namespace ${namespace} not found`)
|
||||
}
|
||||
|
||||
if (!this.namespaces[namespace].endpoints[method]) {
|
||||
throw new Error(`Method ${method} not found`)
|
||||
}
|
||||
|
||||
if (!this.namespaces[namespace].endpoints[method][endpoint]) {
|
||||
throw new Error(`Endpoint ${endpoint} not found`)
|
||||
}
|
||||
|
||||
return this.namespaces[namespace].endpoints[method][endpoint](...args)
|
||||
request(method, endpoint, ...args) {
|
||||
return this.instance.endpoints[method][endpoint](...args)
|
||||
}
|
||||
|
||||
withEndpoints(namespace = "main") {
|
||||
if (!this.namespaces[namespace]) {
|
||||
throw new Error(`Namespace ${namespace} not found`)
|
||||
}
|
||||
|
||||
return this.namespaces[namespace].endpoints
|
||||
withEndpoints() {
|
||||
return this.instance.endpoints
|
||||
}
|
||||
|
||||
async handleBeforeRequest(request) {
|
||||
@ -149,7 +148,7 @@ export default class ApiCore extends Core {
|
||||
const expiredToken = await SessionModel.token
|
||||
|
||||
// send request to regenerate token
|
||||
const response = await this.customRequest("main", {
|
||||
const response = await this.customRequest({
|
||||
method: "POST",
|
||||
url: "/session/regenerate",
|
||||
data: {
|
||||
@ -176,14 +175,6 @@ export default class ApiCore extends Core {
|
||||
window.app.eventBus.emit("session.regenerated")
|
||||
}
|
||||
|
||||
attachBridge(key, params) {
|
||||
return this.namespaces[key] = this.createBridge(params)
|
||||
}
|
||||
|
||||
detachBridge(key) {
|
||||
return delete this.namespaces[key]
|
||||
}
|
||||
|
||||
createBridge(params = {}) {
|
||||
const getSessionContext = async () => {
|
||||
const obj = {}
|
||||
@ -236,51 +227,74 @@ export default class ApiCore extends Core {
|
||||
const bridge = new Bridge(bridgeOptions)
|
||||
|
||||
// handle main ws onEvents
|
||||
const mainWSSocket = bridge.wsInterface.sockets["main"]
|
||||
const mainSocket = bridge.wsInterface.sockets["main"]
|
||||
|
||||
mainWSSocket.on("authenticated", () => {
|
||||
mainSocket.on("authenticated", () => {
|
||||
console.debug("[WS] Authenticated")
|
||||
})
|
||||
|
||||
mainWSSocket.on("authenticateFailed", (error) => {
|
||||
mainSocket.on("authenticateFailed", (error) => {
|
||||
console.error("[WS] Authenticate Failed", error)
|
||||
})
|
||||
|
||||
mainWSSocket.on("connect", () => {
|
||||
mainSocket.on("connect", () => {
|
||||
if (this.ctx.eventBus) {
|
||||
this.ctx.eventBus.emit(`api.ws.main.connect`)
|
||||
}
|
||||
|
||||
this.autenticateWS(mainWSSocket)
|
||||
console.debug("[WS] Connected, authenticating...")
|
||||
|
||||
this.autenticateWS(mainSocket)
|
||||
})
|
||||
|
||||
mainWSSocket.on("disconnect", (...context) => {
|
||||
mainSocket.on("disconnect", (...context) => {
|
||||
if (this.ctx.eventBus) {
|
||||
this.ctx.eventBus.emit(`api.ws.main.disconnect`, ...context)
|
||||
}
|
||||
})
|
||||
|
||||
mainWSSocket.on("connect_error", (...context) => {
|
||||
mainSocket.on("connect_error", (...context) => {
|
||||
if (this.ctx.eventBus) {
|
||||
this.ctx.eventBus.emit(`api.ws.main.connect_error`, ...context)
|
||||
}
|
||||
})
|
||||
|
||||
// generate functions
|
||||
bridge.listenEvent = generateWSFunctionHandler(bridge.wsInterface, "listen")
|
||||
bridge.unlistenEvent = generateWSFunctionHandler(bridge.wsInterface, "unlisten")
|
||||
mainSocket.onAny((event, ...args) => {
|
||||
console.debug(`[WS] Recived Event (${event})`, ...args)
|
||||
})
|
||||
|
||||
// mainSocket.onAnyOutgoing((event, ...args) => {
|
||||
// console.debug(`[WS] Sent Event (${event})`, ...args)
|
||||
// })
|
||||
|
||||
// return bridge
|
||||
return bridge
|
||||
}
|
||||
|
||||
listenEvent(event, callback) {
|
||||
if (!this.instance.wsInterface) {
|
||||
throw new Error("API is not attached")
|
||||
}
|
||||
|
||||
return this.instance.wsInterface.sockets["main"].on(event, callback)
|
||||
}
|
||||
|
||||
unlistenEvent(event, callback) {
|
||||
if (!this.instance.wsInterface) {
|
||||
throw new Error("API is not attached")
|
||||
}
|
||||
|
||||
return this.instance.wsInterface.sockets["main"].off(event, callback)
|
||||
}
|
||||
|
||||
async autenticateWS(socket) {
|
||||
const token = await SessionModel.token
|
||||
|
||||
if (token) {
|
||||
socket.emit("authenticate", {
|
||||
token,
|
||||
})
|
||||
if (!token) {
|
||||
return console.error("Failed to authenticate WS, no token found")
|
||||
}
|
||||
|
||||
socket.emit("authenticate", {
|
||||
token,
|
||||
})
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ import SessionModel from "../session"
|
||||
|
||||
export default class AuthModel {
|
||||
static login = async (payload) => {
|
||||
const response = await app.cores.api.customRequest("main", {
|
||||
const response = await app.cores.api.customRequest( {
|
||||
method: "post",
|
||||
url: "/auth/login",
|
||||
data: {
|
||||
|
@ -1,6 +1,6 @@
|
||||
export default class FeedModel {
|
||||
static get bridge() {
|
||||
return window.app?.cores.api.withEndpoints("main")
|
||||
return window.app?.cores.api.withEndpoints()
|
||||
}
|
||||
|
||||
static async getPostsFeed({ trim, limit }) {
|
||||
@ -8,7 +8,7 @@ export default class FeedModel {
|
||||
throw new Error("Bridge is not available")
|
||||
}
|
||||
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/feed/posts`,
|
||||
params: {
|
||||
@ -25,7 +25,7 @@ export default class FeedModel {
|
||||
throw new Error("Bridge is not available")
|
||||
}
|
||||
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/feed/playlists`,
|
||||
params: {
|
||||
@ -42,7 +42,7 @@ export default class FeedModel {
|
||||
throw new Error("Bridge is not available")
|
||||
}
|
||||
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/search`,
|
||||
params: {
|
||||
|
@ -6,7 +6,7 @@ export default class FollowsModel {
|
||||
throw new Error("user_id is required")
|
||||
}
|
||||
|
||||
const response = await app.cores.api.customRequest("main", {
|
||||
const response = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/follow/user/${user_id}`,
|
||||
})
|
||||
@ -20,7 +20,7 @@ export default class FollowsModel {
|
||||
user_id = SessionModel.user_id
|
||||
}
|
||||
|
||||
const response = await app.cores.api.customRequest("main", {
|
||||
const response = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/follow/user/${user_id}/followers`,
|
||||
})
|
||||
@ -33,7 +33,7 @@ export default class FollowsModel {
|
||||
throw new Error("user_id or username is required")
|
||||
}
|
||||
|
||||
const response = await app.cores.api.customRequest("main", {
|
||||
const response = await app.cores.api.customRequest( {
|
||||
method: "POST",
|
||||
url: "/follow/user/toogle",
|
||||
data: {
|
||||
|
@ -1,6 +1,6 @@
|
||||
export default class Livestream {
|
||||
static async getStreamingKey() {
|
||||
const request = await app.cores.api.customRequest("main", {
|
||||
const request = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/tv/streaming/key`,
|
||||
})
|
||||
@ -9,7 +9,7 @@ export default class Livestream {
|
||||
}
|
||||
|
||||
static async regenerateStreamingKey() {
|
||||
const request = await app.cores.api.customRequest("main", {
|
||||
const request = await app.cores.api.customRequest( {
|
||||
method: "POST",
|
||||
url: `/tv/streaming/key/regenerate`,
|
||||
|
||||
@ -19,7 +19,7 @@ export default class Livestream {
|
||||
}
|
||||
|
||||
static async updateLivestreamInfo(payload) {
|
||||
const request = await app.cores.api.customRequest("main", {
|
||||
const request = await app.cores.api.customRequest( {
|
||||
method: "POST",
|
||||
url: `/tv/stream/info`,
|
||||
data: {
|
||||
@ -31,7 +31,7 @@ export default class Livestream {
|
||||
}
|
||||
|
||||
static async getCategories(key) {
|
||||
const request = await app.cores.api.customRequest("main", {
|
||||
const request = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/tv/streaming/categories`,
|
||||
params: {
|
||||
@ -49,7 +49,7 @@ export default class Livestream {
|
||||
username = app.userData.username
|
||||
}
|
||||
|
||||
const request = await app.cores.api.customRequest("main", {
|
||||
const request = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/tv/stream/info`,
|
||||
params: {
|
||||
@ -65,7 +65,7 @@ export default class Livestream {
|
||||
throw new Error("Username is required")
|
||||
}
|
||||
|
||||
let request = await app.cores.api.customRequest("main", {
|
||||
let request = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/tv/streams`,
|
||||
params: {
|
||||
@ -77,7 +77,7 @@ export default class Livestream {
|
||||
}
|
||||
|
||||
static async getAddresses() {
|
||||
const request = await app.cores.api.customRequest("main", {
|
||||
const request = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/tv/streaming/addresses`,
|
||||
})
|
||||
@ -86,7 +86,7 @@ export default class Livestream {
|
||||
}
|
||||
|
||||
static async getLivestreams() {
|
||||
const request = await app.cores.api.customRequest("main", {
|
||||
const request = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/tv/streams`,
|
||||
})
|
||||
|
@ -1,10 +1,10 @@
|
||||
export class MusicModel {
|
||||
static get bridge() {
|
||||
return window.app?.cores.api.withEndpoints("main")
|
||||
return window.app?.cores.api.withEndpoints()
|
||||
}
|
||||
|
||||
static async createSpaceRoom() {
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "post",
|
||||
url: `/music/create_space_room`,
|
||||
})
|
||||
|
@ -1,6 +1,6 @@
|
||||
export default class PlaylistsModel {
|
||||
static get bridge() {
|
||||
return window.app?.cores.api.withEndpoints("main")
|
||||
return window.app?.cores.api.withEndpoints()
|
||||
}
|
||||
|
||||
static async uploadTrack(file, payload) {
|
||||
@ -22,7 +22,7 @@ export default class PlaylistsModel {
|
||||
formData.append("files", file)
|
||||
|
||||
// send the request
|
||||
const uploadRequest = await app.cores.api.customRequest("main", {
|
||||
const uploadRequest = await app.cores.api.customRequest( {
|
||||
method: "POST",
|
||||
url: "/upload",
|
||||
data: formData,
|
||||
@ -38,7 +38,7 @@ export default class PlaylistsModel {
|
||||
const source = uploadRequest.data.files[0].url
|
||||
|
||||
// send the request for the track to be created
|
||||
const trackRequest = await app.cores.api.customRequest("main", {
|
||||
const trackRequest = await app.cores.api.customRequest( {
|
||||
method: "POST",
|
||||
url: "/tracks/publish",
|
||||
data: {
|
||||
@ -51,7 +51,7 @@ export default class PlaylistsModel {
|
||||
}
|
||||
|
||||
static async publishTrack(payload) {
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "POST",
|
||||
url: "/tracks/publish",
|
||||
data: payload,
|
||||
@ -61,7 +61,7 @@ export default class PlaylistsModel {
|
||||
}
|
||||
|
||||
static async publish(payload) {
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "POST",
|
||||
url: `/playlist/publish`,
|
||||
data: payload,
|
||||
@ -71,7 +71,7 @@ export default class PlaylistsModel {
|
||||
}
|
||||
|
||||
static async getPlaylist(id) {
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/playlist/data/${id}`,
|
||||
})
|
||||
@ -80,7 +80,7 @@ export default class PlaylistsModel {
|
||||
}
|
||||
|
||||
static async getMyReleases() {
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/playlist/self`,
|
||||
})
|
||||
@ -93,7 +93,7 @@ export default class PlaylistsModel {
|
||||
throw new Error("Payload is required")
|
||||
}
|
||||
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "PUT",
|
||||
url: `/tracks/${payload._id}`,
|
||||
data: {
|
||||
@ -109,7 +109,7 @@ export default class PlaylistsModel {
|
||||
throw new Error("Payload is required")
|
||||
}
|
||||
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "PUT",
|
||||
url: `/playlist/${payload._id}`,
|
||||
data: {
|
||||
@ -125,7 +125,7 @@ export default class PlaylistsModel {
|
||||
throw new Error("ID is required")
|
||||
}
|
||||
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "DELETE",
|
||||
url: `/playlist/${id}`,
|
||||
})
|
||||
|
@ -1,6 +1,6 @@
|
||||
export default class Post {
|
||||
static get bridge() {
|
||||
return window.app?.cores.api.withEndpoints("main")
|
||||
return window.app?.cores.api.withEndpoints()
|
||||
}
|
||||
|
||||
static get maxPostTextLength() {
|
||||
@ -16,7 +16,7 @@ export default class Post {
|
||||
throw new Error("Post ID is required")
|
||||
}
|
||||
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/posts/post/${post_id}`,
|
||||
})
|
||||
@ -29,7 +29,7 @@ export default class Post {
|
||||
throw new Error("Post ID is required")
|
||||
}
|
||||
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/comments/post/${post_id}`,
|
||||
})
|
||||
@ -42,7 +42,7 @@ export default class Post {
|
||||
throw new Error("Post ID and/or comment are required")
|
||||
}
|
||||
|
||||
const request = await app.cores.apies.api.customRequest("main", {
|
||||
const request = await app.cores.apies.api.customRequest( {
|
||||
method: "POST",
|
||||
url: `/comments/post/${post_id}`,
|
||||
data: {
|
||||
@ -58,7 +58,7 @@ export default class Post {
|
||||
throw new Error("Post ID and/or comment ID are required")
|
||||
}
|
||||
|
||||
const request = await app.cores.apies.api.customRequest("main", {
|
||||
const request = await app.cores.apies.api.customRequest( {
|
||||
method: "DELETE",
|
||||
url: `/comments/post/${post_id}/${comment_id}`,
|
||||
})
|
||||
@ -71,7 +71,7 @@ export default class Post {
|
||||
throw new Error("Bridge is not available")
|
||||
}
|
||||
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/posts/explore`,
|
||||
params: {
|
||||
@ -88,7 +88,7 @@ export default class Post {
|
||||
throw new Error("Bridge is not available")
|
||||
}
|
||||
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/posts/saved`,
|
||||
params: {
|
||||
@ -110,7 +110,7 @@ export default class Post {
|
||||
user_id = app.userData?._id
|
||||
}
|
||||
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/posts/user/${user_id}`,
|
||||
params: {
|
||||
@ -131,7 +131,7 @@ export default class Post {
|
||||
throw new Error("Post ID is required")
|
||||
}
|
||||
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "POST",
|
||||
url: `/posts/${post_id}/toogle_like`,
|
||||
})
|
||||
@ -148,7 +148,7 @@ export default class Post {
|
||||
throw new Error("Post ID is required")
|
||||
}
|
||||
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "POST",
|
||||
url: `/posts/${post_id}/toogle_save`,
|
||||
})
|
||||
@ -161,7 +161,7 @@ export default class Post {
|
||||
throw new Error("Bridge is not available")
|
||||
}
|
||||
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "POST",
|
||||
url: `/posts/new`,
|
||||
data: payload,
|
||||
@ -179,7 +179,7 @@ export default class Post {
|
||||
throw new Error("Post ID is required")
|
||||
}
|
||||
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "DELETE",
|
||||
url: `/posts/${post_id}`,
|
||||
})
|
||||
|
@ -28,7 +28,7 @@ export default class Session {
|
||||
}
|
||||
|
||||
static async getAllSessions() {
|
||||
const response = await app.cores.api.customRequest("main", {
|
||||
const response = await app.cores.api.customRequest( {
|
||||
method: "get",
|
||||
url: "/session/all"
|
||||
})
|
||||
@ -37,7 +37,7 @@ export default class Session {
|
||||
}
|
||||
|
||||
static async getCurrentSession() {
|
||||
const response = await app.cores.api.customRequest("main", {
|
||||
const response = await app.cores.api.customRequest( {
|
||||
method: "get",
|
||||
url: "/session/current"
|
||||
})
|
||||
@ -48,7 +48,7 @@ export default class Session {
|
||||
static async getTokenValidation() {
|
||||
const session = await Session.token
|
||||
|
||||
const response = await app.cores.api.customRequest("main", {
|
||||
const response = await app.cores.api.customRequest( {
|
||||
method: "get",
|
||||
url: "/session/validate",
|
||||
data: {
|
||||
@ -71,7 +71,7 @@ export default class Session {
|
||||
return false
|
||||
}
|
||||
|
||||
const response = await app.cores.api.customRequest("main", {
|
||||
const response = await app.cores.api.customRequest( {
|
||||
method: "delete",
|
||||
url: "/session/current"
|
||||
}).catch((error) => {
|
||||
@ -94,7 +94,7 @@ export default class Session {
|
||||
return false
|
||||
}
|
||||
|
||||
const response = await app.cores.api.customRequest("main", {
|
||||
const response = await app.cores.api.customRequest( {
|
||||
method: "delete",
|
||||
url: "/session/all"
|
||||
})
|
||||
|
@ -28,7 +28,7 @@ export default class SpotifySyncModel {
|
||||
}
|
||||
|
||||
static async get_client_id() {
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/sync/spotify/client_id`,
|
||||
})
|
||||
@ -37,7 +37,7 @@ export default class SpotifySyncModel {
|
||||
}
|
||||
|
||||
static async syncAuthCode(code) {
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "POST",
|
||||
url: `/sync/spotify/auth`,
|
||||
data: {
|
||||
@ -50,7 +50,7 @@ export default class SpotifySyncModel {
|
||||
}
|
||||
|
||||
static async unlinkAccount() {
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "POST",
|
||||
url: `/sync/spotify/unlink`,
|
||||
})
|
||||
@ -59,7 +59,7 @@ export default class SpotifySyncModel {
|
||||
}
|
||||
|
||||
static async isAuthorized() {
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/sync/spotify/is_authorized`,
|
||||
})
|
||||
@ -68,7 +68,7 @@ export default class SpotifySyncModel {
|
||||
}
|
||||
|
||||
static async getData() {
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/sync/spotify/data`,
|
||||
})
|
||||
@ -77,7 +77,7 @@ export default class SpotifySyncModel {
|
||||
}
|
||||
|
||||
static async getCurrentPlaying() {
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/sync/spotify/currently_playing`,
|
||||
})
|
||||
|
@ -2,7 +2,7 @@ import SpotifySyncModel from "./cores/spotifyCore"
|
||||
|
||||
export default class SyncModel {
|
||||
static get bridge() {
|
||||
return window.app?.cores.api.withEndpoints("main")
|
||||
return window.app?.cores.api.withEndpoints()
|
||||
}
|
||||
|
||||
static get spotifyCore() {
|
||||
|
@ -12,7 +12,7 @@ export default class UploadModel {
|
||||
formData.append("files", file)
|
||||
|
||||
// send the request
|
||||
const uploadRequest = await app.cores.api.customRequest("main", {
|
||||
const uploadRequest = await app.cores.api.customRequest( {
|
||||
method: "POST",
|
||||
url: "/upload",
|
||||
data: formData,
|
||||
|
@ -13,7 +13,7 @@ export default class User {
|
||||
|
||||
if (username && !user_id) {
|
||||
// resolve user_id from username
|
||||
const resolveResponse = await app.cores.api.customRequest("main", {
|
||||
const resolveResponse = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/user/user_id/${username}`,
|
||||
})
|
||||
@ -21,7 +21,7 @@ export default class User {
|
||||
user_id = resolveResponse.data.user_id
|
||||
}
|
||||
|
||||
const response = await app.cores.api.customRequest("main", {
|
||||
const response = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/user/${user_id}/data`,
|
||||
})
|
||||
@ -30,7 +30,7 @@ export default class User {
|
||||
}
|
||||
|
||||
static async updateData(payload) {
|
||||
const response = await app.cores.api.customRequest("main", {
|
||||
const response = await app.cores.api.customRequest( {
|
||||
method: "POST",
|
||||
url: "/user/self/update_data",
|
||||
data: {
|
||||
@ -42,7 +42,7 @@ export default class User {
|
||||
}
|
||||
|
||||
static async unsetFullName() {
|
||||
const response = await app.cores.api.customRequest("main", {
|
||||
const response = await app.cores.api.customRequest( {
|
||||
method: "DELETE",
|
||||
url: "/user/self/public_name",
|
||||
})
|
||||
@ -51,7 +51,7 @@ export default class User {
|
||||
}
|
||||
|
||||
static async selfRoles() {
|
||||
const response = await app.cores.api.customRequest("main", {
|
||||
const response = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: "/roles/self",
|
||||
})
|
||||
@ -78,7 +78,7 @@ export default class User {
|
||||
user_id = SessionModel.user_id
|
||||
}
|
||||
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/badge/user/${user_id}`,
|
||||
})
|
||||
@ -89,7 +89,7 @@ export default class User {
|
||||
static async changePassword(payload) {
|
||||
const { currentPassword, newPassword } = payload
|
||||
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "POST",
|
||||
url: "/self/update_password",
|
||||
data: {
|
||||
@ -111,7 +111,7 @@ export default class User {
|
||||
user_id = SessionModel.user_id
|
||||
}
|
||||
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/user/${user_id}/followers`,
|
||||
params: {
|
||||
@ -124,7 +124,7 @@ export default class User {
|
||||
}
|
||||
|
||||
static async getConnectedUsersFollowing() {
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: "/status/connected/following",
|
||||
})
|
||||
|
@ -74,7 +74,7 @@ export default class Account extends React.Component {
|
||||
|
||||
actionsRef = React.createRef()
|
||||
|
||||
api = window.app.cores.api.withEndpoints("main")
|
||||
api = window.app.cores.api.withEndpoints()
|
||||
|
||||
componentDidMount = async () => {
|
||||
const token = await SessionModel.getDecodedToken()
|
||||
|
@ -24,7 +24,7 @@ export default (props) => {
|
||||
const [eventData, setEventData] = React.useState(null)
|
||||
|
||||
const fetchEventData = async () => {
|
||||
const { data } = await app.cores.api.customRequest("main", {
|
||||
const { data } = await app.cores.api.customRequest( {
|
||||
method: "GET",
|
||||
url: `/featured_event/${eventId}`
|
||||
}).catch((err) => {
|
||||
|
@ -33,7 +33,7 @@ export default (props) => {
|
||||
const [wallpaperData, setWallpaperData] = React.useState(null)
|
||||
|
||||
const setRandomWallpaper = async () => {
|
||||
const featuredWallpapers = await app.cores.api.request("main", "get", "featuredWallpapers").catch((err) => {
|
||||
const featuredWallpapers = await app.cores.api.request("get", "featuredWallpapers").catch((err) => {
|
||||
console.error(err)
|
||||
return []
|
||||
})
|
||||
|
@ -92,13 +92,13 @@ export default class ExplorePosts extends React.Component {
|
||||
await this.loadPosts()
|
||||
|
||||
Object.keys(this.wsEvents).forEach((event) => {
|
||||
window.app.cores.api.namespaces["main"].listenEvent(event, this.wsEvents[event])
|
||||
app.cores.api.listenEvent(event, this.wsEvents[event])
|
||||
})
|
||||
}
|
||||
|
||||
componentWillUnmount = async () => {
|
||||
Object.keys(this.wsEvents).forEach((event) => {
|
||||
window.app.cores.api.namespaces["main"].unlistenEvent(event, this.wsEvents[event])
|
||||
app.cores.api.unlistenEvent(event, this.wsEvents[event])
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -90,13 +90,13 @@ export default class Feed extends React.Component {
|
||||
console.log(this.wsEvents)
|
||||
|
||||
Object.keys(this.wsEvents).forEach((event) => {
|
||||
window.app.cores.api.namespaces["main"].listenEvent(event, this.wsEvents[event])
|
||||
app.cores.api.listenEvent(event, this.wsEvents[event])
|
||||
})
|
||||
}
|
||||
|
||||
componentWillUnmount = async () => {
|
||||
Object.keys(this.wsEvents).forEach((event) => {
|
||||
window.app.cores.api.namespaces["main"].unlistenEvent(event, this.wsEvents[event])
|
||||
app.cores.api.unlistenEvent(event, this.wsEvents[event])
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user