fixing stuff after splitting jsons

This commit is contained in:
Davide Scaini
2026-04-09 15:27:00 +02:00
parent 8118f6f316
commit 084c652fdd
6 changed files with 315 additions and 17 deletions
+12 -5
View File
@@ -186,17 +186,24 @@ export async function loadTimeseries(
): Promise<Timeseries | null> {
try {
let url: string;
// Strip the leading "activities/" from timeseriesUrl so we can append it
// to whatever directory the detail JSON lives in.
const filename = timeseriesUrl.replace(/^activities\//, '');
if (timeseriesUrl.startsWith('http')) {
url = timeseriesUrl;
} else if (detailUrl.startsWith('http')) {
// detailUrl is absolute — resolve timeseries relative to its directory
// absolute detailUrl (browser shard resolution) → same directory
const dir = detailUrl.substring(0, detailUrl.lastIndexOf('/') + 1);
// timeseriesUrl is "activities/id.timeseries.json" — strip leading "activities/"
// because dir already ends with "activities/"
const filename = timeseriesUrl.replace(/^activities\//, '');
url = `${dir}${filename}`;
} else {
url = `${baseUrl}data/${timeseriesUrl}`;
// relative detailUrl — may be plain ("activities/{id}.json", single-user)
// or prefixed ("dave/_merged/activities/{id}.json", multi-user SSG prop).
// In both cases, resolve the timeseries file from the same directory.
const dir = detailUrl.includes('/')
? detailUrl.substring(0, detailUrl.lastIndexOf('/') + 1)
: '';
url = `${baseUrl}data/${dir}${filename}`;
}
return await fetchJSON<Timeseries>(url);
} catch {