mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-22 01:43:29 +01:00
ref
This commit is contained in:
@@ -30,6 +30,7 @@ import logger from "./logger";
|
|||||||
import { assertSystem, BUrn } from "./burn";
|
import { assertSystem, BUrn } from "./burn";
|
||||||
import { artist } from "./smapi";
|
import { artist } from "./smapi";
|
||||||
import { axiosImageFetcher, ImageFetcher } from "./images";
|
import { axiosImageFetcher, ImageFetcher } from "./images";
|
||||||
|
import { asURLSearchParams } from "./utils";
|
||||||
|
|
||||||
|
|
||||||
export const t = (password: string, s: string) =>
|
export const t = (password: string, s: string) =>
|
||||||
@@ -331,16 +332,6 @@ export function appendMimeTypeToClientFor(mimeTypes: string[]) {
|
|||||||
mimeTypes.includes(track.mimeType) ? `bonob+${track.mimeType}` : "bonob";
|
mimeTypes.includes(track.mimeType) ? `bonob+${track.mimeType}` : "bonob";
|
||||||
}
|
}
|
||||||
|
|
||||||
export const asURLSearchParams = (q: any) => {
|
|
||||||
const urlSearchParams = new URLSearchParams();
|
|
||||||
Object.keys(q).forEach((k) => {
|
|
||||||
_.flatten([q[k]]).forEach((v) => {
|
|
||||||
urlSearchParams.append(k, `${v}`);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return urlSearchParams;
|
|
||||||
};
|
|
||||||
|
|
||||||
const AlbumQueryTypeToSubsonicType: Record<AlbumQueryType, string> = {
|
const AlbumQueryTypeToSubsonicType: Record<AlbumQueryType, string> = {
|
||||||
alphabeticalByArtist: "alphabeticalByArtist",
|
alphabeticalByArtist: "alphabeticalByArtist",
|
||||||
alphabeticalByName: "alphabeticalByName",
|
alphabeticalByName: "alphabeticalByName",
|
||||||
|
|||||||
14
src/utils.ts
14
src/utils.ts
@@ -1,3 +1,5 @@
|
|||||||
|
import { flatten } from "underscore";
|
||||||
|
|
||||||
export const BROWSER_HEADERS = {
|
export const BROWSER_HEADERS = {
|
||||||
accept:
|
accept:
|
||||||
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
|
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
|
||||||
@@ -8,6 +10,18 @@ export const BROWSER_HEADERS = {
|
|||||||
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:86.0) Gecko/20100101 Firefox/86.0",
|
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:86.0) Gecko/20100101 Firefox/86.0",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export const asURLSearchParams = (q: any) => {
|
||||||
|
const urlSearchParams = new URLSearchParams();
|
||||||
|
Object.keys(q).forEach((k) => {
|
||||||
|
flatten([q[k]]).forEach((v) => {
|
||||||
|
urlSearchParams.append(k, `${v}`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return urlSearchParams;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
export function takeWithRepeats<T>(things:T[], count: number) {
|
export function takeWithRepeats<T>(things:T[], count: number) {
|
||||||
const result = [];
|
const result = [];
|
||||||
for(let i = 0; i < count; i++) {
|
for(let i = 0; i < count; i++) {
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import {
|
|||||||
DODGY_IMAGE_NAME,
|
DODGY_IMAGE_NAME,
|
||||||
asGenre,
|
asGenre,
|
||||||
appendMimeTypeToClientFor,
|
appendMimeTypeToClientFor,
|
||||||
asURLSearchParams,
|
|
||||||
asTrack,
|
asTrack,
|
||||||
artistImageURN,
|
artistImageURN,
|
||||||
images,
|
images,
|
||||||
@@ -58,6 +57,7 @@ import {
|
|||||||
} from "./builders";
|
} from "./builders";
|
||||||
import { b64Encode } from "../src/b64";
|
import { b64Encode } from "../src/b64";
|
||||||
import { BUrn } from "../src/burn";
|
import { BUrn } from "../src/burn";
|
||||||
|
import { asURLSearchParams } from "../src/utils";
|
||||||
|
|
||||||
describe("t", () => {
|
describe("t", () => {
|
||||||
it("should be an md5 of the password and the salt", () => {
|
it("should be an md5 of the password and the salt", () => {
|
||||||
@@ -121,52 +121,6 @@ describe("appendMimeTypeToUserAgentFor", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("asURLSearchParams", () => {
|
|
||||||
describe("empty q", () => {
|
|
||||||
it("should return empty params", () => {
|
|
||||||
const q = {};
|
|
||||||
const expected = new URLSearchParams();
|
|
||||||
expect(asURLSearchParams(q)).toEqual(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("singular params", () => {
|
|
||||||
it("should append each", () => {
|
|
||||||
const q = {
|
|
||||||
a: 1,
|
|
||||||
b: "bee",
|
|
||||||
c: false,
|
|
||||||
d: true,
|
|
||||||
};
|
|
||||||
const expected = new URLSearchParams();
|
|
||||||
expected.append("a", "1");
|
|
||||||
expected.append("b", "bee");
|
|
||||||
expected.append("c", "false");
|
|
||||||
expected.append("d", "true");
|
|
||||||
|
|
||||||
expect(asURLSearchParams(q)).toEqual(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("list params", () => {
|
|
||||||
it("should append each", () => {
|
|
||||||
const q = {
|
|
||||||
a: [1, "two", false, true],
|
|
||||||
b: "yippee",
|
|
||||||
};
|
|
||||||
|
|
||||||
const expected = new URLSearchParams();
|
|
||||||
expected.append("a", "1");
|
|
||||||
expected.append("a", "two");
|
|
||||||
expected.append("a", "false");
|
|
||||||
expected.append("a", "true");
|
|
||||||
expected.append("b", "yippee");
|
|
||||||
|
|
||||||
expect(asURLSearchParams(q)).toEqual(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
const ok = (data: string | object) => ({
|
const ok = (data: string | object) => ({
|
||||||
status: 200,
|
status: 200,
|
||||||
data,
|
data,
|
||||||
|
|||||||
@@ -1,4 +1,52 @@
|
|||||||
import { takeWithRepeats } from "../src/utils";
|
import { asURLSearchParams, takeWithRepeats } from "../src/utils";
|
||||||
|
|
||||||
|
describe("asURLSearchParams", () => {
|
||||||
|
describe("empty q", () => {
|
||||||
|
it("should return empty params", () => {
|
||||||
|
const q = {};
|
||||||
|
const expected = new URLSearchParams();
|
||||||
|
expect(asURLSearchParams(q)).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("singular params", () => {
|
||||||
|
it("should append each", () => {
|
||||||
|
const q = {
|
||||||
|
a: 1,
|
||||||
|
b: "bee",
|
||||||
|
c: false,
|
||||||
|
d: true,
|
||||||
|
};
|
||||||
|
const expected = new URLSearchParams();
|
||||||
|
expected.append("a", "1");
|
||||||
|
expected.append("b", "bee");
|
||||||
|
expected.append("c", "false");
|
||||||
|
expected.append("d", "true");
|
||||||
|
|
||||||
|
expect(asURLSearchParams(q)).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("list params", () => {
|
||||||
|
it("should append each", () => {
|
||||||
|
const q = {
|
||||||
|
a: [1, "two", false, true],
|
||||||
|
b: "yippee",
|
||||||
|
};
|
||||||
|
|
||||||
|
const expected = new URLSearchParams();
|
||||||
|
expected.append("a", "1");
|
||||||
|
expected.append("a", "two");
|
||||||
|
expected.append("a", "false");
|
||||||
|
expected.append("a", "true");
|
||||||
|
expected.append("b", "yippee");
|
||||||
|
|
||||||
|
expect(asURLSearchParams(q)).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
describe("takeWithRepeat", () => {
|
describe("takeWithRepeat", () => {
|
||||||
describe("when there is nothing in the input", () => {
|
describe("when there is nothing in the input", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user