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:
@@ -62,12 +62,14 @@ function isYearShardUrl(url: string): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function rewriteActivityUrls(a: ActivitySummary, shardBase: string): ActivitySummary {
|
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 {
|
return {
|
||||||
...a,
|
...a,
|
||||||
detail_url: a.detail_url && !a.detail_url.startsWith('http')
|
detail_url: needsRewrite(a.detail_url) ? `${shardBase}${a.detail_url}` : a.detail_url,
|
||||||
? `${shardBase}${a.detail_url}` : a.detail_url,
|
track_url: needsRewrite(a.track_url) ? `${shardBase}${a.track_url}` : a.track_url,
|
||||||
track_url: a.track_url && !a.track_url.startsWith('http')
|
|
||||||
? `${shardBase}${a.track_url}` : a.track_url,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user