diff --git a/src/subsonic/index.ts b/src/subsonic/index.ts index c3e71ca..d6cd1c8 100644 --- a/src/subsonic/index.ts +++ b/src/subsonic/index.ts @@ -5,7 +5,7 @@ import axios from "axios"; import randomstring from "randomstring"; import _ from "underscore"; // todo: rename http2 to http -import { Http, http as http2 } from "../http"; +import { Http, http as http2, RequestParams } from "../http"; import { Credentials, @@ -17,7 +17,7 @@ import { import { b64Encode, b64Decode } from "../b64"; import { axiosImageFetcher, ImageFetcher } from "../images"; import { navidromeMusicLibrary, SubsonicGenericMusicLibrary } from "./library"; -import { getJSON as getJSON2 } from "./subsonic_http"; +import { getJSON as getJSON } from "./subsonic_http"; export const t = (password: string, s: string) => Md5.hashStr(`${password}${s}`); @@ -126,16 +126,14 @@ export class Subsonic implements MusicService { }, }); - getJSON = async ( - credentials: Credentials, - url: string, - params: {} = {} - ): Promise => getJSON2(http2(this.authenticatedSubsonicHttp(credentials), { url, params })); + GET = (query: Partial) => ({ + asJSON: () => getJSON(http2(this.subsonicHttp, query)), + }); generateToken = (credentials: Credentials) => pipe( TE.tryCatch( - () => getJSON2(http2(this.authenticatedSubsonicHttp(credentials), { url: "/rest/ping.view" })), + () => getJSON(http2(this.authenticatedSubsonicHttp(credentials), { url: "/rest/ping.view" })), (e) => new AuthFailure(e as string) ), TE.chain(({ type }) => diff --git a/src/subsonic/library.ts b/src/subsonic/library.ts index e1f2ce7..8866a70 100644 --- a/src/subsonic/library.ts +++ b/src/subsonic/library.ts @@ -38,9 +38,8 @@ import { import axios from "axios"; import { asURLSearchParams } from "../utils"; import { artistSummaryFromNDArtist, NDArtist } from "./navidrome"; -//todo: rename http2 -> http -import { Http, http as http2, RequestParams } from "../http"; -import { getRaw2, getJSON as getJSON2 } from "./subsonic_http"; +import { Http, http as newHttp, RequestParams } from "../http"; +import { getRaw2, getJSON } from "./subsonic_http"; type album = { id: string; @@ -288,8 +287,8 @@ export class SubsonicGenericMusicLibrary implements SubsonicMusicLibrary { } GET = (query: Partial) => ({ - asRAW: () => getRaw2(http2(this.subsonicHttp, query)), - asJSON: () => getJSON2(http2(this.subsonicHttp, query)), + asRAW: () => getRaw2(newHttp(this.subsonicHttp, query)), + asJSON: () => getJSON(newHttp(this.subsonicHttp, query)), }); flavour = () => "subsonic"; diff --git a/src/subsonic/subsonic_http.ts b/src/subsonic/subsonic_http.ts index 4ed9a81..bb57e41 100644 --- a/src/subsonic/subsonic_http.ts +++ b/src/subsonic/subsonic_http.ts @@ -3,7 +3,7 @@ import { SubsonicEnvelope, } from "."; // todo: rename http2 to http -import { Http, http as http2 } from "../http"; +import { Http, http as newHttp } from "../http"; export type HttpResponse = { data: any; @@ -23,7 +23,7 @@ export const getRaw2 = (http: Http) => }); export const getJSON = async (http: Http): Promise => - getRaw2(http2(http, { params: { f: "json" } })).then(asJSON) as Promise; + getRaw2(newHttp(http, { params: { f: "json" } })).then(asJSON) as Promise; export const asJSON = (response: HttpResponse): T => { const subsonicResponse = (response.data as SubsonicEnvelope)[ @@ -35,3 +35,4 @@ export const asJSON = (response: HttpResponse): T => { }; +