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.
2.3 kB · 81 lines
TSX
at strict
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081import type {TrackStringOptions} from "../../core/Atomic";import React, {type ReactElement, Fragment} from "react";import {defaultBuildTrackStringTransformers} from "../../core/StringUtils";import type {Dayjs} from 'dayjs';import dayjs from 'dayjs';
export const buildTrackStringReactOptions: TrackStringOptions<ReactElement> = { transformers: { ...defaultBuildTrackStringTransformers, reducer: arr => { const allFrags = arr.map((x, index) => { if (typeof x === 'string') { return <Fragment key={index}>{x}</Fragment>; } else { return x; } }); const spacedFrags = allFrags.reduce((acc, curr, index) => { return acc.concat([curr, <Fragment key={`${index} space`}> </Fragment>]); }, []); return <Fragment>{spacedFrags}</Fragment> } }}
const LOG_LINE_REGEX = new RegExp(/\[(?<timestamp>.+)]\s+(?<level>\w+)\s*:\s*(?<message>(?:.|\n)*)/m, 'm');export const parseLogLine = (line: string) => { const match = line.match(LOG_LINE_REGEX); if (match === null) { return undefined; } return { timestamp: match[1], level: match[2], message: match[3] }}
export interface DateFormatOptions { includeRelative?: boolean includeDate?: boolean}
export const DAYJS_TIMEZ_FORMAT = 'HH:mm:ssZ';export const DAYJS_TIME_FORMAT = 'HH:mm:ss';export const DAYJS_DATE_FORMAT = 'YYYY-MM-DD';
export const isoToHuman = (iso?: string | null, opts?: DateFormatOptions) => { const { includeRelative = false, includeDate } = opts;
if(iso === undefined || iso === null) { return 'N/A'; }
const parts = [];
const date = dayjs(iso); let useDate = includeDate; let now: Dayjs; if(useDate === undefined) { now = dayjs(); if(now.isSame(date, 'day')) { useDate = false; } } if(useDate) { parts.push(date.format(DAYJS_DATE_FORMAT)); } parts.push(date.format(DAYJS_TIME_FORMAT));
if(includeRelative) { parts.push(`(${date.fromNow()})`); }
return parts.join(' ');}
export const baseUrl = 'api/';