mirror of
https://github.com/IliesAllali/parenthese.git
synced 2026-11-09 23:50:58 +00:00
Galaxie familiale : personnes, unions et filiations, photos, vidéos et voix sur chaque personne, partage par lien avec consultation sans compte et contributions validées par le propriétaire. Auto-hébergeable avec Docker. Licence PolyForm Noncommercial 1.0.0. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
26 lines
1.6 KiB
JavaScript
26 lines
1.6 KiB
JavaScript
// Récupère un arbre par le chemin visiteur (slug → unlock → graph) et l'enregistre comme fixture.
|
|
// Usage : TREE_PASSWORD='...' node fetch-fixture.mjs <slug> [nomFixture]
|
|
import { writeFileSync } from 'node:fs'
|
|
|
|
const BASE = process.env.PARENTHESE_BASE || 'https://app.parenthese.io'
|
|
const [slug, fixtureName = 'famille'] = process.argv.slice(2)
|
|
const PASSWORD = process.env.TREE_PASSWORD
|
|
if (!slug || !PASSWORD) { console.error("Usage : TREE_PASSWORD='...' node fetch-fixture.mjs <slug> [nomFixture]"); process.exit(1) }
|
|
|
|
async function j(path, opts = {}) {
|
|
const r = await fetch(BASE + path, { ...opts, headers: { 'Content-Type': 'application/json', ...(opts.headers || {}) } })
|
|
const text = await r.text()
|
|
let body; try { body = JSON.parse(text) } catch { body = text }
|
|
if (!r.ok) throw new Error(`${r.status} ${path} ${typeof body === 'string' ? body.slice(0, 200) : JSON.stringify(body).slice(0, 200)}`)
|
|
return body
|
|
}
|
|
|
|
const resolved = await j(`/api/arbre/${encodeURIComponent(slug)}`)
|
|
const treeId = resolved.tree.id
|
|
const unlock = await j(`/trees/${treeId}/access/unlock`, { method: 'POST', body: JSON.stringify({ password: PASSWORD }) })
|
|
const token = unlock.token || unlock.accessToken
|
|
const g = await j(`/trees/${treeId}/graph?t=${Date.now()}`, { headers: { Authorization: `Bearer ${token}` } })
|
|
const graph = g.graph
|
|
console.log(resolved.tree.name, '·', graph.persons.length, 'personnes,', graph.unions.length, 'unions,', graph.filiations.length, 'filiations,', graph.medias.length, 'médias')
|
|
writeFileSync(new URL(`./fixtures/${fixtureName}-graph.json`, import.meta.url), JSON.stringify({ treeId, rootPersonId: g.rootPersonId, graph }, null, 1))
|