fix: prevent double URL-rewrite in nested shard resolution

rewriteActivityUrls now skips URLs that are already absolute (start with
/ or http). Before this fix, the new user→year two-level nesting caused
year-shard URLs (/data/brut/_merged/activities/X.json) to be prepended
again at the user-shard level, producing broken doubled paths and making
every activity show "Activity not found".
This commit is contained in:
Davide Scaini
2026-04-19 22:46:36 +02:00
parent 8575a7015b
commit 8a3e7831d3
+6 -4
View File
@@ -62,12 +62,14 @@ function isYearShardUrl(url: string): boolean {
}
function rewriteActivityUrls(a: ActivitySummary, shardBase: string): ActivitySummary {
// Skip if URL is already absolute (http:// or root-relative /) — avoids
// double-rewriting when shards are nested (e.g. user shard → year shard).
const needsRewrite = (url: string | null | undefined): boolean =>
!!url && !url.startsWith('http') && !url.startsWith('/');
return {
...a,
detail_url: a.detail_url && !a.detail_url.startsWith('http')
? `${shardBase}${a.detail_url}` : a.detail_url,
track_url: a.track_url && !a.track_url.startsWith('http')
? `${shardBase}${a.track_url}` : a.track_url,
detail_url: needsRewrite(a.detail_url) ? `${shardBase}${a.detail_url}` : a.detail_url,
track_url: needsRewrite(a.track_url) ? `${shardBase}${a.track_url}` : a.track_url,
};
}