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.9 kB · 53 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354import { childLogger, type Logger } from '@foxxmd/logging';import type {Request} from "express";import type {RemoteIdentityParts} from "../../common/infrastructure/Atomic.ts";import { remoteHostIdentifiers, remoteHostStr } from "../../utils.ts";
export abstract class IngressNotifier {
identifier: string; logger: Logger;
remotes: Record<string, RemoteIdentityParts> = {};
protected constructor(name: string, logger: Logger) { this.identifier = name; this.logger = childLogger(logger, ['Ingress', name]); }
public trackIngress(req: Request, isRaw: boolean) { const parts = remoteHostIdentifiers(req); const id = `${parts.host}-${parts.proxy ?? ''}`;
const notifs: string[] = [];
const newRemote = this.remotes[id] === undefined; if (newRemote) { this.remotes[id] = parts; notifs.push(`Received request from a new remote address: ${remoteHostStr(req)}`); } const requestNotif = this.notifyByRequest(req, isRaw); if (requestNotif !== undefined) { notifs.push(`${!newRemote ? remoteHostStr(req) : ''} ${requestNotif}`); } const [sourceValid, sourceNotif] = this.notifyBySource(req, isRaw); if (sourceNotif !== undefined) { notifs.push(`${!newRemote && requestNotif === undefined ? `${remoteHostStr(req)} ` : ''}${sourceNotif}`); }
if(notifs.length > 0) { if (requestNotif !== undefined || sourceValid === false) { this.logger.warn(notifs.join(' | ')); } else { this.logger.info(notifs.join(' | ')) } } }
notifyByRequest(req: Request, isRaw: boolean): string | undefined { return; }
abstract notifyBySource(req: Request, isRaw: boolean): [boolean, string | undefined];}