Skip to content

Commit

Permalink
fix(preprocess): add new regex for GraphQL defs for >=1.2.31 (#2873)
Browse files Browse the repository at this point in the history
  • Loading branch information
rxri authored Mar 2, 2024
1 parent 7657d0a commit 931af1d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 4 additions & 2 deletions jsHelper/spicetifyWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -928,11 +928,13 @@ Spicetify.getAudioData = async uri => {
throw "URI is invalid.";
}

return await Spicetify.CosmosAsync.get(`wg://audio-attributes/v1/audio-analysis/${uriObj.getBase62Id?.() ?? uriObj.id}?format=json`);
return await Spicetify.CosmosAsync.get(
`https://spclient.wg.spotify.com/audio-attributes/v1/audio-analysis/${uriObj.getBase62Id?.() ?? uriObj.id}?format=json`
);
};

Spicetify.colorExtractor = async uri => {
const body = await Spicetify.CosmosAsync.get(`wg://colorextractor/v1/extract-presets?uri=${uri}&format=json`);
const body = await Spicetify.CosmosAsync.get(`https://spclient.wg.spotify.com/colorextractor/v1/extract-presets?uri=${uri}&format=json`);

if (body.entries?.length) {
const list = {};
Expand Down
10 changes: 9 additions & 1 deletion src/preprocess/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,14 +507,22 @@ func exposeAPIs_main(input string) string {
return ""
})

// GraphQL definitions
// GraphQL definitions <=1.2.30
utils.Replace(
&input,
`((?:\w+ ?)?[\w$]+=)(\{kind:"Document",definitions:\[\{(?:\w+:[\w"]+,)+name:\{(?:\w+:[\w"]+,?)+value:("\w+"))`,
func(submatches ...string) string {
return fmt.Sprintf("%sSpicetify.GraphQL.Definitions[%s]=%s", submatches[1], submatches[3], submatches[2])
})

// GraphQL definitons >=1.2.31
utils.Replace(
&input,
`(=new [\w_\$][\w_\$\d]*\.[\w_\$][\w_\$\d]*\("(\w+)","(query|mutation)","[\w\d]{64}",null\))`,
func(submatches ...string) string {
return fmt.Sprintf(`=Spicetify.GraphQL.Definitions["%s"]%s`, submatches[2], submatches[1])
})

utils.Replace(
&input,
`\b\w\s*\(\)\s*[^;,]*enqueueCustomSnackbar:\s*(\w)\s*[^;]*;`,
Expand Down

0 comments on commit 931af1d

Please sign in to comment.