mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-22 09:53:32 +01:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2961b651d9 | ||
|
|
d8d532e35f | ||
|
|
a581100d29 | ||
|
|
6bc4c79f02 | ||
|
|
dd52c5706b | ||
|
|
996582ce93 |
@@ -1,4 +1,4 @@
|
|||||||
FROM node:20-bullseye
|
FROM node:22-bullseye
|
||||||
|
|
||||||
LABEL maintainer=simojenki
|
LABEL maintainer=simojenki
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM node:20-bullseye-slim as build
|
FROM node:22-bullseye-slim AS build
|
||||||
|
|
||||||
WORKDIR /bonob
|
WORKDIR /bonob
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ RUN apt-get update && \
|
|||||||
NODE_ENV=production npm install --omit=dev
|
NODE_ENV=production npm install --omit=dev
|
||||||
|
|
||||||
|
|
||||||
FROM node:20-bullseye-slim
|
FROM node:22-bullseye-slim
|
||||||
|
|
||||||
LABEL maintainer="simojenki" \
|
LABEL maintainer="simojenki" \
|
||||||
org.opencontainers.image.source="https://github.com/simojenki/bonob" \
|
org.opencontainers.image.source="https://github.com/simojenki/bonob" \
|
||||||
@@ -58,7 +58,7 @@ COPY --from=build /bonob/build/src ./src
|
|||||||
COPY --from=build /bonob/node_modules ./node_modules
|
COPY --from=build /bonob/node_modules ./node_modules
|
||||||
COPY --from=build /bonob/.gitinfo ./
|
COPY --from=build /bonob/.gitinfo ./
|
||||||
COPY web ./web
|
COPY web ./web
|
||||||
COPY src/Sonoswsdl-1.19.4-20190411.142401-3.wsdl ./src/Sonoswsdl-1.19.4-20190411.142401-3.wsdl
|
COPY src/Sonoswsdl-1.19.6-20231024.wsdl ./src/Sonoswsdl-1.19.6-20231024.wsdl
|
||||||
|
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
apt-get -y upgrade && \
|
apt-get -y upgrade && \
|
||||||
|
|||||||
1690
package-lock.json
generated
1690
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
64
package.json
64
package.json
@@ -6,56 +6,56 @@
|
|||||||
"author": "simojenki <simojenki@users.noreply.github.com>",
|
"author": "simojenki <simojenki@users.noreply.github.com>",
|
||||||
"license": "GPL-3.0-only",
|
"license": "GPL-3.0-only",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@svrooij/sonos": "^2.6.0-beta.7",
|
"@svrooij/sonos": "^2.6.0-beta.11",
|
||||||
"@types/express": "^4.17.21",
|
"@types/express": "^4.17.21",
|
||||||
"@types/fs-extra": "^11.0.4",
|
"@types/fs-extra": "^11.0.4",
|
||||||
"@types/jsonwebtoken": "^9.0.5",
|
"@types/jsonwebtoken": "^9.0.7",
|
||||||
"@types/jws": "^3.2.9",
|
"@types/jws": "^3.2.10",
|
||||||
"@types/morgan": "^1.9.9",
|
"@types/morgan": "^1.9.9",
|
||||||
"@types/node": "^20.11.5",
|
"@types/node": "^20.11.5",
|
||||||
"@types/randomstring": "^1.1.11",
|
"@types/randomstring": "^1.3.0",
|
||||||
"@types/underscore": "^1.11.15",
|
"@types/underscore": "^1.13.0",
|
||||||
"@types/uuid": "^9.0.7",
|
"@types/uuid": "^10.0.0",
|
||||||
"@types/xmldom": "0.1.34",
|
"@types/xmldom": "^0.1.34",
|
||||||
"axios": "^1.6.5",
|
"@xmldom/xmldom": "^0.9.7",
|
||||||
"dayjs": "^1.11.10",
|
"axios": "^1.7.8",
|
||||||
|
"dayjs": "^1.11.13",
|
||||||
"eta": "^2.2.0",
|
"eta": "^2.2.0",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.3",
|
||||||
"fp-ts": "^2.16.2",
|
"fp-ts": "^2.16.9",
|
||||||
"fs-extra": "^11.2.0",
|
"fs-extra": "^11.2.0",
|
||||||
"jsonwebtoken": "^9.0.2",
|
"jsonwebtoken": "^9.0.2",
|
||||||
"jws": "^4.0.0",
|
"jws": "^4.0.0",
|
||||||
"libxmljs2": "^0.33.0",
|
|
||||||
"morgan": "^1.10.0",
|
"morgan": "^1.10.0",
|
||||||
"node-html-parser": "^6.1.12",
|
"node-html-parser": "^6.1.13",
|
||||||
"randomstring": "^1.3.0",
|
"randomstring": "^1.3.0",
|
||||||
"sharp": "^0.33.2",
|
"sharp": "^0.33.5",
|
||||||
"soap": "^1.0.0",
|
"soap": "^1.1.6",
|
||||||
"ts-md5": "^1.3.1",
|
"ts-md5": "^1.3.1",
|
||||||
"typescript": "^5.3.3",
|
"typescript": "^5.7.2",
|
||||||
"underscore": "^1.13.6",
|
"underscore": "^1.13.7",
|
||||||
"urn-lib": "^2.0.0",
|
"urn-lib": "^2.0.0",
|
||||||
"uuid": "^9.0.1",
|
"uuid": "^11.0.3",
|
||||||
"winston": "^3.11.0",
|
"winston": "^3.17.0",
|
||||||
"xmldom-ts": "^0.3.1"
|
"xmldom-ts": "^0.3.1",
|
||||||
|
"xpath": "^0.0.34"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/chai": "^4.3.11",
|
"@types/chai": "^5.0.1",
|
||||||
"@types/jest": "^29.5.11",
|
"@types/jest": "^29.5.14",
|
||||||
"@types/mocha": "^10.0.6",
|
"@types/mocha": "^10.0.10",
|
||||||
"@types/supertest": "^6.0.2",
|
"@types/supertest": "^6.0.2",
|
||||||
"@types/tmp": "^0.2.6",
|
"@types/tmp": "^0.2.6",
|
||||||
"chai": "^5.0.0",
|
"chai": "^5.1.2",
|
||||||
"get-port": "^7.0.0",
|
"get-port": "^7.1.0",
|
||||||
"image-js": "^0.35.5",
|
"image-js": "^0.35.6",
|
||||||
"jest": "^29.7.0",
|
"jest": "^29.7.0",
|
||||||
"nodemon": "^3.0.3",
|
"nodemon": "^3.1.7",
|
||||||
"supertest": "^6.3.4",
|
"supertest": "^7.0.0",
|
||||||
"tmp": "^0.2.1",
|
"tmp": "^0.2.3",
|
||||||
"ts-jest": "^29.1.2",
|
"ts-jest": "^29.2.5",
|
||||||
"ts-mockito": "^2.6.1",
|
"ts-mockito": "^2.6.1",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"xmldom-ts": "^0.3.1",
|
|
||||||
"xpath-ts": "^1.3.13"
|
"xpath-ts": "^1.3.13"
|
||||||
},
|
},
|
||||||
"overrides": {
|
"overrides": {
|
||||||
@@ -66,7 +66,7 @@
|
|||||||
"clean": "rm -Rf build node_modules",
|
"clean": "rm -Rf build node_modules",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"dev": "BNB_SUBSONIC_CUSTOM_CLIENTS1=audio/flac,audio/mpeg,audio/mp4\\>audio/flac BNB_LOG_LEVEL=debug BNB_DEBUG=true BNB_SCROBBLE_TRACKS=false BNB_REPORT_NOW_PLAYING=false BNB_SONOS_SEED_HOST=$BNB_DEV_SONOS_DEVICE_IP BNB_SONOS_SERVICE_NAME=z_bonobDev BNB_URL=\"http://${BNB_DEV_HOST_IP}:4534\" BNB_SUBSONIC_URL=\"${BNB_DEV_SUBSONIC_URL}\" nodemon -V ./src/app.ts",
|
"dev": "BNB_SUBSONIC_CUSTOM_CLIENTS1=audio/flac,audio/mpeg,audio/mp4\\>audio/flac BNB_LOG_LEVEL=debug BNB_DEBUG=true BNB_SCROBBLE_TRACKS=false BNB_REPORT_NOW_PLAYING=false BNB_SONOS_SEED_HOST=$BNB_DEV_SONOS_DEVICE_IP BNB_SONOS_SERVICE_NAME=z_bonobDev BNB_URL=\"http://${BNB_DEV_HOST_IP}:4534\" BNB_SUBSONIC_URL=\"${BNB_DEV_SUBSONIC_URL}\" nodemon -V ./src/app.ts",
|
||||||
"devr": "BNB_LOG_LEVEL=debug BNB_DEBUG=true BNB_SCROBBLE_TRACKS=false BNB_REPORT_NOW_PLAYING=false BNB_SONOS_SEED_HOST=$BNB_DEV_SONOS_DEVICE_IP BNB_SONOS_SERVICE_NAME=z_bonobDev BNB_SONOS_DEVICE_DISCOVERY=true BNB_SONOS_AUTO_REGISTER=true BNB_URL=\"http://${BNB_DEV_HOST_IP}:4534\" BNB_SUBSONIC_URL=\"${BNB_DEV_SUBSONIC_URL}\" nodemon -V ./src/app.ts",
|
"devr": "BNB_LOG_LEVEL=debug BNB_DEBUG=true BNB_ICON_FOREGROUND_COLOR=deeppink BNB_ICON_BACKGROUND_COLOR=darkslategray BNB_SCROBBLE_TRACKS=false BNB_REPORT_NOW_PLAYING=false BNB_SONOS_SEED_HOST=$BNB_DEV_SONOS_DEVICE_IP BNB_SONOS_SERVICE_NAME=z_bonobDev BNB_SONOS_DEVICE_DISCOVERY=true BNB_SONOS_AUTO_REGISTER=true BNB_URL=\"http://${BNB_DEV_HOST_IP}:4534\" BNB_SUBSONIC_URL=\"${BNB_DEV_SUBSONIC_URL}\" nodemon -V ./src/app.ts",
|
||||||
"register-dev": "ts-node ./src/register.ts http://${BNB_DEV_HOST_IP}:4534",
|
"register-dev": "ts-node ./src/register.ts http://${BNB_DEV_HOST_IP}:4534",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"testw": "jest --watch",
|
"testw": "jest --watch",
|
||||||
|
|||||||
@@ -97,7 +97,7 @@
|
|||||||
<xs:complexType>
|
<xs:complexType>
|
||||||
<xs:sequence>
|
<xs:sequence>
|
||||||
<xs:element name="token" type="xs:string"/>
|
<xs:element name="token" type="xs:string"/>
|
||||||
<xs:element name="key" type="xs:string"/>
|
<xs:element name="key" type="xs:string" minOccurs="0"/>
|
||||||
<xs:element name="householdId" type="xs:string"/>
|
<xs:element name="householdId" type="xs:string"/>
|
||||||
</xs:sequence>
|
</xs:sequence>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
@@ -111,11 +111,12 @@
|
|||||||
</xs:simpleType>
|
</xs:simpleType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
|
|
||||||
<xs:simpleType name="userAccountType">
|
<xs:simpleType name="userAccountTier">
|
||||||
<xs:restriction base="xs:string">
|
<xs:restriction base="xs:string">
|
||||||
<xs:enumeration value="premium"/>
|
<xs:enumeration value="paidPremium"/>
|
||||||
<xs:enumeration value="trial"/>
|
<xs:enumeration value="paidLimited"/>
|
||||||
<xs:enumeration value="free"/>
|
<xs:enumeration value="free"/>
|
||||||
|
<xs:enumeration value="none"/>
|
||||||
</xs:restriction>
|
</xs:restriction>
|
||||||
</xs:simpleType>
|
</xs:simpleType>
|
||||||
|
|
||||||
@@ -239,6 +240,12 @@
|
|||||||
</xs:simpleContent>
|
</xs:simpleContent>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
|
|
||||||
|
<xs:complexType name="contentKeys">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="contentKey" type="tns:contentKey" maxOccurs="8"/>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
|
||||||
<xs:simpleType name="mediaUriAction">
|
<xs:simpleType name="mediaUriAction">
|
||||||
<xs:restriction base="xs:string">
|
<xs:restriction base="xs:string">
|
||||||
<xs:enumeration value="IMPLICIT"/>
|
<xs:enumeration value="IMPLICIT"/>
|
||||||
@@ -355,13 +362,11 @@
|
|||||||
|
|
||||||
<xs:complexType name="userInfo">
|
<xs:complexType name="userInfo">
|
||||||
<xs:sequence>
|
<xs:sequence>
|
||||||
<!-- Everything except userIdHashCode and nickname are for future use -->
|
<!-- accountStatus potentially for future use -->
|
||||||
<xs:element name="userIdHashCode" type="xs:string" minOccurs="1"/>
|
<xs:element name="userIdHashCode" type="xs:string" minOccurs="1"/>
|
||||||
<xs:element name="accountType" type="tns:userAccountType" minOccurs="0"/>
|
<xs:element name="accountTier" type="tns:userAccountTier" minOccurs="0"/>
|
||||||
<xs:element name="accountStatus" type="tns:userAccountStatus" minOccurs="0"/>
|
<xs:element name="accountStatus" type="tns:userAccountStatus" minOccurs="0"/>
|
||||||
<xs:element ref="tns:nickname" minOccurs="0"/>
|
<xs:element ref="tns:nickname" minOccurs="0"/>
|
||||||
<xs:element name="profileUrl" type="tns:sonosUri" minOccurs="0"/>
|
|
||||||
<xs:element name="pictureUrl" type="tns:sonosUri" minOccurs="0"/>
|
|
||||||
</xs:sequence>
|
</xs:sequence>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
|
|
||||||
@@ -888,7 +893,10 @@
|
|||||||
<xs:element name="getMediaURIResult" type="xs:anyURI"/>
|
<xs:element name="getMediaURIResult" type="xs:anyURI"/>
|
||||||
<xs:element name="deviceSessionToken" type="tns:deviceSessionToken" minOccurs="0" maxOccurs="1"/>
|
<xs:element name="deviceSessionToken" type="tns:deviceSessionToken" minOccurs="0" maxOccurs="1"/>
|
||||||
<xs:element name="deviceSessionKey" type="tns:encryptionContext" minOccurs="0" maxOccurs="1"/>
|
<xs:element name="deviceSessionKey" type="tns:encryptionContext" minOccurs="0" maxOccurs="1"/>
|
||||||
|
<xs:choice minOccurs="0">
|
||||||
<xs:element name="contentKey" type="tns:encryptionContext" minOccurs="0" maxOccurs="1"/>
|
<xs:element name="contentKey" type="tns:encryptionContext" minOccurs="0" maxOccurs="1"/>
|
||||||
|
<xs:element name="contentKeys" type="tns:contentKeys" minOccurs="0" maxOccurs="1"/>
|
||||||
|
</xs:choice>
|
||||||
<xs:element name="httpHeaders" type="tns:httpHeaders" minOccurs="0" maxOccurs="1"/>
|
<xs:element name="httpHeaders" type="tns:httpHeaders" minOccurs="0" maxOccurs="1"/>
|
||||||
<xs:element name="uriTimeout" type="xs:int" minOccurs="0" maxOccurs="1"/>
|
<xs:element name="uriTimeout" type="xs:int" minOccurs="0" maxOccurs="1"/>
|
||||||
<xs:element name="positionInformation" type="tns:positionInformation" minOccurs="0" maxOccurs="1"/>
|
<xs:element name="positionInformation" type="tns:positionInformation" minOccurs="0" maxOccurs="1"/>
|
||||||
@@ -2059,7 +2067,7 @@
|
|||||||
|
|
||||||
<wsdl:service name="Sonos">
|
<wsdl:service name="Sonos">
|
||||||
<wsdl:port name="SonosSoap" binding="tns:SonosSoap">
|
<wsdl:port name="SonosSoap" binding="tns:SonosSoap">
|
||||||
<soap:address location="/about"/>
|
<soap:address location="http://moapi.sonos.com/Test/TestService.php"/>
|
||||||
</wsdl:port>
|
</wsdl:port>
|
||||||
</wsdl:service>
|
</wsdl:service>
|
||||||
|
|
||||||
10
src/app.ts
10
src/app.ts
@@ -6,9 +6,10 @@ import logger from "./logger";
|
|||||||
import {
|
import {
|
||||||
axiosImageFetcher,
|
axiosImageFetcher,
|
||||||
cachingImageFetcher,
|
cachingImageFetcher,
|
||||||
Subsonic,
|
SubsonicMusicService,
|
||||||
TranscodingCustomPlayers,
|
TranscodingCustomPlayers,
|
||||||
NO_CUSTOM_PLAYERS
|
NO_CUSTOM_PLAYERS,
|
||||||
|
Subsonic
|
||||||
} from "./subsonic";
|
} from "./subsonic";
|
||||||
import { InMemoryAPITokens, sha256 } from "./api_tokens";
|
import { InMemoryAPITokens, sha256 } from "./api_tokens";
|
||||||
import { InMemoryLinkCodes } from "./link_codes";
|
import { InMemoryLinkCodes } from "./link_codes";
|
||||||
@@ -40,10 +41,13 @@ const artistImageFetcher = config.subsonic.artistImageCache
|
|||||||
? cachingImageFetcher(config.subsonic.artistImageCache, axiosImageFetcher)
|
? cachingImageFetcher(config.subsonic.artistImageCache, axiosImageFetcher)
|
||||||
: axiosImageFetcher;
|
: axiosImageFetcher;
|
||||||
|
|
||||||
const subsonic = new Subsonic(
|
const subsonic = new SubsonicMusicService(
|
||||||
|
new Subsonic(
|
||||||
config.subsonic.url,
|
config.subsonic.url,
|
||||||
customPlayers,
|
customPlayers,
|
||||||
artistImageFetcher
|
artistImageFetcher
|
||||||
|
),
|
||||||
|
customPlayers
|
||||||
);
|
);
|
||||||
|
|
||||||
const featureFlagAwareMusicService: MusicService = {
|
const featureFlagAwareMusicService: MusicService = {
|
||||||
|
|||||||
10
src/burn.ts
10
src/burn.ts
@@ -1,6 +1,8 @@
|
|||||||
import _ from "underscore";
|
import _ from "underscore";
|
||||||
import { createUrnUtil } from "urn-lib";
|
import { createUrnUtil } from "urn-lib";
|
||||||
import randomstring from "randomstring";
|
import randomstring from "randomstring";
|
||||||
|
import { pipe } from "fp-ts/lib/function";
|
||||||
|
import { either as E } from "fp-ts";
|
||||||
|
|
||||||
import jwsEncryption from "./encryption";
|
import jwsEncryption from "./encryption";
|
||||||
|
|
||||||
@@ -78,7 +80,13 @@ export const parse = (burn: string): BUrn => {
|
|||||||
resource: result.resource as string,
|
resource: result.resource as string,
|
||||||
};
|
};
|
||||||
if(x.system == "encrypted") {
|
if(x.system == "encrypted") {
|
||||||
return parse(encryptor.decrypt(x.resource));
|
return pipe(
|
||||||
|
encryptor.decrypt(x.resource),
|
||||||
|
E.match(
|
||||||
|
(err) => { throw new Error(err) },
|
||||||
|
(z) => parse(z)
|
||||||
|
)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,14 @@ import {
|
|||||||
randomBytes,
|
randomBytes,
|
||||||
createHash,
|
createHash,
|
||||||
} from "crypto";
|
} from "crypto";
|
||||||
|
import { option as O, either as E } from "fp-ts";
|
||||||
|
import { Either, left, right } from 'fp-ts/Either'
|
||||||
|
import { pipe } from "fp-ts/lib/function";
|
||||||
import jws from "jws";
|
import jws from "jws";
|
||||||
|
|
||||||
const ALGORITHM = "aes-256-cbc";
|
const ALGORITHM = "aes-256-cbc";
|
||||||
const IV = randomBytes(16);
|
const IV = randomBytes(16);
|
||||||
|
|
||||||
|
|
||||||
export type Hash = {
|
export type Hash = {
|
||||||
iv: string;
|
iv: string;
|
||||||
encryptedData: string;
|
encryptedData: string;
|
||||||
@@ -18,7 +19,7 @@ export type Hash = {
|
|||||||
|
|
||||||
export type Encryption = {
|
export type Encryption = {
|
||||||
encrypt: (value: string) => string;
|
encrypt: (value: string) => string;
|
||||||
decrypt: (value: string) => string;
|
decrypt: (value: string) => Either<string, string>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const jwsEncryption = (secret: string): Encryption => {
|
export const jwsEncryption = (secret: string): Encryption => {
|
||||||
@@ -28,7 +29,15 @@ export const jwsEncryption = (secret: string): Encryption => {
|
|||||||
payload: value,
|
payload: value,
|
||||||
secret: secret,
|
secret: secret,
|
||||||
}),
|
}),
|
||||||
decrypt: (value: string) => jws.decode(value).payload
|
decrypt: (value: string) => pipe(
|
||||||
|
jws.decode(value),
|
||||||
|
O.fromNullable,
|
||||||
|
O.map(it => it.payload),
|
||||||
|
O.match(
|
||||||
|
() => left("Failed to decrypt jws"),
|
||||||
|
(payload) => right(payload)
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +45,8 @@ export const cryptoEncryption = (secret: string): Encryption => {
|
|||||||
const key = createHash("sha256")
|
const key = createHash("sha256")
|
||||||
.update(String(secret))
|
.update(String(secret))
|
||||||
.digest("base64")
|
.digest("base64")
|
||||||
.substr(0, 32);
|
.substring(0, 32);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
encrypt: (value: string) => {
|
encrypt: (value: string) => {
|
||||||
const cipher = createCipheriv(ALGORITHM, key, IV);
|
const cipher = createCipheriv(ALGORITHM, key, IV);
|
||||||
@@ -45,20 +55,23 @@ export const cryptoEncryption = (secret: string): Encryption => {
|
|||||||
cipher.final(),
|
cipher.final(),
|
||||||
]).toString("hex")}`;
|
]).toString("hex")}`;
|
||||||
},
|
},
|
||||||
decrypt: (value: string) => {
|
decrypt: (value: string) => pipe(
|
||||||
const parts = value.split(".");
|
right(value),
|
||||||
if(parts.length != 2) throw `Invalid value to decrypt`;
|
E.map(it => it.split(".")),
|
||||||
|
E.flatMap(it => it.length == 2 ? right({ iv: it[0]!, data: it[1]! }) : left("Invalid value to decrypt")),
|
||||||
const decipher = createDecipheriv(
|
E.map(it => ({
|
||||||
|
hash: it,
|
||||||
|
decipher: createDecipheriv(
|
||||||
ALGORITHM,
|
ALGORITHM,
|
||||||
key,
|
key,
|
||||||
Buffer.from(parts[0]!, "hex")
|
Buffer.from(it.iv, "hex")
|
||||||
);
|
)
|
||||||
return Buffer.concat([
|
})),
|
||||||
decipher.update(Buffer.from(parts[1]!, "hex")),
|
E.map(it => Buffer.concat([
|
||||||
decipher.final(),
|
it.decipher.update(Buffer.from(it.hash.data, "hex")),
|
||||||
]).toString();
|
it.decipher.final(),
|
||||||
},
|
]).toString())
|
||||||
|
),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
94
src/icon.ts
94
src/icon.ts
@@ -1,4 +1,5 @@
|
|||||||
import libxmljs, { Element, Attribute } from "libxmljs2";
|
import * as xpath from "xpath";
|
||||||
|
import { DOMParser, Node } from '@xmldom/xmldom';
|
||||||
import _ from "underscore";
|
import _ from "underscore";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
|
||||||
@@ -13,11 +14,10 @@ import {
|
|||||||
isMay4,
|
isMay4,
|
||||||
SystemClock,
|
SystemClock,
|
||||||
} from "./clock";
|
} from "./clock";
|
||||||
|
import { xmlTidy } from "./utils";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
const SVG_NS = {
|
const SVG_NS = "http://www.w3.org/2000/svg";
|
||||||
svg: "http://www.w3.org/2000/svg",
|
|
||||||
};
|
|
||||||
|
|
||||||
class ViewBox {
|
class ViewBox {
|
||||||
minX: number;
|
minX: number;
|
||||||
@@ -48,8 +48,16 @@ export type IconFeatures = {
|
|||||||
viewPortIncreasePercent: number | undefined;
|
viewPortIncreasePercent: number | undefined;
|
||||||
backgroundColor: string | undefined;
|
backgroundColor: string | undefined;
|
||||||
foregroundColor: string | undefined;
|
foregroundColor: string | undefined;
|
||||||
|
text: string | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const NO_FEATURES: IconFeatures = {
|
||||||
|
viewPortIncreasePercent: undefined,
|
||||||
|
backgroundColor: undefined,
|
||||||
|
foregroundColor: undefined,
|
||||||
|
text: undefined
|
||||||
|
}
|
||||||
|
|
||||||
export type IconSpec = {
|
export type IconSpec = {
|
||||||
svg: string | undefined;
|
svg: string | undefined;
|
||||||
features: Partial<IconFeatures> | undefined;
|
features: Partial<IconFeatures> | undefined;
|
||||||
@@ -93,17 +101,11 @@ export class SvgIcon implements Icon {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
svg: string,
|
svg: string,
|
||||||
features: Partial<IconFeatures> = {
|
features: Partial<IconFeatures> = {}
|
||||||
viewPortIncreasePercent: undefined,
|
|
||||||
backgroundColor: undefined,
|
|
||||||
foregroundColor: undefined,
|
|
||||||
}
|
|
||||||
) {
|
) {
|
||||||
this.svg = svg;
|
this.svg = svg;
|
||||||
this.features = {
|
this.features = {
|
||||||
viewPortIncreasePercent: undefined,
|
...NO_FEATURES,
|
||||||
backgroundColor: undefined,
|
|
||||||
foregroundColor: undefined,
|
|
||||||
...features,
|
...features,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -117,38 +119,44 @@ export class SvgIcon implements Icon {
|
|||||||
});
|
});
|
||||||
|
|
||||||
public toString = () => {
|
public toString = () => {
|
||||||
const xml = libxmljs.parseXmlString(this.svg, {
|
const doc = new DOMParser().parseFromString(this.svg, 'text/xml') as unknown as Document;
|
||||||
noblanks: true,
|
const select = xpath.useNamespaces({ svg: SVG_NS });
|
||||||
net: false,
|
|
||||||
});
|
const elements = (path: string) => (select(path, doc) as Element[])
|
||||||
const viewBoxAttr = xml.get("//svg:svg/@viewBox", SVG_NS) as Attribute;
|
const element = (path: string) => elements(path)[0]!
|
||||||
let viewBox = new ViewBox(viewBoxAttr.value());
|
|
||||||
|
let viewBox = new ViewBox(select("string(//svg:svg/@viewBox)", doc) as string);
|
||||||
if (
|
if (
|
||||||
this.features.viewPortIncreasePercent &&
|
this.features.viewPortIncreasePercent &&
|
||||||
this.features.viewPortIncreasePercent > 0
|
this.features.viewPortIncreasePercent > 0
|
||||||
) {
|
) {
|
||||||
viewBox = viewBox.increasePercent(this.features.viewPortIncreasePercent);
|
viewBox = viewBox.increasePercent(this.features.viewPortIncreasePercent);
|
||||||
viewBoxAttr.value(viewBox.toString());
|
element("//svg:svg").setAttribute("viewBox", viewBox.toString());
|
||||||
}
|
}
|
||||||
if (this.features.backgroundColor) {
|
if(this.features.text) {
|
||||||
(xml.get("//svg:svg/*[1]", SVG_NS) as Element).addPrevSibling(
|
elements("//svg:text").forEach((text) => {
|
||||||
new Element(xml, "rect").attr({
|
text.textContent = this.features.text!
|
||||||
x: `${viewBox.minX}`,
|
|
||||||
y: `${viewBox.minY}`,
|
|
||||||
width: `${Math.abs(viewBox.minX) + viewBox.width}`,
|
|
||||||
height: `${Math.abs(viewBox.minY) + viewBox.height}`,
|
|
||||||
fill: this.features.backgroundColor,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (this.features.foregroundColor) {
|
|
||||||
(xml.find("//svg:path", SVG_NS) as Element[]).forEach((path) => {
|
|
||||||
if (path.attr("fill"))
|
|
||||||
path.attr({ stroke: this.features.foregroundColor! });
|
|
||||||
else path.attr({ fill: this.features.foregroundColor! });
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return xml.toString();
|
if (this.features.foregroundColor) {
|
||||||
|
elements("//svg:path|//svg:text").forEach((path) => {
|
||||||
|
if (path.getAttribute("fill")) path.setAttribute("stroke", this.features.foregroundColor!);
|
||||||
|
else path.setAttribute("fill", this.features.foregroundColor!);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (this.features.backgroundColor) {
|
||||||
|
const rect = doc.createElementNS(SVG_NS, "rect");
|
||||||
|
rect.setAttribute("x", `${viewBox.minX}`);
|
||||||
|
rect.setAttribute("y", `${viewBox.minY}`);
|
||||||
|
rect.setAttribute("width", `${Math.abs(viewBox.minX) + viewBox.width}`);
|
||||||
|
rect.setAttribute("height", `${Math.abs(viewBox.minY) + viewBox.height}`);
|
||||||
|
rect.setAttribute("fill", this.features.backgroundColor);
|
||||||
|
|
||||||
|
const svg = element("//svg:svg")
|
||||||
|
svg.insertBefore(rect, svg.childNodes[0]!);
|
||||||
|
}
|
||||||
|
|
||||||
|
return xmlTidy(doc as unknown as Node);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,20 +237,24 @@ export type ICON =
|
|||||||
| "yoda"
|
| "yoda"
|
||||||
| "heart"
|
| "heart"
|
||||||
| "star"
|
| "star"
|
||||||
| "solidStar";
|
| "solidStar"
|
||||||
|
| "yy"
|
||||||
|
| "yyyy";
|
||||||
|
|
||||||
const iconFrom = (name: string) =>
|
const svgFrom = (name: string) =>
|
||||||
new SvgIcon(
|
new SvgIcon(
|
||||||
fs
|
fs
|
||||||
.readFileSync(path.resolve(__dirname, "..", "web", "icons", name))
|
.readFileSync(path.resolve(__dirname, "..", "web", "icons", name))
|
||||||
.toString()
|
.toString()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const iconFrom = (name: string) => svgFrom(name).with({ features: { viewPortIncreasePercent: 80 } });
|
||||||
|
|
||||||
export const ICONS: Record<ICON, SvgIcon> = {
|
export const ICONS: Record<ICON, SvgIcon> = {
|
||||||
artists: iconFrom("navidrome-artists.svg"),
|
artists: iconFrom("navidrome-artists.svg"),
|
||||||
albums: iconFrom("navidrome-all.svg"),
|
albums: iconFrom("navidrome-all.svg"),
|
||||||
radio: iconFrom("navidrome-radio.svg"),
|
radio: iconFrom("navidrome-radio.svg"),
|
||||||
blank: iconFrom("blank.svg"),
|
blank: svgFrom("blank.svg"),
|
||||||
playlists: iconFrom("navidrome-playlists.svg"),
|
playlists: iconFrom("navidrome-playlists.svg"),
|
||||||
genres: iconFrom("Theatre-Mask-111172.svg"),
|
genres: iconFrom("Theatre-Mask-111172.svg"),
|
||||||
random: iconFrom("navidrome-random.svg"),
|
random: iconFrom("navidrome-random.svg"),
|
||||||
@@ -307,7 +319,9 @@ export const ICONS: Record<ICON, SvgIcon> = {
|
|||||||
yoda: iconFrom("Yoda-68107.svg"),
|
yoda: iconFrom("Yoda-68107.svg"),
|
||||||
heart: iconFrom("Heart-85038.svg"),
|
heart: iconFrom("Heart-85038.svg"),
|
||||||
star: iconFrom("Star-16101.svg"),
|
star: iconFrom("Star-16101.svg"),
|
||||||
solidStar: iconFrom("Star-43879.svg")
|
solidStar: iconFrom("Star-43879.svg"),
|
||||||
|
yy: svgFrom("yy.svg"),
|
||||||
|
yyyy: svgFrom("yyyy.svg"),
|
||||||
};
|
};
|
||||||
|
|
||||||
export const STAR_WARS = [ICONS.c3po, ICONS.chewy, ICONS.darth, ICONS.skywalker, ICONS.leia, ICONS.r2d2, ICONS.yoda];
|
export const STAR_WARS = [ICONS.c3po, ICONS.chewy, ICONS.darth, ICONS.skywalker, ICONS.leia, ICONS.r2d2, ICONS.yoda];
|
||||||
|
|||||||
@@ -498,16 +498,18 @@ function server(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/icon/:type/size/:size", (req, res) => {
|
app.get("/icon/:type_text/size/:size", (req, res) => {
|
||||||
const type = req.params["type"]!;
|
const match = (req.params["type_text"] || "")!.match("^([A-Za-z0-9]+)(?:\:([A-Za-z0-9]+))?$")
|
||||||
|
if (!match)
|
||||||
|
return res.status(400).send();
|
||||||
|
|
||||||
|
const type = match[1]!
|
||||||
|
const text = match[2]
|
||||||
const size = req.params["size"]!;
|
const size = req.params["size"]!;
|
||||||
|
|
||||||
if (!Object.keys(ICONS).includes(type)) {
|
if (!Object.keys(ICONS).includes(type)) {
|
||||||
return res.status(404).send();
|
return res.status(404).send();
|
||||||
} else if (
|
} else if (size != "legacy" && !SONOS_RECOMMENDED_IMAGE_SIZES.includes(size)) {
|
||||||
size != "legacy" &&
|
|
||||||
!SONOS_RECOMMENDED_IMAGE_SIZES.includes(size)
|
|
||||||
) {
|
|
||||||
return res.status(400).send();
|
return res.status(400).send();
|
||||||
} else {
|
} else {
|
||||||
let icon = (ICONS as any)[type]! as Icon;
|
let icon = (ICONS as any)[type]! as Icon;
|
||||||
@@ -528,8 +530,8 @@ function server(
|
|||||||
icon
|
icon
|
||||||
.apply(
|
.apply(
|
||||||
features({
|
features({
|
||||||
viewPortIncreasePercent: 80,
|
|
||||||
...serverOpts.iconColors,
|
...serverOpts.iconColors,
|
||||||
|
text: text
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.apply(festivals(clock))
|
.apply(festivals(clock))
|
||||||
|
|||||||
13
src/smapi.ts
13
src/smapi.ts
@@ -62,7 +62,7 @@ export const SONOS_RECOMMENDED_IMAGE_SIZES = [
|
|||||||
|
|
||||||
const WSDL_FILE = path.resolve(
|
const WSDL_FILE = path.resolve(
|
||||||
__dirname,
|
__dirname,
|
||||||
"Sonoswsdl-1.19.4-20190411.142401-3.wsdl"
|
"Sonoswsdl-1.19.6-20231024.wsdl"
|
||||||
);
|
);
|
||||||
|
|
||||||
export type Credentials = {
|
export type Credentials = {
|
||||||
@@ -251,11 +251,12 @@ const genre = (bonobUrl: URLBuilder, genre: Genre) => ({
|
|||||||
albumArtURI: iconArtURI(bonobUrl, iconForGenre(genre.name)).href(),
|
albumArtURI: iconArtURI(bonobUrl, iconForGenre(genre.name)).href(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const year = (bonobUrl: URLBuilder, year: Year) => ({
|
const yyyy = (bonobUrl: URLBuilder, year: Year) => ({
|
||||||
itemType: "albumList",
|
itemType: "albumList",
|
||||||
id: `year:${year.year}`,
|
id: `year:${year.year}`,
|
||||||
title: year.year,
|
title: year.year,
|
||||||
albumArtURI: iconArtURI(bonobUrl, "music").href(),
|
// todo: maybe year.year should be nullable?
|
||||||
|
albumArtURI: year.year !== "?" ? iconArtURI(bonobUrl, "yyyy", year.year).href() : iconArtURI(bonobUrl, "music").href(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const playlist = (bonobUrl: URLBuilder, playlist: Playlist) => ({
|
const playlist = (bonobUrl: URLBuilder, playlist: Playlist) => ({
|
||||||
@@ -286,9 +287,9 @@ export const coverArtURI = (
|
|||||||
O.getOrElseW(() => iconArtURI(bonobUrl, "vinyl"))
|
O.getOrElseW(() => iconArtURI(bonobUrl, "vinyl"))
|
||||||
);
|
);
|
||||||
|
|
||||||
export const iconArtURI = (bonobUrl: URLBuilder, icon: ICON) =>
|
export const iconArtURI = (bonobUrl: URLBuilder, icon: ICON, text: string | undefined = undefined) =>
|
||||||
bonobUrl.append({
|
bonobUrl.append({
|
||||||
pathname: `/icon/${icon}/size/legacy`,
|
pathname: `/icon/${text == undefined ? icon : `${icon}:${text}`}/size/legacy`,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const sonosifyMimeType = (mimeType: string) =>
|
export const sonosifyMimeType = (mimeType: string) =>
|
||||||
@@ -888,7 +889,7 @@ function bindSmapiSoapServiceToExpress(
|
|||||||
.then(([page, total]) =>
|
.then(([page, total]) =>
|
||||||
getMetadataResult({
|
getMetadataResult({
|
||||||
mediaCollection: page.map((it) =>
|
mediaCollection: page.map((it) =>
|
||||||
year(bonobUrl, it)
|
yyyy(bonobUrl, it)
|
||||||
),
|
),
|
||||||
index: paging._index,
|
index: paging._index,
|
||||||
total,
|
total,
|
||||||
|
|||||||
812
src/subsonic.ts
812
src/subsonic.ts
@@ -22,6 +22,7 @@ import {
|
|||||||
AuthFailure,
|
AuthFailure,
|
||||||
PlaylistSummary,
|
PlaylistSummary,
|
||||||
Encoding,
|
Encoding,
|
||||||
|
AuthSuccess,
|
||||||
} from "./music_service";
|
} from "./music_service";
|
||||||
import sharp from "sharp";
|
import sharp from "sharp";
|
||||||
import _ from "underscore";
|
import _ from "underscore";
|
||||||
@@ -469,17 +470,441 @@ type SubsonicCredentials = Credentials & {
|
|||||||
|
|
||||||
export const asToken = (credentials: SubsonicCredentials) =>
|
export const asToken = (credentials: SubsonicCredentials) =>
|
||||||
b64Encode(JSON.stringify(credentials));
|
b64Encode(JSON.stringify(credentials));
|
||||||
|
|
||||||
export const parseToken = (token: string): SubsonicCredentials =>
|
export const parseToken = (token: string): SubsonicCredentials =>
|
||||||
JSON.parse(b64Decode(token));
|
JSON.parse(b64Decode(token));
|
||||||
|
|
||||||
interface SubsonicMusicLibrary extends MusicLibrary {
|
export class SubsonicMusicLibrary implements MusicLibrary {
|
||||||
flavour(): string;
|
subsonic: Subsonic;
|
||||||
bearerToken(
|
|
||||||
credentials: Credentials
|
credentials: Credentials
|
||||||
): TE.TaskEither<Error, string | undefined>;
|
customPlayers: CustomPlayers
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
subsonic: Subsonic,
|
||||||
|
credentials: Credentials,
|
||||||
|
customPlayers: CustomPlayers
|
||||||
|
) {
|
||||||
|
this.subsonic = subsonic
|
||||||
|
this.credentials = credentials
|
||||||
|
this.customPlayers = customPlayers
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Subsonic implements MusicService {
|
flavour = () => "subsonic"
|
||||||
|
|
||||||
|
bearerToken = (_: Credentials) => TE.right<AuthFailure, string | undefined>(undefined)
|
||||||
|
|
||||||
|
artists = (q: ArtistQuery): Promise<Result<ArtistSummary>> =>
|
||||||
|
this.subsonic
|
||||||
|
.getArtists(this.credentials)
|
||||||
|
.then(slice2(q))
|
||||||
|
.then(([page, total]) => ({
|
||||||
|
total,
|
||||||
|
results: page.map((it) => ({
|
||||||
|
id: it.id,
|
||||||
|
name: it.name,
|
||||||
|
image: it.image,
|
||||||
|
})),
|
||||||
|
}))
|
||||||
|
|
||||||
|
artist = async (id: string): Promise<Artist> =>
|
||||||
|
this.subsonic.getArtistWithInfo(this.credentials, id)
|
||||||
|
|
||||||
|
albums = async (q: AlbumQuery): Promise<Result<AlbumSummary>> =>
|
||||||
|
this.subsonic.getAlbumList2(this.credentials, q)
|
||||||
|
|
||||||
|
album = (id: string): Promise<Album> => this.subsonic.getAlbum(this.credentials, id)
|
||||||
|
|
||||||
|
genres = () =>
|
||||||
|
this.subsonic
|
||||||
|
.getJSON<GetGenresResponse>(this.credentials, "/rest/getGenres")
|
||||||
|
.then((it) =>
|
||||||
|
pipe(
|
||||||
|
it.genres.genre || [],
|
||||||
|
A.filter((it) => it.albumCount > 0),
|
||||||
|
A.map((it) => it.value),
|
||||||
|
A.sort(ordString),
|
||||||
|
A.map((it) => ({ id: b64Encode(it), name: it }))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
tracks = (albumId: string) =>
|
||||||
|
this.subsonic
|
||||||
|
.getJSON<GetAlbumResponse>(this.credentials, "/rest/getAlbum", {
|
||||||
|
id: albumId,
|
||||||
|
})
|
||||||
|
.then((it) => it.album)
|
||||||
|
.then((album) =>
|
||||||
|
(album.song || []).map((song) => asTrack(asAlbum(album), song, this.customPlayers))
|
||||||
|
)
|
||||||
|
|
||||||
|
track = (trackId: string) => this.subsonic.getTrack(this.credentials, trackId)
|
||||||
|
|
||||||
|
rate = (trackId: string, rating: Rating) =>
|
||||||
|
Promise.resolve(true)
|
||||||
|
.then(() => {
|
||||||
|
if (rating.stars >= 0 && rating.stars <= 5) {
|
||||||
|
return this.subsonic.getTrack(this.credentials, trackId);
|
||||||
|
} else {
|
||||||
|
throw `Invalid rating.stars value of ${rating.stars}`;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then((track) => {
|
||||||
|
const thingsToUpdate = [];
|
||||||
|
if (track.rating.love != rating.love) {
|
||||||
|
thingsToUpdate.push(
|
||||||
|
this.subsonic.getJSON(
|
||||||
|
this.credentials,
|
||||||
|
`/rest/${rating.love ? "star" : "unstar"}`,
|
||||||
|
{
|
||||||
|
id: trackId,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (track.rating.stars != rating.stars) {
|
||||||
|
thingsToUpdate.push(
|
||||||
|
this.subsonic.getJSON(this.credentials, `/rest/setRating`, {
|
||||||
|
id: trackId,
|
||||||
|
rating: rating.stars,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return Promise.all(thingsToUpdate);
|
||||||
|
})
|
||||||
|
.then(() => true)
|
||||||
|
.catch(() => false)
|
||||||
|
|
||||||
|
stream = async ({
|
||||||
|
trackId,
|
||||||
|
range,
|
||||||
|
}: {
|
||||||
|
trackId: string;
|
||||||
|
range: string | undefined;
|
||||||
|
}) =>
|
||||||
|
this.subsonic.getTrack(this.credentials, trackId).then((track) =>
|
||||||
|
this.subsonic
|
||||||
|
.get(
|
||||||
|
this.credentials,
|
||||||
|
`/rest/stream`,
|
||||||
|
{
|
||||||
|
id: trackId,
|
||||||
|
c: track.encoding.player,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: pipe(
|
||||||
|
range,
|
||||||
|
O.fromNullable,
|
||||||
|
O.map((range) => ({
|
||||||
|
"User-Agent": USER_AGENT,
|
||||||
|
Range: range,
|
||||||
|
})),
|
||||||
|
O.getOrElse(() => ({
|
||||||
|
"User-Agent": USER_AGENT,
|
||||||
|
}))
|
||||||
|
),
|
||||||
|
responseType: "stream",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.then((stream) => ({
|
||||||
|
status: stream.status,
|
||||||
|
headers: {
|
||||||
|
"content-type": stream.headers["content-type"],
|
||||||
|
"content-length": stream.headers["content-length"],
|
||||||
|
"content-range": stream.headers["content-range"],
|
||||||
|
"accept-ranges": stream.headers["accept-ranges"],
|
||||||
|
},
|
||||||
|
stream: stream.data,
|
||||||
|
}))
|
||||||
|
)
|
||||||
|
|
||||||
|
coverArt = async (coverArtURN: BUrn, size?: number) =>
|
||||||
|
Promise.resolve(coverArtURN)
|
||||||
|
.then((it) => assertSystem(it, "subsonic"))
|
||||||
|
.then((it) => this.subsonic.getCoverArt(this.credentials, it.resource.split(":")[1]!, size))
|
||||||
|
.then((res) => ({
|
||||||
|
contentType: res.headers["content-type"],
|
||||||
|
data: Buffer.from(res.data, "binary"),
|
||||||
|
}))
|
||||||
|
.catch((e) => {
|
||||||
|
logger.error(
|
||||||
|
`Failed getting coverArt for urn:'${coverArtURN}': ${e}`
|
||||||
|
);
|
||||||
|
return undefined;
|
||||||
|
})
|
||||||
|
|
||||||
|
scrobble = async (id: string) =>
|
||||||
|
this.subsonic
|
||||||
|
.getJSON(this.credentials, `/rest/scrobble`, {
|
||||||
|
id,
|
||||||
|
submission: true,
|
||||||
|
})
|
||||||
|
.then((_) => true)
|
||||||
|
.catch(() => false)
|
||||||
|
|
||||||
|
nowPlaying = async (id: string) =>
|
||||||
|
this.subsonic
|
||||||
|
.getJSON(this.credentials, `/rest/scrobble`, {
|
||||||
|
id,
|
||||||
|
submission: false,
|
||||||
|
})
|
||||||
|
.then((_) => true)
|
||||||
|
.catch(() => false)
|
||||||
|
|
||||||
|
searchArtists = async (query: string) =>
|
||||||
|
this.subsonic
|
||||||
|
.search3(this.credentials, { query, artistCount: 20 })
|
||||||
|
.then(({ artists }) =>
|
||||||
|
artists.map((artist) => ({
|
||||||
|
id: artist.id,
|
||||||
|
name: artist.name,
|
||||||
|
image: artistImageURN({
|
||||||
|
artistId: artist.id,
|
||||||
|
artistImageURL: artist.artistImageUrl,
|
||||||
|
}),
|
||||||
|
}))
|
||||||
|
)
|
||||||
|
|
||||||
|
searchAlbums = async (query: string) =>
|
||||||
|
this.subsonic
|
||||||
|
.search3(this.credentials, { query, albumCount: 20 })
|
||||||
|
.then(({ albums }) => this.subsonic.toAlbumSummary(albums))
|
||||||
|
|
||||||
|
searchTracks = async (query: string) =>
|
||||||
|
this.subsonic
|
||||||
|
.search3(this.credentials, { query, songCount: 20 })
|
||||||
|
.then(({ songs }) =>
|
||||||
|
Promise.all(
|
||||||
|
songs.map((it) => this.subsonic.getTrack(this.credentials, it.id))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
playlists = async () =>
|
||||||
|
this.subsonic
|
||||||
|
.getJSON<GetPlaylistsResponse>(this.credentials, "/rest/getPlaylists")
|
||||||
|
.then(({ playlists }) => (playlists.playlist || []).map(asPlayListSummary))
|
||||||
|
|
||||||
|
playlist = async (id: string) =>
|
||||||
|
this.subsonic
|
||||||
|
.getJSON<GetPlaylistResponse>(this.credentials, "/rest/getPlaylist", {
|
||||||
|
id,
|
||||||
|
})
|
||||||
|
.then(({ playlist }) => {
|
||||||
|
let trackNumber = 1;
|
||||||
|
return {
|
||||||
|
id: playlist.id,
|
||||||
|
name: playlist.name,
|
||||||
|
coverArt: coverArtURN(playlist.coverArt),
|
||||||
|
entries: (playlist.entry || []).map((entry) => ({
|
||||||
|
...asTrack(
|
||||||
|
{
|
||||||
|
id: entry.albumId!,
|
||||||
|
name: entry.album!,
|
||||||
|
year: entry.year,
|
||||||
|
genre: maybeAsGenre(entry.genre),
|
||||||
|
artistName: entry.artist,
|
||||||
|
artistId: entry.artistId,
|
||||||
|
coverArt: coverArtURN(entry.coverArt),
|
||||||
|
},
|
||||||
|
entry,
|
||||||
|
this.customPlayers
|
||||||
|
),
|
||||||
|
number: trackNumber++,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
})
|
||||||
|
|
||||||
|
createPlaylist = async (name: string) =>
|
||||||
|
this.subsonic
|
||||||
|
.getJSON<GetPlaylistResponse>(this.credentials, "/rest/createPlaylist", {
|
||||||
|
name,
|
||||||
|
})
|
||||||
|
.then(({ playlist }) => ({
|
||||||
|
id: playlist.id,
|
||||||
|
name: playlist.name,
|
||||||
|
coverArt: coverArtURN(playlist.coverArt),
|
||||||
|
}))
|
||||||
|
|
||||||
|
deletePlaylist = async (id: string) =>
|
||||||
|
this.subsonic
|
||||||
|
.getJSON<GetPlaylistResponse>(this.credentials, "/rest/deletePlaylist", {
|
||||||
|
id,
|
||||||
|
})
|
||||||
|
.then((_) => true)
|
||||||
|
|
||||||
|
addToPlaylist = async (playlistId: string, trackId: string) =>
|
||||||
|
this.subsonic
|
||||||
|
.getJSON<GetPlaylistResponse>(this.credentials, "/rest/updatePlaylist", {
|
||||||
|
playlistId,
|
||||||
|
songIdToAdd: trackId,
|
||||||
|
})
|
||||||
|
.then((_) => true)
|
||||||
|
|
||||||
|
removeFromPlaylist = async (playlistId: string, indicies: number[]) =>
|
||||||
|
this.subsonic
|
||||||
|
.getJSON<GetPlaylistResponse>(this.credentials, "/rest/updatePlaylist", {
|
||||||
|
playlistId,
|
||||||
|
songIndexToRemove: indicies,
|
||||||
|
})
|
||||||
|
.then((_) => true)
|
||||||
|
|
||||||
|
similarSongs = async (id: string) =>
|
||||||
|
this.subsonic
|
||||||
|
.getJSON<GetSimilarSongsResponse>(
|
||||||
|
this.credentials,
|
||||||
|
"/rest/getSimilarSongs2",
|
||||||
|
{ id, count: 50 }
|
||||||
|
)
|
||||||
|
.then((it) => it.similarSongs2.song || [])
|
||||||
|
.then((songs) =>
|
||||||
|
Promise.all(
|
||||||
|
songs.map((song) =>
|
||||||
|
this.subsonic
|
||||||
|
.getAlbum(this.credentials, song.albumId!)
|
||||||
|
.then((album) => asTrack(album, song, this.customPlayers))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
topSongs = async (artistId: string) =>
|
||||||
|
this.subsonic.getArtist(this.credentials, artistId).then(({ name }) =>
|
||||||
|
this.subsonic
|
||||||
|
.getJSON<GetTopSongsResponse>(this.credentials, "/rest/getTopSongs", {
|
||||||
|
artist: name,
|
||||||
|
count: 50,
|
||||||
|
})
|
||||||
|
.then((it) => it.topSongs.song || [])
|
||||||
|
.then((songs) =>
|
||||||
|
Promise.all(
|
||||||
|
songs.map((song) =>
|
||||||
|
this.subsonic
|
||||||
|
.getAlbum(this.credentials, song.albumId!)
|
||||||
|
.then((album) => asTrack(album, song, this.customPlayers))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
radioStations = async () => this.subsonic
|
||||||
|
.getJSON<GetInternetRadioStationsResponse>(
|
||||||
|
this.credentials,
|
||||||
|
"/rest/getInternetRadioStations"
|
||||||
|
)
|
||||||
|
.then((it) => it.internetRadioStations.internetRadioStation || [])
|
||||||
|
.then((stations) => stations.map((it) => ({
|
||||||
|
id: it.id,
|
||||||
|
name: it.name,
|
||||||
|
url: it.streamUrl,
|
||||||
|
homePage: it.homePageUrl
|
||||||
|
})))
|
||||||
|
|
||||||
|
radioStation = async (id: string) => this.radioStations()
|
||||||
|
.then(it =>
|
||||||
|
it.find(station => station.id === id)!
|
||||||
|
)
|
||||||
|
|
||||||
|
years = async () => {
|
||||||
|
const q: AlbumQuery = {
|
||||||
|
_index: 0,
|
||||||
|
_count: 100000, // FIXME: better than this, probably doesnt work anyway as max _count is 500 or something
|
||||||
|
type: "alphabeticalByArtist",
|
||||||
|
};
|
||||||
|
const years = this.subsonic.getAlbumList2(this.credentials, q)
|
||||||
|
.then(({ results }) =>
|
||||||
|
results.map((album) => album.year || "?")
|
||||||
|
.filter((item, i, ar) => ar.indexOf(item) === i)
|
||||||
|
.sort()
|
||||||
|
.map((year) => ({
|
||||||
|
...asYear(year)
|
||||||
|
}))
|
||||||
|
.reverse()
|
||||||
|
);
|
||||||
|
return years;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SubsonicMusicService implements MusicService {
|
||||||
|
subsonic: Subsonic;
|
||||||
|
customPlayers: CustomPlayers;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
subsonic: Subsonic,
|
||||||
|
customPlayers: CustomPlayers = NO_CUSTOM_PLAYERS
|
||||||
|
) {
|
||||||
|
this.subsonic = subsonic;
|
||||||
|
this.customPlayers = customPlayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
generateToken = (credentials: Credentials): TE.TaskEither<AuthFailure, AuthSuccess> => {
|
||||||
|
const x: TE.TaskEither<AuthFailure, PingResponse> = TE.tryCatch(
|
||||||
|
() =>
|
||||||
|
this.subsonic.getJSON<PingResponse>(
|
||||||
|
_.pick(credentials, "username", "password"),
|
||||||
|
"/rest/ping.view"
|
||||||
|
),
|
||||||
|
(e) => new AuthFailure(e as string)
|
||||||
|
)
|
||||||
|
return pipe(
|
||||||
|
x,
|
||||||
|
TE.flatMap(({ type }) =>
|
||||||
|
pipe(
|
||||||
|
TE.tryCatch(
|
||||||
|
() => this.libraryFor({ ...credentials, type }),
|
||||||
|
() => new AuthFailure("Failed to get library")
|
||||||
|
),
|
||||||
|
TE.map((library) => ({ type, library }))
|
||||||
|
)
|
||||||
|
),
|
||||||
|
TE.flatMap(({ library, type }) =>
|
||||||
|
pipe(
|
||||||
|
library.bearerToken(credentials),
|
||||||
|
TE.map((bearer) => ({ bearer, type }))
|
||||||
|
)
|
||||||
|
),
|
||||||
|
TE.map(({ bearer, type }) => ({
|
||||||
|
serviceToken: asToken({ ...credentials, bearer, type }),
|
||||||
|
userId: credentials.username,
|
||||||
|
nickname: credentials.username,
|
||||||
|
}))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshToken = (serviceToken: string) =>
|
||||||
|
this.generateToken(parseToken(serviceToken));
|
||||||
|
|
||||||
|
login = async (token: string) => this.libraryFor(parseToken(token));
|
||||||
|
|
||||||
|
private libraryFor = (
|
||||||
|
credentials: Credentials & { type: string }
|
||||||
|
): Promise<SubsonicMusicLibrary> => {
|
||||||
|
const genericSubsonic = new SubsonicMusicLibrary(this.subsonic, credentials, this.customPlayers);
|
||||||
|
// return Promise.resolve(genericSubsonic);
|
||||||
|
|
||||||
|
if (credentials.type == "navidrome") {
|
||||||
|
// todo: there does not seem to be a test for this??
|
||||||
|
const nd: SubsonicMusicLibrary = {
|
||||||
|
...genericSubsonic,
|
||||||
|
flavour: () => "navidrome",
|
||||||
|
bearerToken: (credentials: Credentials) =>
|
||||||
|
pipe(
|
||||||
|
TE.tryCatch(
|
||||||
|
() =>
|
||||||
|
axios.post(
|
||||||
|
this.subsonic.url.append({ pathname: "/auth/login" }).href(),
|
||||||
|
_.pick(credentials, "username", "password")
|
||||||
|
),
|
||||||
|
() => new AuthFailure("Failed to get bearerToken")
|
||||||
|
),
|
||||||
|
TE.map((it) => it.data.token as string | undefined)
|
||||||
|
),
|
||||||
|
}
|
||||||
|
return Promise.resolve(nd);
|
||||||
|
} else {
|
||||||
|
return Promise.resolve(genericSubsonic);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Subsonic {
|
||||||
url: URLBuilder;
|
url: URLBuilder;
|
||||||
customPlayers: CustomPlayers;
|
customPlayers: CustomPlayers;
|
||||||
externalImageFetcher: ImageFetcher;
|
externalImageFetcher: ImageFetcher;
|
||||||
@@ -536,41 +961,6 @@ export class Subsonic implements MusicService {
|
|||||||
else return json as unknown as T;
|
else return json as unknown as T;
|
||||||
});
|
});
|
||||||
|
|
||||||
generateToken = (credentials: Credentials) =>
|
|
||||||
pipe(
|
|
||||||
TE.tryCatch(
|
|
||||||
() =>
|
|
||||||
this.getJSON<PingResponse>(
|
|
||||||
_.pick(credentials, "username", "password"),
|
|
||||||
"/rest/ping.view"
|
|
||||||
),
|
|
||||||
(e) => new AuthFailure(e as string)
|
|
||||||
),
|
|
||||||
TE.chain(({ type }) =>
|
|
||||||
pipe(
|
|
||||||
TE.tryCatch(
|
|
||||||
() => this.libraryFor({ ...credentials, type }),
|
|
||||||
() => new AuthFailure("Failed to get library")
|
|
||||||
),
|
|
||||||
TE.map((library) => ({ type, library }))
|
|
||||||
)
|
|
||||||
),
|
|
||||||
TE.chain(({ library, type }) =>
|
|
||||||
pipe(
|
|
||||||
library.bearerToken(credentials),
|
|
||||||
TE.map((bearer) => ({ bearer, type }))
|
|
||||||
)
|
|
||||||
),
|
|
||||||
TE.map(({ bearer, type }) => ({
|
|
||||||
serviceToken: asToken({ ...credentials, bearer, type }),
|
|
||||||
userId: credentials.username,
|
|
||||||
nickname: credentials.username,
|
|
||||||
}))
|
|
||||||
);
|
|
||||||
|
|
||||||
refreshToken = (serviceToken: string) =>
|
|
||||||
this.generateToken(parseToken(serviceToken));
|
|
||||||
|
|
||||||
getArtists = (
|
getArtists = (
|
||||||
credentials: Credentials
|
credentials: Credentials
|
||||||
): Promise<(IdName & { albumCount: number; image: BUrn | undefined })[]> =>
|
): Promise<(IdName & { albumCount: number; image: BUrn | undefined })[]> =>
|
||||||
@@ -744,346 +1134,4 @@ export class Subsonic implements MusicService {
|
|||||||
// albums: it.album.map(asAlbum),
|
// albums: it.album.map(asAlbum),
|
||||||
// }));
|
// }));
|
||||||
|
|
||||||
login = async (token: string) => this.libraryFor(parseToken(token));
|
|
||||||
|
|
||||||
private libraryFor = (
|
|
||||||
credentials: Credentials & { type: string }
|
|
||||||
): Promise<SubsonicMusicLibrary> => {
|
|
||||||
const subsonic = this;
|
|
||||||
|
|
||||||
const genericSubsonic: SubsonicMusicLibrary = {
|
|
||||||
flavour: () => "subsonic",
|
|
||||||
bearerToken: (_: Credentials) => TE.right(undefined),
|
|
||||||
artists: (q: ArtistQuery): Promise<Result<ArtistSummary>> =>
|
|
||||||
subsonic
|
|
||||||
.getArtists(credentials)
|
|
||||||
.then(slice2(q))
|
|
||||||
.then(([page, total]) => ({
|
|
||||||
total,
|
|
||||||
results: page.map((it) => ({
|
|
||||||
id: it.id,
|
|
||||||
name: it.name,
|
|
||||||
image: it.image,
|
|
||||||
})),
|
|
||||||
})),
|
|
||||||
artist: async (id: string): Promise<Artist> =>
|
|
||||||
subsonic.getArtistWithInfo(credentials, id),
|
|
||||||
albums: async (q: AlbumQuery): Promise<Result<AlbumSummary>> =>
|
|
||||||
subsonic.getAlbumList2(credentials, q),
|
|
||||||
album: (id: string): Promise<Album> => subsonic.getAlbum(credentials, id),
|
|
||||||
genres: () =>
|
|
||||||
subsonic
|
|
||||||
.getJSON<GetGenresResponse>(credentials, "/rest/getGenres")
|
|
||||||
.then((it) =>
|
|
||||||
pipe(
|
|
||||||
it.genres.genre || [],
|
|
||||||
A.filter((it) => it.albumCount > 0),
|
|
||||||
A.map((it) => it.value),
|
|
||||||
A.sort(ordString),
|
|
||||||
A.map((it) => ({ id: b64Encode(it), name: it }))
|
|
||||||
)
|
|
||||||
),
|
|
||||||
tracks: (albumId: string) =>
|
|
||||||
subsonic
|
|
||||||
.getJSON<GetAlbumResponse>(credentials, "/rest/getAlbum", {
|
|
||||||
id: albumId,
|
|
||||||
})
|
|
||||||
.then((it) => it.album)
|
|
||||||
.then((album) =>
|
|
||||||
(album.song || []).map((song) => asTrack(asAlbum(album), song, this.customPlayers))
|
|
||||||
),
|
|
||||||
track: (trackId: string) => subsonic.getTrack(credentials, trackId),
|
|
||||||
rate: (trackId: string, rating: Rating) =>
|
|
||||||
Promise.resolve(true)
|
|
||||||
.then(() => {
|
|
||||||
if (rating.stars >= 0 && rating.stars <= 5) {
|
|
||||||
return subsonic.getTrack(credentials, trackId);
|
|
||||||
} else {
|
|
||||||
throw `Invalid rating.stars value of ${rating.stars}`;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then((track) => {
|
|
||||||
const thingsToUpdate = [];
|
|
||||||
if (track.rating.love != rating.love) {
|
|
||||||
thingsToUpdate.push(
|
|
||||||
subsonic.getJSON(
|
|
||||||
credentials,
|
|
||||||
`/rest/${rating.love ? "star" : "unstar"}`,
|
|
||||||
{
|
|
||||||
id: trackId,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (track.rating.stars != rating.stars) {
|
|
||||||
thingsToUpdate.push(
|
|
||||||
subsonic.getJSON(credentials, `/rest/setRating`, {
|
|
||||||
id: trackId,
|
|
||||||
rating: rating.stars,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return Promise.all(thingsToUpdate);
|
|
||||||
})
|
|
||||||
.then(() => true)
|
|
||||||
.catch(() => false),
|
|
||||||
stream: async ({
|
|
||||||
trackId,
|
|
||||||
range,
|
|
||||||
}: {
|
|
||||||
trackId: string;
|
|
||||||
range: string | undefined;
|
|
||||||
}) =>
|
|
||||||
subsonic.getTrack(credentials, trackId).then((track) =>
|
|
||||||
subsonic
|
|
||||||
.get(
|
|
||||||
credentials,
|
|
||||||
`/rest/stream`,
|
|
||||||
{
|
|
||||||
id: trackId,
|
|
||||||
c: track.encoding.player,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
headers: pipe(
|
|
||||||
range,
|
|
||||||
O.fromNullable,
|
|
||||||
O.map((range) => ({
|
|
||||||
"User-Agent": USER_AGENT,
|
|
||||||
Range: range,
|
|
||||||
})),
|
|
||||||
O.getOrElse(() => ({
|
|
||||||
"User-Agent": USER_AGENT,
|
|
||||||
}))
|
|
||||||
),
|
|
||||||
responseType: "stream",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.then((stream) => ({
|
|
||||||
status: stream.status,
|
|
||||||
headers: {
|
|
||||||
"content-type": stream.headers["content-type"],
|
|
||||||
"content-length": stream.headers["content-length"],
|
|
||||||
"content-range": stream.headers["content-range"],
|
|
||||||
"accept-ranges": stream.headers["accept-ranges"],
|
|
||||||
},
|
|
||||||
stream: stream.data,
|
|
||||||
}))
|
|
||||||
),
|
|
||||||
coverArt: async (coverArtURN: BUrn, size?: number) =>
|
|
||||||
Promise.resolve(coverArtURN)
|
|
||||||
.then((it) => assertSystem(it, "subsonic"))
|
|
||||||
.then((it) => it.resource.split(":")[1]!)
|
|
||||||
.then((it) => subsonic.getCoverArt(credentials, it, size))
|
|
||||||
.then((res) => ({
|
|
||||||
contentType: res.headers["content-type"],
|
|
||||||
data: Buffer.from(res.data, "binary"),
|
|
||||||
}))
|
|
||||||
.catch((e) => {
|
|
||||||
logger.error(
|
|
||||||
`Failed getting coverArt for urn:'${coverArtURN}': ${e}`
|
|
||||||
);
|
|
||||||
return undefined;
|
|
||||||
}),
|
|
||||||
scrobble: async (id: string) =>
|
|
||||||
subsonic
|
|
||||||
.getJSON(credentials, `/rest/scrobble`, {
|
|
||||||
id,
|
|
||||||
submission: true,
|
|
||||||
})
|
|
||||||
.then((_) => true)
|
|
||||||
.catch(() => false),
|
|
||||||
nowPlaying: async (id: string) =>
|
|
||||||
subsonic
|
|
||||||
.getJSON(credentials, `/rest/scrobble`, {
|
|
||||||
id,
|
|
||||||
submission: false,
|
|
||||||
})
|
|
||||||
.then((_) => true)
|
|
||||||
.catch(() => false),
|
|
||||||
searchArtists: async (query: string) =>
|
|
||||||
subsonic
|
|
||||||
.search3(credentials, { query, artistCount: 20 })
|
|
||||||
.then(({ artists }) =>
|
|
||||||
artists.map((artist) => ({
|
|
||||||
id: artist.id,
|
|
||||||
name: artist.name,
|
|
||||||
image: artistImageURN({
|
|
||||||
artistId: artist.id,
|
|
||||||
artistImageURL: artist.artistImageUrl,
|
|
||||||
}),
|
|
||||||
}))
|
|
||||||
),
|
|
||||||
searchAlbums: async (query: string) =>
|
|
||||||
subsonic
|
|
||||||
.search3(credentials, { query, albumCount: 20 })
|
|
||||||
.then(({ albums }) => subsonic.toAlbumSummary(albums)),
|
|
||||||
searchTracks: async (query: string) =>
|
|
||||||
subsonic
|
|
||||||
.search3(credentials, { query, songCount: 20 })
|
|
||||||
.then(({ songs }) =>
|
|
||||||
Promise.all(
|
|
||||||
songs.map((it) => subsonic.getTrack(credentials, it.id))
|
|
||||||
)
|
|
||||||
),
|
|
||||||
playlists: async () =>
|
|
||||||
subsonic
|
|
||||||
.getJSON<GetPlaylistsResponse>(credentials, "/rest/getPlaylists")
|
|
||||||
.then((it) => it.playlists.playlist || [])
|
|
||||||
.then((playlists) => playlists.map(asPlayListSummary)),
|
|
||||||
playlist: async (id: string) =>
|
|
||||||
subsonic
|
|
||||||
.getJSON<GetPlaylistResponse>(credentials, "/rest/getPlaylist", {
|
|
||||||
id,
|
|
||||||
})
|
|
||||||
.then((it) => it.playlist)
|
|
||||||
.then((playlist) => {
|
|
||||||
let trackNumber = 1;
|
|
||||||
return {
|
|
||||||
id: playlist.id,
|
|
||||||
name: playlist.name,
|
|
||||||
coverArt: coverArtURN(playlist.coverArt),
|
|
||||||
entries: (playlist.entry || []).map((entry) => ({
|
|
||||||
...asTrack(
|
|
||||||
{
|
|
||||||
id: entry.albumId!,
|
|
||||||
name: entry.album!,
|
|
||||||
year: entry.year,
|
|
||||||
genre: maybeAsGenre(entry.genre),
|
|
||||||
artistName: entry.artist,
|
|
||||||
artistId: entry.artistId,
|
|
||||||
coverArt: coverArtURN(entry.coverArt),
|
|
||||||
},
|
|
||||||
entry,
|
|
||||||
this.customPlayers
|
|
||||||
),
|
|
||||||
number: trackNumber++,
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
createPlaylist: async (name: string) =>
|
|
||||||
subsonic
|
|
||||||
.getJSON<GetPlaylistResponse>(credentials, "/rest/createPlaylist", {
|
|
||||||
name,
|
|
||||||
})
|
|
||||||
.then((it) => it.playlist)
|
|
||||||
// todo: why is this line so similar to other playlist lines??
|
|
||||||
.then((it) => ({
|
|
||||||
id: it.id,
|
|
||||||
name: it.name,
|
|
||||||
coverArt: coverArtURN(it.coverArt),
|
|
||||||
})),
|
|
||||||
deletePlaylist: async (id: string) =>
|
|
||||||
subsonic
|
|
||||||
.getJSON<GetPlaylistResponse>(credentials, "/rest/deletePlaylist", {
|
|
||||||
id,
|
|
||||||
})
|
|
||||||
.then((_) => true),
|
|
||||||
addToPlaylist: async (playlistId: string, trackId: string) =>
|
|
||||||
subsonic
|
|
||||||
.getJSON<GetPlaylistResponse>(credentials, "/rest/updatePlaylist", {
|
|
||||||
playlistId,
|
|
||||||
songIdToAdd: trackId,
|
|
||||||
})
|
|
||||||
.then((_) => true),
|
|
||||||
removeFromPlaylist: async (playlistId: string, indicies: number[]) =>
|
|
||||||
subsonic
|
|
||||||
.getJSON<GetPlaylistResponse>(credentials, "/rest/updatePlaylist", {
|
|
||||||
playlistId,
|
|
||||||
songIndexToRemove: indicies,
|
|
||||||
})
|
|
||||||
.then((_) => true),
|
|
||||||
similarSongs: async (id: string) =>
|
|
||||||
subsonic
|
|
||||||
.getJSON<GetSimilarSongsResponse>(
|
|
||||||
credentials,
|
|
||||||
"/rest/getSimilarSongs2",
|
|
||||||
{ id, count: 50 }
|
|
||||||
)
|
|
||||||
.then((it) => it.similarSongs2.song || [])
|
|
||||||
.then((songs) =>
|
|
||||||
Promise.all(
|
|
||||||
songs.map((song) =>
|
|
||||||
subsonic
|
|
||||||
.getAlbum(credentials, song.albumId!)
|
|
||||||
.then((album) => asTrack(album, song, this.customPlayers))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
topSongs: async (artistId: string) =>
|
|
||||||
subsonic.getArtist(credentials, artistId).then(({ name }) =>
|
|
||||||
subsonic
|
|
||||||
.getJSON<GetTopSongsResponse>(credentials, "/rest/getTopSongs", {
|
|
||||||
artist: name,
|
|
||||||
count: 50,
|
|
||||||
})
|
|
||||||
.then((it) => it.topSongs.song || [])
|
|
||||||
.then((songs) =>
|
|
||||||
Promise.all(
|
|
||||||
songs.map((song) =>
|
|
||||||
subsonic
|
|
||||||
.getAlbum(credentials, song.albumId!)
|
|
||||||
.then((album) => asTrack(album, song, this.customPlayers))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
radioStations: async () => subsonic
|
|
||||||
.getJSON<GetInternetRadioStationsResponse>(
|
|
||||||
credentials,
|
|
||||||
"/rest/getInternetRadioStations"
|
|
||||||
)
|
|
||||||
.then((it) => it.internetRadioStations.internetRadioStation || [])
|
|
||||||
.then((stations) => stations.map((it) => ({
|
|
||||||
id: it.id,
|
|
||||||
name: it.name,
|
|
||||||
url: it.streamUrl,
|
|
||||||
homePage: it.homePageUrl
|
|
||||||
}))),
|
|
||||||
radioStation: async (id: string) => genericSubsonic
|
|
||||||
.radioStations()
|
|
||||||
.then(it =>
|
|
||||||
it.find(station => station.id === id)!
|
|
||||||
),
|
|
||||||
years: async () => {
|
|
||||||
const q: AlbumQuery = {
|
|
||||||
_index: 0,
|
|
||||||
_count: 100000, // FIXME: better than this ?
|
|
||||||
type: "alphabeticalByArtist",
|
|
||||||
};
|
|
||||||
const years = subsonic.getAlbumList2(credentials, q)
|
|
||||||
.then(({ results }) =>
|
|
||||||
results.map((album) => album.year || "?")
|
|
||||||
.filter((item, i, ar) => ar.indexOf(item) === i)
|
|
||||||
.sort()
|
|
||||||
.map((year) => ({
|
|
||||||
...asYear(year)
|
|
||||||
}))
|
|
||||||
.reverse()
|
|
||||||
);
|
|
||||||
return years;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (credentials.type == "navidrome") {
|
|
||||||
// todo: there does not seem to be a test for this??
|
|
||||||
return Promise.resolve({
|
|
||||||
...genericSubsonic,
|
|
||||||
flavour: () => "navidrome",
|
|
||||||
bearerToken: (credentials: Credentials) =>
|
|
||||||
pipe(
|
|
||||||
TE.tryCatch(
|
|
||||||
() =>
|
|
||||||
axios.post(
|
|
||||||
this.url.append({ pathname: "/auth/login" }).href(),
|
|
||||||
_.pick(credentials, "username", "password")
|
|
||||||
),
|
|
||||||
() => new AuthFailure("Failed to get bearerToken")
|
|
||||||
),
|
|
||||||
TE.map((it) => it.data.token as string | undefined)
|
|
||||||
),
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return Promise.resolve(genericSubsonic);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
27
src/utils.ts
27
src/utils.ts
@@ -1,3 +1,5 @@
|
|||||||
|
import { DOMParser, XMLSerializer, Node } from '@xmldom/xmldom';
|
||||||
|
|
||||||
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++) {
|
||||||
@@ -5,3 +7,28 @@ export function takeWithRepeats<T>(things:T[], count: number) {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function xmlRemoveWhitespaceNodes(node: Node) {
|
||||||
|
let child = node.firstChild;
|
||||||
|
while (child) {
|
||||||
|
const nextSibling = child.nextSibling;
|
||||||
|
if (child.nodeType === 3 && !child.nodeValue?.trim()) {
|
||||||
|
// Remove empty text nodes
|
||||||
|
node.removeChild(child);
|
||||||
|
} else {
|
||||||
|
// Recursively process child nodes
|
||||||
|
xmlRemoveWhitespaceNodes(child);
|
||||||
|
}
|
||||||
|
child = nextSibling;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function xmlTidy(xml: string | Node) {
|
||||||
|
const xmlToString = new XMLSerializer().serializeToString
|
||||||
|
|
||||||
|
const xmlString = xml instanceof Node ? xmlToString(xml as any) : xml
|
||||||
|
const doc = new DOMParser().parseFromString(xmlString, 'text/xml') as unknown as Node;
|
||||||
|
xmlRemoveWhitespaceNodes(doc);
|
||||||
|
return xmlToString(doc as any);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
Playlist,
|
Playlist,
|
||||||
SimilarArtist,
|
SimilarArtist,
|
||||||
AlbumSummary,
|
AlbumSummary,
|
||||||
RadioStation,
|
RadioStation
|
||||||
} from "../src/music_service";
|
} from "../src/music_service";
|
||||||
|
|
||||||
import { b64Encode } from "../src/b64";
|
import { b64Encode } from "../src/b64";
|
||||||
@@ -166,12 +166,6 @@ export const SAMPLE_GENRES = [
|
|||||||
];
|
];
|
||||||
export const randomGenre = () => SAMPLE_GENRES[randomInt(SAMPLE_GENRES.length)];
|
export const randomGenre = () => SAMPLE_GENRES[randomInt(SAMPLE_GENRES.length)];
|
||||||
|
|
||||||
export const aYear = (year: string) => ({ id: year, year });
|
|
||||||
|
|
||||||
export const Y2024 = aYear("2024");
|
|
||||||
export const Y2023 = aYear("2023");
|
|
||||||
export const Y1969 = aYear("1969");
|
|
||||||
|
|
||||||
export function aTrack(fields: Partial<Track> = {}): Track {
|
export function aTrack(fields: Partial<Track> = {}): Track {
|
||||||
const id = uuid();
|
const id = uuid();
|
||||||
const artist = anArtist();
|
const artist = anArtist();
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { left, right } from 'fp-ts/Either'
|
||||||
|
|
||||||
import { cryptoEncryption, jwsEncryption } from '../src/encryption';
|
import { cryptoEncryption, jwsEncryption } from '../src/encryption';
|
||||||
|
|
||||||
describe("jwsEncryption", () => {
|
describe("jwsEncryption", () => {
|
||||||
@@ -7,7 +9,7 @@ describe("jwsEncryption", () => {
|
|||||||
const value = "bobs your uncle"
|
const value = "bobs your uncle"
|
||||||
const hash = e.encrypt(value)
|
const hash = e.encrypt(value)
|
||||||
expect(hash).not.toContain(value);
|
expect(hash).not.toContain(value);
|
||||||
expect(e.decrypt(hash)).toEqual(value);
|
expect(e.decrypt(hash)).toEqual(right(value));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns different values for different secrets", () => {
|
it("returns different values for different secrets", () => {
|
||||||
@@ -29,7 +31,7 @@ describe("cryptoEncryption", () => {
|
|||||||
const value = "bobs your uncle"
|
const value = "bobs your uncle"
|
||||||
const hash = e.encrypt(value)
|
const hash = e.encrypt(value)
|
||||||
expect(hash).not.toContain(value);
|
expect(hash).not.toContain(value);
|
||||||
expect(e.decrypt(hash)).toEqual(value);
|
expect(e.decrypt(hash)).toEqual(right(value));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns different values for different secrets", () => {
|
it("returns different values for different secrets", () => {
|
||||||
@@ -42,4 +44,10 @@ describe("cryptoEncryption", () => {
|
|||||||
|
|
||||||
expect(h1).not.toEqual(h2);
|
expect(h1).not.toEqual(h2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should return left on invalid value", () => {
|
||||||
|
const e = cryptoEncryption("secret squirrel");
|
||||||
|
|
||||||
|
expect(e.decrypt("not-valid")).toEqual(left("Invalid value to decrypt"));
|
||||||
|
});
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import libxmljs from "libxmljs2";
|
|
||||||
import { FixedClock } from "../src/clock";
|
import { FixedClock } from "../src/clock";
|
||||||
|
import { xmlTidy } from "../src/utils";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
contains,
|
contains,
|
||||||
@@ -20,17 +20,17 @@ import {
|
|||||||
allOf,
|
allOf,
|
||||||
features,
|
features,
|
||||||
STAR_WARS,
|
STAR_WARS,
|
||||||
|
NO_FEATURES,
|
||||||
} from "../src/icon";
|
} from "../src/icon";
|
||||||
|
|
||||||
describe("SvgIcon", () => {
|
describe("SvgIcon", () => {
|
||||||
const xmlTidy = (xml: string) =>
|
|
||||||
libxmljs.parseXmlString(xml, { noblanks: true, net: false }).toString();
|
|
||||||
|
|
||||||
const svgIcon24 = `<?xml version="1.0" encoding="UTF-8"?>
|
const svgIcon24 = `<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||||
<path d="path1"/>
|
<path d="path1"/>
|
||||||
<path d="path2" fill="none" stroke="#000"/>
|
<path d="path2" fill="none" stroke="#000"/>
|
||||||
|
<text font-size="25" fill="none">80's</text>
|
||||||
<path d="path3"/>
|
<path d="path3"/>
|
||||||
|
<text font-size="25">80's</text>
|
||||||
</svg>
|
</svg>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@@ -61,7 +61,9 @@ describe("SvgIcon", () => {
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-4 -4 32 32">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-4 -4 32 32">
|
||||||
<path d="path1"/>
|
<path d="path1"/>
|
||||||
<path d="path2" fill="none" stroke="#000"/>
|
<path d="path2" fill="none" stroke="#000"/>
|
||||||
|
<text font-size="25" fill="none">80's</text>
|
||||||
<path d="path3"/>
|
<path d="path3"/>
|
||||||
|
<text font-size="25">80's</text>
|
||||||
</svg>
|
</svg>
|
||||||
`)
|
`)
|
||||||
);
|
);
|
||||||
@@ -110,7 +112,9 @@ describe("SvgIcon", () => {
|
|||||||
<rect x="0" y="0" width="24" height="24" fill="red"/>
|
<rect x="0" y="0" width="24" height="24" fill="red"/>
|
||||||
<path d="path1"/>
|
<path d="path1"/>
|
||||||
<path d="path2" fill="none" stroke="#000"/>
|
<path d="path2" fill="none" stroke="#000"/>
|
||||||
|
<text font-size="25" fill="none">80's</text>
|
||||||
<path d="path3"/>
|
<path d="path3"/>
|
||||||
|
<text font-size="25">80's</text>
|
||||||
</svg>
|
</svg>
|
||||||
`)
|
`)
|
||||||
);
|
);
|
||||||
@@ -134,7 +138,9 @@ describe("SvgIcon", () => {
|
|||||||
<rect x="-4" y="-4" width="36" height="36" fill="pink"/>
|
<rect x="-4" y="-4" width="36" height="36" fill="pink"/>
|
||||||
<path d="path1"/>
|
<path d="path1"/>
|
||||||
<path d="path2" fill="none" stroke="#000"/>
|
<path d="path2" fill="none" stroke="#000"/>
|
||||||
|
<text font-size="25" fill="none">80's</text>
|
||||||
<path d="path3"/>
|
<path d="path3"/>
|
||||||
|
<text font-size="25">80's</text>
|
||||||
</svg>
|
</svg>
|
||||||
`)
|
`)
|
||||||
);
|
);
|
||||||
@@ -152,7 +158,9 @@ describe("SvgIcon", () => {
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||||
<path d="path1"/>
|
<path d="path1"/>
|
||||||
<path d="path2" fill="none" stroke="#000"/>
|
<path d="path2" fill="none" stroke="#000"/>
|
||||||
|
<text font-size="25" fill="none">80's</text>
|
||||||
<path d="path3"/>
|
<path d="path3"/>
|
||||||
|
<text font-size="25">80's</text>
|
||||||
</svg>
|
</svg>
|
||||||
`)
|
`)
|
||||||
);
|
);
|
||||||
@@ -172,7 +180,9 @@ describe("SvgIcon", () => {
|
|||||||
<rect x="0" y="0" width="24" height="24" fill="red"/>
|
<rect x="0" y="0" width="24" height="24" fill="red"/>
|
||||||
<path d="path1"/>
|
<path d="path1"/>
|
||||||
<path d="path2" fill="none" stroke="#000"/>
|
<path d="path2" fill="none" stroke="#000"/>
|
||||||
|
<text font-size="25" fill="none">80's</text>
|
||||||
<path d="path3"/>
|
<path d="path3"/>
|
||||||
|
<text font-size="25">80's</text>
|
||||||
</svg>
|
</svg>
|
||||||
`)
|
`)
|
||||||
);
|
);
|
||||||
@@ -182,7 +192,7 @@ describe("SvgIcon", () => {
|
|||||||
|
|
||||||
describe("foreground color", () => {
|
describe("foreground color", () => {
|
||||||
describe("with no viewPort increase", () => {
|
describe("with no viewPort increase", () => {
|
||||||
it("should add a rectangle the same size as the original viewPort", () => {
|
it("should change the fill values", () => {
|
||||||
expect(
|
expect(
|
||||||
new SvgIcon(svgIcon24)
|
new SvgIcon(svgIcon24)
|
||||||
.with({ features: { foregroundColor: "red" } })
|
.with({ features: { foregroundColor: "red" } })
|
||||||
@@ -192,7 +202,9 @@ describe("SvgIcon", () => {
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||||
<path d="path1" fill="red"/>
|
<path d="path1" fill="red"/>
|
||||||
<path d="path2" fill="none" stroke="red"/>
|
<path d="path2" fill="none" stroke="red"/>
|
||||||
|
<text font-size="25" fill="none" stroke="red">80's</text>
|
||||||
<path d="path3" fill="red"/>
|
<path d="path3" fill="red"/>
|
||||||
|
<text font-size="25" fill="red">80's</text>
|
||||||
</svg>
|
</svg>
|
||||||
`)
|
`)
|
||||||
);
|
);
|
||||||
@@ -200,7 +212,7 @@ describe("SvgIcon", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("with a viewPort increase", () => {
|
describe("with a viewPort increase", () => {
|
||||||
it("should add a rectangle the same size as the original viewPort", () => {
|
it("should change the fill values", () => {
|
||||||
expect(
|
expect(
|
||||||
new SvgIcon(svgIcon24)
|
new SvgIcon(svgIcon24)
|
||||||
.with({
|
.with({
|
||||||
@@ -215,7 +227,9 @@ describe("SvgIcon", () => {
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-4 -4 32 32">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-4 -4 32 32">
|
||||||
<path d="path1" fill="pink"/>
|
<path d="path1" fill="pink"/>
|
||||||
<path d="path2" fill="none" stroke="pink"/>
|
<path d="path2" fill="none" stroke="pink"/>
|
||||||
|
<text font-size="25" fill="none" stroke="pink">80's</text>
|
||||||
<path d="path3" fill="pink"/>
|
<path d="path3" fill="pink"/>
|
||||||
|
<text font-size="25" fill="pink">80's</text>
|
||||||
</svg>
|
</svg>
|
||||||
`)
|
`)
|
||||||
);
|
);
|
||||||
@@ -233,7 +247,9 @@ describe("SvgIcon", () => {
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||||
<path d="path1"/>
|
<path d="path1"/>
|
||||||
<path d="path2" fill="none" stroke="#000"/>
|
<path d="path2" fill="none" stroke="#000"/>
|
||||||
|
<text font-size="25" fill="none">80's</text>
|
||||||
<path d="path3"/>
|
<path d="path3"/>
|
||||||
|
<text font-size="25">80's</text>
|
||||||
</svg>
|
</svg>
|
||||||
`)
|
`)
|
||||||
);
|
);
|
||||||
@@ -252,7 +268,51 @@ describe("SvgIcon", () => {
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||||
<path d="path1" fill="red"/>
|
<path d="path1" fill="red"/>
|
||||||
<path d="path2" fill="none" stroke="red"/>
|
<path d="path2" fill="none" stroke="red"/>
|
||||||
|
<text font-size="25" fill="none" stroke="red">80's</text>
|
||||||
<path d="path3" fill="red"/>
|
<path d="path3" fill="red"/>
|
||||||
|
<text font-size="25" fill="red">80's</text>
|
||||||
|
</svg>
|
||||||
|
`)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("text", () => {
|
||||||
|
describe("when text value specified", () => {
|
||||||
|
it("should change the text values", () => {
|
||||||
|
expect(
|
||||||
|
new SvgIcon(svgIcon24)
|
||||||
|
.with({ features: { text: "yipppeeee" } })
|
||||||
|
.toString()
|
||||||
|
).toEqual(
|
||||||
|
xmlTidy(`<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||||
|
<path d="path1"/>
|
||||||
|
<path d="path2" fill="none" stroke="#000"/>
|
||||||
|
<text font-size="25" fill="none">yipppeeee</text>
|
||||||
|
<path d="path3"/>
|
||||||
|
<text font-size="25">yipppeeee</text>
|
||||||
|
</svg>
|
||||||
|
`)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("of undefined", () => {
|
||||||
|
it("should not do anything", () => {
|
||||||
|
expect(
|
||||||
|
new SvgIcon(svgIcon24)
|
||||||
|
.with({ features: { text: undefined } })
|
||||||
|
.toString()
|
||||||
|
).toEqual(
|
||||||
|
xmlTidy(`<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||||
|
<path d="path1"/>
|
||||||
|
<path d="path2" fill="none" stroke="#000"/>
|
||||||
|
<text font-size="25" fill="none">80's</text>
|
||||||
|
<path d="path3"/>
|
||||||
|
<text font-size="25">80's</text>
|
||||||
</svg>
|
</svg>
|
||||||
`)
|
`)
|
||||||
);
|
);
|
||||||
@@ -318,10 +378,14 @@ describe("SvgIcon", () => {
|
|||||||
|
|
||||||
class DummyIcon implements Icon {
|
class DummyIcon implements Icon {
|
||||||
svg: string;
|
svg: string;
|
||||||
features: Partial<IconFeatures>;
|
features: IconFeatures;
|
||||||
|
|
||||||
constructor(svg: string, features: Partial<IconFeatures>) {
|
constructor(svg: string, features: Partial<IconFeatures>) {
|
||||||
this.svg = svg;
|
this.svg = svg;
|
||||||
this.features = features;
|
this.features = {
|
||||||
|
...NO_FEATURES,
|
||||||
|
...features
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public apply = (transformer: Transformer): Icon => transformer(this);
|
public apply = (transformer: Transformer): Icon => transformer(this);
|
||||||
@@ -350,6 +414,7 @@ describe("transform", () => {
|
|||||||
viewPortIncreasePercent: 100,
|
viewPortIncreasePercent: 100,
|
||||||
foregroundColor: "blue",
|
foregroundColor: "blue",
|
||||||
backgroundColor: "blue",
|
backgroundColor: "blue",
|
||||||
|
text: "a",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.apply(
|
.apply(
|
||||||
@@ -357,6 +422,7 @@ describe("transform", () => {
|
|||||||
features: {
|
features: {
|
||||||
foregroundColor: "override1",
|
foregroundColor: "override1",
|
||||||
backgroundColor: "override2",
|
backgroundColor: "override2",
|
||||||
|
text: "b",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
) as DummyIcon;
|
) as DummyIcon;
|
||||||
@@ -366,6 +432,7 @@ describe("transform", () => {
|
|||||||
viewPortIncreasePercent: 100,
|
viewPortIncreasePercent: 100,
|
||||||
foregroundColor: "override1",
|
foregroundColor: "override1",
|
||||||
backgroundColor: "override2",
|
backgroundColor: "override2",
|
||||||
|
text: "b",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -382,6 +449,7 @@ describe("transform", () => {
|
|||||||
viewPortIncreasePercent: 100,
|
viewPortIncreasePercent: 100,
|
||||||
foregroundColor: "blue",
|
foregroundColor: "blue",
|
||||||
backgroundColor: "blue",
|
backgroundColor: "blue",
|
||||||
|
text: "bob",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.apply(
|
.apply(
|
||||||
@@ -395,6 +463,7 @@ describe("transform", () => {
|
|||||||
viewPortIncreasePercent: 100,
|
viewPortIncreasePercent: 100,
|
||||||
foregroundColor: "blue",
|
foregroundColor: "blue",
|
||||||
backgroundColor: "blue",
|
backgroundColor: "blue",
|
||||||
|
text: "bob"
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -411,6 +480,7 @@ describe("features", () => {
|
|||||||
viewPortIncreasePercent: 100,
|
viewPortIncreasePercent: 100,
|
||||||
foregroundColor: "blue",
|
foregroundColor: "blue",
|
||||||
backgroundColor: "blue",
|
backgroundColor: "blue",
|
||||||
|
text: "foobar"
|
||||||
})
|
})
|
||||||
) as DummyIcon;
|
) as DummyIcon;
|
||||||
|
|
||||||
@@ -418,6 +488,7 @@ describe("features", () => {
|
|||||||
viewPortIncreasePercent: 100,
|
viewPortIncreasePercent: 100,
|
||||||
foregroundColor: "blue",
|
foregroundColor: "blue",
|
||||||
backgroundColor: "blue",
|
backgroundColor: "blue",
|
||||||
|
text: "foobar"
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1366,11 +1366,25 @@ describe("server", () => {
|
|||||||
"..%2F..%2Ffoo",
|
"..%2F..%2Ffoo",
|
||||||
"%2Fetc%2Fpasswd",
|
"%2Fetc%2Fpasswd",
|
||||||
".%2Fbob.js",
|
".%2Fbob.js",
|
||||||
".",
|
|
||||||
"..",
|
|
||||||
"1",
|
|
||||||
"%23%24",
|
"%23%24",
|
||||||
|
].forEach((type) => {
|
||||||
|
describe(`trying to retrieve an icon with name ${type}`, () => {
|
||||||
|
it(`should fail`, async () => {
|
||||||
|
const response = await request(server()).get(
|
||||||
|
`/icon/${type}/size/legacy`
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(response.status).toEqual(400);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("missing icons", () => {
|
||||||
|
[
|
||||||
|
"1",
|
||||||
"notAValidIcon",
|
"notAValidIcon",
|
||||||
|
"notAValidIcon:withSomeText"
|
||||||
].forEach((type) => {
|
].forEach((type) => {
|
||||||
describe(`trying to retrieve an icon with name ${type}`, () => {
|
describe(`trying to retrieve an icon with name ${type}`, () => {
|
||||||
it(`should fail`, async () => {
|
it(`should fail`, async () => {
|
||||||
@@ -1398,6 +1412,20 @@ describe("server", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("invalid text", () => {
|
||||||
|
["..", "foobar.123", "_dog_", "{ whoop }"].forEach((text) => {
|
||||||
|
describe(`trying to retrieve an icon with text ${text}`, () => {
|
||||||
|
it(`should fail`, async () => {
|
||||||
|
const response = await request(server()).get(
|
||||||
|
`/icon/yyyy:${text}/size/60`
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(response.status).toEqual(400);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("fetching", () => {
|
describe("fetching", () => {
|
||||||
[
|
[
|
||||||
"artists",
|
"artists",
|
||||||
@@ -1527,6 +1555,41 @@ describe("server", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("specifing some text", () => {
|
||||||
|
const text = "somethingWicked"
|
||||||
|
|
||||||
|
describe(`legacy icon`, () => {
|
||||||
|
it("should return the png image", async () => {
|
||||||
|
const response = await request(server()).get(
|
||||||
|
`/icon/yyyy:${text}/size/legacy`
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200);
|
||||||
|
expect(response.header["content-type"]).toEqual("image/png");
|
||||||
|
const image = await Image.load(response.body);
|
||||||
|
expect(image.width).toEqual(80);
|
||||||
|
expect(image.height).toEqual(80);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("svg icon", () => {
|
||||||
|
it(`should return an svg image with the text replaced`, async () => {
|
||||||
|
const response = await request(server()).get(
|
||||||
|
`/icon/yyyy:${text}/size/60`
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200);
|
||||||
|
expect(response.header["content-type"]).toEqual(
|
||||||
|
"image/svg+xml; charset=utf-8"
|
||||||
|
);
|
||||||
|
const svg = Buffer.from(response.body).toString();
|
||||||
|
expect(svg).toContain(
|
||||||
|
`>${text}</text>`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -39,9 +39,6 @@ import {
|
|||||||
ROCK,
|
ROCK,
|
||||||
TRIP_HOP,
|
TRIP_HOP,
|
||||||
PUNK,
|
PUNK,
|
||||||
Y2024,
|
|
||||||
Y2023,
|
|
||||||
Y1969,
|
|
||||||
aPlaylist,
|
aPlaylist,
|
||||||
aRadioStation,
|
aRadioStation,
|
||||||
} from "./builders";
|
} from "./builders";
|
||||||
@@ -562,6 +559,24 @@ describe("coverArtURI", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("iconArtURI", () => {
|
||||||
|
const bonobUrl = new URLBuilder(
|
||||||
|
"http://bonob.example.com:8080/context?search=yes"
|
||||||
|
);
|
||||||
|
|
||||||
|
describe("with no text", () => {
|
||||||
|
it("should return just the icon uri", () => {
|
||||||
|
expect(iconArtURI(bonobUrl, "mushroom").href()).toEqual("http://bonob.example.com:8080/context/icon/mushroom/size/legacy?search=yes")
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("with text", () => {
|
||||||
|
it("should return just the icon uri", () => {
|
||||||
|
expect(iconArtURI(bonobUrl, "yyyy", "foobar10000").href()).toEqual("http://bonob.example.com:8080/context/icon/yyyy:foobar10000/size/legacy?search=yes")
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("wsdl api", () => {
|
describe("wsdl api", () => {
|
||||||
const musicService = {
|
const musicService = {
|
||||||
generateToken: jest.fn(),
|
generateToken: jest.fn(),
|
||||||
@@ -1383,7 +1398,7 @@ describe("wsdl api", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("asking for a year", () => {
|
describe("asking for a year", () => {
|
||||||
const expectedYears = [Y1969, Y2023, Y2024];
|
const expectedYears = [{ year: "?" }, { year: "1969" }, { year: "1980" }, { year: "2001" }, { year: "2010" }];
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
musicLibrary.years.mockResolvedValue(expectedYears);
|
musicLibrary.years.mockResolvedValue(expectedYears);
|
||||||
@@ -1396,17 +1411,22 @@ describe("wsdl api", () => {
|
|||||||
index: 0,
|
index: 0,
|
||||||
count: 100,
|
count: 100,
|
||||||
});
|
});
|
||||||
|
const albumListForYear = (year: string, icon: URLBuilder) => ({
|
||||||
|
itemType: "albumList",
|
||||||
|
id: `year:${year}`,
|
||||||
|
title: year,
|
||||||
|
albumArtURI: icon.href(),
|
||||||
|
});
|
||||||
|
|
||||||
expect(result[0]).toEqual(
|
expect(result[0]).toEqual(
|
||||||
getMetadataResult({
|
getMetadataResult({
|
||||||
mediaCollection: expectedYears.map((year) => ({
|
mediaCollection: [
|
||||||
itemType: "albumList",
|
albumListForYear("?", iconArtURI(bonobUrl, "music")),
|
||||||
id: `year:${year.id}`,
|
albumListForYear("1969", iconArtURI(bonobUrl, "yyyy", "1969")),
|
||||||
title: year.year,
|
albumListForYear("1980", iconArtURI(bonobUrl, "yyyy", "1980")),
|
||||||
albumArtURI: iconArtURI(
|
albumListForYear("2001", iconArtURI(bonobUrl, "yyyy", "2001")),
|
||||||
bonobUrl,
|
albumListForYear("2010", iconArtURI(bonobUrl, "yyyy", "2010")),
|
||||||
"music",
|
],
|
||||||
).href(),
|
|
||||||
})),
|
|
||||||
index: 0,
|
index: 0,
|
||||||
total: expectedYears.length,
|
total: expectedYears.length,
|
||||||
})
|
})
|
||||||
@@ -1418,21 +1438,22 @@ describe("wsdl api", () => {
|
|||||||
it("should return just that page", async () => {
|
it("should return just that page", async () => {
|
||||||
const result = await ws.getMetadataAsync({
|
const result = await ws.getMetadataAsync({
|
||||||
id: `years`,
|
id: `years`,
|
||||||
index: 1,
|
index: 2,
|
||||||
count: 2,
|
count: 2,
|
||||||
});
|
});
|
||||||
expect(result[0]).toEqual(
|
expect(result[0]).toEqual(
|
||||||
getMetadataResult({
|
getMetadataResult({
|
||||||
mediaCollection: [Y2023, Y2024].map((year) => ({
|
mediaCollection: [{ year: "1980" }, { year: "2001" }].map((year) => ({
|
||||||
itemType: "albumList",
|
itemType: "albumList",
|
||||||
id: `year:${year.id}`,
|
id: `year:${year.year}`,
|
||||||
title: year.year,
|
title: year.year,
|
||||||
albumArtURI: iconArtURI(
|
albumArtURI: iconArtURI(
|
||||||
bonobUrl,
|
bonobUrl,
|
||||||
"music"
|
"yyyy",
|
||||||
|
year.year
|
||||||
).href(),
|
).href(),
|
||||||
})),
|
})),
|
||||||
index: 1,
|
index: 2,
|
||||||
total: expectedYears.length,
|
total: expectedYears.length,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
3
web/icons/yy.svg
Normal file
3
web/icons/yy.svg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<text x="50" y="75" font-size="65" text-anchor="middle" font-family="Arial, sans-serif" font-weight="bold">80s</text>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 189 B |
3
web/icons/yyyy.svg
Normal file
3
web/icons/yyyy.svg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<text x="50" y="65" font-size="35" text-anchor="middle" font-family="Arial, sans-serif" font-weight="bold">1980</text>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 190 B |
Reference in New Issue
Block a user