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 randomstring from "randomstring";
|
||||||
import _ from "underscore";
|
import _ from "underscore";
|
||||||
// todo: rename http2 to http
|
// todo: rename http2 to http
|
||||||
import { Http, http as http2 } from "../http";
|
import { Http, http as http2, RequestParams } from "../http";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Credentials,
|
Credentials,
|
||||||
@@ -17,7 +17,7 @@ import {
|
|||||||
import { b64Encode, b64Decode } from "../b64";
|
import { b64Encode, b64Decode } from "../b64";
|
||||||
import { axiosImageFetcher, ImageFetcher } from "../images";
|
import { axiosImageFetcher, ImageFetcher } from "../images";
|
||||||
import { navidromeMusicLibrary, SubsonicGenericMusicLibrary } from "./library";
|
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) =>
|
export const t = (password: string, s: string) =>
|
||||||
Md5.hashStr(`${password}${s}`);
|
Md5.hashStr(`${password}${s}`);
|
||||||
@@ -126,16 +126,14 @@ export class Subsonic implements MusicService {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
getJSON = async <T>(
|
GET = (query: Partial<RequestParams>) => ({
|
||||||
credentials: Credentials,
|
asJSON: <T>() => getJSON<T>(http2(this.subsonicHttp, query)),
|
||||||
url: string,
|
});
|
||||||
params: {} = {}
|
|
||||||
): Promise<T> => getJSON2(http2(this.authenticatedSubsonicHttp(credentials), { url, params }));
|
|
||||||
|
|
||||||
generateToken = (credentials: Credentials) =>
|
generateToken = (credentials: Credentials) =>
|
||||||
pipe(
|
pipe(
|
||||||
TE.tryCatch(
|
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)
|
(e) => new AuthFailure(e as string)
|
||||||
),
|
),
|
||||||
TE.chain(({ type }) =>
|
TE.chain(({ type }) =>
|
||||||
|
|||||||
@@ -38,9 +38,8 @@ import {
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { asURLSearchParams } from "../utils";
|
import { asURLSearchParams } from "../utils";
|
||||||
import { artistSummaryFromNDArtist, NDArtist } from "./navidrome";
|
import { artistSummaryFromNDArtist, NDArtist } from "./navidrome";
|
||||||
//todo: rename http2 -> http
|
import { Http, http as newHttp, RequestParams } from "../http";
|
||||||
import { Http, http as http2, RequestParams } from "../http";
|
import { getRaw2, getJSON } from "./subsonic_http";
|
||||||
import { getRaw2, getJSON as getJSON2 } from "./subsonic_http";
|
|
||||||
|
|
||||||
type album = {
|
type album = {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -288,8 +287,8 @@ export class SubsonicGenericMusicLibrary implements SubsonicMusicLibrary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GET = (query: Partial<RequestParams>) => ({
|
GET = (query: Partial<RequestParams>) => ({
|
||||||
asRAW: () => getRaw2(http2(this.subsonicHttp, query)),
|
asRAW: () => getRaw2(newHttp(this.subsonicHttp, query)),
|
||||||
asJSON: <T>() => getJSON2<T>(http2(this.subsonicHttp, query)),
|
asJSON: <T>() => getJSON<T>(newHttp(this.subsonicHttp, query)),
|
||||||
});
|
});
|
||||||
|
|
||||||
flavour = () => "subsonic";
|
flavour = () => "subsonic";
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
SubsonicEnvelope,
|
SubsonicEnvelope,
|
||||||
} from ".";
|
} from ".";
|
||||||
// todo: rename http2 to http
|
// todo: rename http2 to http
|
||||||
import { Http, http as http2 } from "../http";
|
import { Http, http as newHttp } from "../http";
|
||||||
|
|
||||||
export type HttpResponse = {
|
export type HttpResponse = {
|
||||||
data: any;
|
data: any;
|
||||||
@@ -23,7 +23,7 @@ export const getRaw2 = (http: Http) =>
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const getJSON = async <T>(http: Http): Promise<T> =>
|
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 => {
|
export const asJSON = <T>(response: HttpResponse): T => {
|
||||||
const subsonicResponse = (response.data as SubsonicEnvelope)[
|
const subsonicResponse = (response.data as SubsonicEnvelope)[
|
||||||
@@ -35,3 +35,4 @@ export const asJSON = <T>(response: HttpResponse): T => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user