Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/FoxxMD/multi-scrobbler. Scrobble plays from multiple sources to multiple clients docs.multi-scrobbler.app
deezer docker jellyfin koito lastfm listenbrainz maloja mopidy mpris music music-assistant plex scrobble self-hosted spotify subsonic tautulli youtube-music
Something went wrong. Try again.
1.5 kB · 46 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647import type {Logger} from "@foxxmd/logging";import type {Request} from "express";import { IngressNotifier } from "./IngressNotifier.ts";import { parseIdentifiersFromRequest } from "../../utils/RequestUtils.ts";import { requestMatchers } from "../EndpointLastfmSource.ts";
export class LFMEndpointNotifier extends IngressNotifier {
constructor(logger: Logger) { super('Lastfm Endpoint', logger); }
seenSlugs: Record<string, boolean> = {}; notifyBySource(req: Request, isRaw: boolean): [boolean, (string | undefined)] {
if(!isRaw) {
const [slug] = parseIdentifiersFromRequest(req, requestMatchers); if(slug === false) { return [false, `Request URL was not valid: ${req.baseUrl}`]; } const slugStr = slug ?? '(no slug)';
const identifier = `${slugStr}`;
if(this.seenSlugs[identifier] === undefined) { this.seenSlugs[identifier] = true; return [true, `Received a request to endpoint with -- Slug: ${slugStr} -- for the first time.`]; } }
return [true, undefined]; }
notifyByRequest(req: Request, isRaw: boolean): string | undefined { if(req.method !== 'POST') { return `Expected POST request but received ${req.method}`; } if(!isRaw) { if(!('method' in req.body)) { return `Body is missing 'method' param` } } return; }}