From 0685d4b06d47c7549dc5c755b50cf08c7389bc78 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Wed, 25 Mar 2026 20:19:29 +0000 Subject: [PATCH] feat(lzendpoint): Update json body parsing to support Music Assistant --- src/backend/server/endpointListenbrainzRoutes.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/backend/server/endpointListenbrainzRoutes.ts b/src/backend/server/endpointListenbrainzRoutes.ts index ada497f5..d6c97bfe 100644 --- a/src/backend/server/endpointListenbrainzRoutes.ts +++ b/src/backend/server/endpointListenbrainzRoutes.ts @@ -8,12 +8,24 @@ import ScrobbleSources from "../sources/ScrobbleSources.js"; import { nonEmptyBody } from "./middleware.js"; import { isDebugMode } from "../utils.js"; +const TEXT_WILDCARD_REGEX = new RegExp(/text\/.+/); + export const setupLZEndpointRoutes = (app: ExpressWithAsync, parentLogger: Logger, scrobbleSources: ScrobbleSources) => { const logger = childLogger(parentLogger, ['Ingress', 'Listenbrainz']); const lzJsonParser = bodyParser.json({ - type: ['text/*', 'application/json'], + type: (req) => { + // either Music Assistant, or the library it uses (libmusicbrainz), + // does not send a content-type header so we need to YOLO these requests + if(req.headers["content-type"] === undefined) { + return true; + } + if(TEXT_WILDCARD_REGEX.test(req.headers["content-type"]) || req.headers["content-type"].includes('application/json')) { + return true; + } + return false; + }, }); const nonEmptyCheck = nonEmptyBody(logger, 'LZ Endpoint'); -- 2.51.2