Skip to content

Commit 214e53a

Browse files
authored
Use graphql and fetch for backend and Spotify API (#15)
1 parent 4326c33 commit 214e53a

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"dependencies": {
1212
"beastsaber-api": "^2.2.1",
1313
"beatsaver-api": "^2.0.2",
14+
"gulp-util": "^3.0.8",
1415
"idb": "^7.0.0",
1516
"jquery": "^3.6.0",
1617
"rxjs": "^7.4.0",

src/core/api/ApiUtils.ts

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,33 @@ export class ApiUtils {
4242
}
4343

4444
async getArtist(uri: URI): Promise<ApiPartnerArtist> {
45+
if ("GraphQL" in Spicetify) {
46+
// @ts-expect-error: not in types
47+
const { GraphQL } = Spicetify
48+
const queryArtistOverview = {
49+
name: "queryArtistOverview",
50+
operation: "query",
51+
sha256Hash:
52+
"35648a112beb1794e39ab931365f6ae4a8d45e65396d641eeda94e4003d41497",
53+
value: null,
54+
}
55+
56+
const request = {
57+
uri: uri.toString(),
58+
locale: "",
59+
includePrerelease: false,
60+
}
61+
62+
const data: any = await GraphQL.Request(
63+
queryArtistOverview,
64+
request,
65+
{
66+
persistCache: true,
67+
}
68+
)
69+
return data.artistUnion as ApiPartnerArtist
70+
}
71+
4572
const vars = {
4673
uri: uri.toString(),
4774
locale: "",
@@ -112,17 +139,23 @@ export class ApiUtils {
112139
const headers = {
113140
Authorization: `Basic ${BeatSaber.Core.Settings.backendAuth}`,
114141
}
115-
const response = await Spicetify.CosmosAsync.get(url, null, headers)
116-
return response as unknown as T
142+
const response = await fetch(url, {
143+
method: "GET",
144+
headers,
145+
})
146+
return (await response.json()) as unknown as T
117147
}
118148

119149
async backendPost<T>(endpoint: string): Promise<T> {
120150
const url = `http://${BeatSaber.Core.Settings.backendHostname}${endpoint}`
121151
const headers = {
122152
Authorization: `Basic ${BeatSaber.Core.Settings.backendAuth}`,
123153
}
124-
const response = await Spicetify.CosmosAsync.post(url, null, headers)
125-
return response as unknown as T
154+
const response = await fetch(url, {
155+
method: "POST",
156+
headers,
157+
})
158+
return (await response.json()) as unknown as T
126159
}
127160

128161
async checkBackend(): Promise<string> {

0 commit comments

Comments
 (0)