mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-22 09:53:32 +01:00
more tidy
This commit is contained in:
@@ -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 <T>(
|
||||
credentials: Credentials,
|
||||
url: string,
|
||||
params: {} = {}
|
||||
): Promise<T> => getJSON2(http2(this.authenticatedSubsonicHttp(credentials), { url, params }));
|
||||
GET = (query: Partial<RequestParams>) => ({
|
||||
asJSON: <T>() => getJSON<T>(http2(this.subsonicHttp, query)),
|
||||
});
|
||||
|
||||
generateToken = (credentials: Credentials) =>
|
||||
pipe(
|
||||
TE.tryCatch(
|
||||
() => getJSON2<PingResponse>(http2(this.authenticatedSubsonicHttp(credentials), { url: "/rest/ping.view" })),
|
||||
() => getJSON<PingResponse>(http2(this.authenticatedSubsonicHttp(credentials), { url: "/rest/ping.view" })),
|
||||
(e) => new AuthFailure(e as string)
|
||||
),
|
||||
TE.chain(({ type }) =>
|
||||
|
||||
@@ -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<RequestParams>) => ({
|
||||
asRAW: () => getRaw2(http2(this.subsonicHttp, query)),
|
||||
asJSON: <T>() => getJSON2<T>(http2(this.subsonicHttp, query)),
|
||||
asRAW: () => getRaw2(newHttp(this.subsonicHttp, query)),
|
||||
asJSON: <T>() => getJSON<T>(newHttp(this.subsonicHttp, query)),
|
||||
});
|
||||
|
||||
flavour = () => "subsonic";
|
||||
|
||||
@@ -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 <T>(http: Http): Promise<T> =>
|
||||
getRaw2(http2(http, { params: { f: "json" } })).then(asJSON) as Promise<T>;
|
||||
getRaw2(newHttp(http, { params: { f: "json" } })).then(asJSON) as Promise<T>;
|
||||
|
||||
export const asJSON = <T>(response: HttpResponse): T => {
|
||||
const subsonicResponse = (response.data as SubsonicEnvelope)[
|
||||
@@ -35,3 +35,4 @@ export const asJSON = <T>(response: HttpResponse): T => {
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user