towards multi-user
This commit is contained in:
@@ -9,18 +9,38 @@ export async function getStaticPaths() {
|
||||
try {
|
||||
const candidates = [
|
||||
process.env.BINCIO_DATA_DIR,
|
||||
resolve(process.cwd(), 'public', 'data'), // symlinked by `bincio render`
|
||||
resolve(process.cwd(), 'public', 'data'),
|
||||
resolve(process.cwd(), '..', 'bincio_data'),
|
||||
].filter(Boolean) as string[];
|
||||
const dataDir = candidates.find(d => { try { readFileSync(join(d, 'index.json')); return true; } catch { return false; } })!;
|
||||
const raw = readFileSync(join(dataDir, 'index.json'), 'utf-8');
|
||||
const index: BASIndex = JSON.parse(raw);
|
||||
const dataDir = candidates.find(d => {
|
||||
try { readFileSync(join(d, 'index.json')); return true; } catch { return false; }
|
||||
})!;
|
||||
|
||||
return index.activities
|
||||
const root: BASIndex = JSON.parse(readFileSync(join(dataDir, 'index.json'), 'utf-8'));
|
||||
|
||||
// Collect activities from root (single-user) or walk shards (multi-user)
|
||||
function readActivities(indexPath: string): ActivitySummary[] {
|
||||
try {
|
||||
const idx: BASIndex = JSON.parse(readFileSync(indexPath, 'utf-8'));
|
||||
const own = idx.activities ?? [];
|
||||
const fromShards = (idx.shards ?? []).flatMap(s => {
|
||||
const shardPath = join(dataDir, s.url);
|
||||
return readActivities(shardPath);
|
||||
});
|
||||
return [...own, ...fromShards];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
const activities = readActivities(join(dataDir, 'index.json'));
|
||||
const athlete = root.owner?.athlete ?? null;
|
||||
|
||||
return activities
|
||||
.filter(a => a.privacy !== 'private' && a.id)
|
||||
.map(a => ({
|
||||
params: { id: a.id },
|
||||
props: { activity: a, athlete: index.owner.athlete ?? null },
|
||||
props: { activity: a, athlete },
|
||||
}));
|
||||
} catch {
|
||||
return [];
|
||||
|
||||
Reference in New Issue
Block a user