Add StreamElements tips and a Feishin now-playing helper (disabled)

- src/streamelements.js: StreamElements Astro websocket, channel.tips with SE_JWT.
  Only allowed + successful tips alert, deduped by id, follows reconnect tokens.
  Off unless SE_JWT is set.
- tools/nowplaying/: PC helper that reads Feishin over MPRIS and posts title,
  artist and a small cover thumbnail to /nowplaying (Bearer NOWPLAYING_KEY). The
  cover is fetched on the LAN so the Navidrome token never leaves the PC.
  Endpoint and overlay widget are kept but switched off for now.
- .env.example: SE_JWT, NOWPLAYING_KEY.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Bashy 2026-11-20 23:18:15 +02:00
parent 553cc35b9e
commit b28e56f991
6 changed files with 253 additions and 0 deletions

28
src/routers/nowplaying.js Normal file
View file

@ -0,0 +1,28 @@
const express = require('express');
const crypto = require('crypto');
const router = express.Router();
const nowplaying = require('../nowplaying');
// POST /nowplaying (Authorization: Bearer <NOWPLAYING_KEY>) from the PC helper; no login session involved.
const key = () => process.env.NOWPLAYING_KEY || '';
function authorized(req) {
const k = key(), got = (req.get('authorization') || '').replace(/^Bearer\s+/i, '');
if (!k || !got) return false;
const a = Buffer.from(k), b = Buffer.from(got);
return a.length === b.length && crypto.timingSafeEqual(a, b);
}
const str = (v, max) => (typeof v === 'string' ? v.trim().slice(0, max) : '');
router.post('/', express.json({ limit: '300kb' }), (req, res) => {
if (!authorized(req)) return res.status(401).json({ ok: false });
const b = req.body || {};
const cover = typeof b.cover === 'string' && /^data:image\/(jpeg|png|webp);base64,[A-Za-z0-9+/=]+$/.test(b.cover) && b.cover.length < 250000 ? b.cover : null;
nowplaying.set({
playing: b.status === 'Playing',
title: str(b.title, 200), artist: str(b.artist, 200), album: str(b.album, 200),
length: Number.isFinite(b.length) ? b.length : null, cover,
});
res.json({ ok: true });
});
module.exports = router;