fix(scrobble): 'Alles' (all-time) stats returned nothing — from=0 mapped to now
The client sends from=0 for the all-time range, but the string "0" is truthy, so it was routed through _toEpochSec which maps 0 -> now, producing an empty window. Parse 'from' directly (0/absent/invalid -> all-time) instead. Affects web + Android. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
561014c83f
commit
14c0dea7e4
1 file changed
+5
-3
@@ -173,9 +173,11 @@ app.get('/scrobble/stats', async (req, res) => {
|
|||||||
if (!user) return res.status(401).json({ error: 'unauthorized' });
|
if (!user) return res.status(401).json({ error: 'unauthorized' });
|
||||||
|
|
||||||
const tz = Math.trunc(Number(req.query.tz) || 0);
|
const tz = Math.trunc(Number(req.query.tz) || 0);
|
||||||
// Default window = all time. Route through _toEpochSec only when provided (it maps 0 → now).
|
// Default window = all time. Parse `from` directly — do NOT route through _toEpochSec, which maps
|
||||||
const from = req.query.from ? _toEpochSec(req.query.from) : 0;
|
// 0 → now (so the client's explicit from=0 for "all time" would wrongly become an empty window).
|
||||||
const to = req.query.to ? _toEpochSec(req.query.to) : Math.floor(Date.now() / 1000) + 1;
|
const fromN = Number(req.query.from);
|
||||||
|
const from = Number.isFinite(fromN) && fromN > 0 ? (fromN > 1e12 ? Math.floor(fromN / 1000) : Math.floor(fromN)) : 0;
|
||||||
|
const to = req.query.to ? _toEpochSec(req.query.to) : Math.floor(Date.now() / 1000) + 1;
|
||||||
const bucket = _STATS_FMT[req.query.bucket] ? req.query.bucket : 'day';
|
const bucket = _STATS_FMT[req.query.bucket] ? req.query.bucket : 'day';
|
||||||
const fmt = _STATS_FMT[bucket];
|
const fmt = _STATS_FMT[bucket];
|
||||||
const limit = Math.min(Math.max(parseInt(req.query.limit, 10) || 20, 1), 100);
|
const limit = Math.min(Math.max(parseInt(req.query.limit, 10) || 20, 1), 100);
|
||||||
|
|||||||
Reference in new issue
Block a user