SPB Git forge

spb/spb-cloud

Public
10commits 1branches 0releases
3.2 MBsize
maindefault branch
2 h agolast push
JavaScript 56.7% TypeScript 42.6%
2.9 KB · 47 lines typescript
Raw Blame History
1/**2 * Vérifications après application : aucun fichier perdu, aucun orphelin, tout dossier rattaché au bon espace,3 * pas de dossier vide, unicité des noms par dossier. Affiche l'arborescence finale.4 *   npx tsx --env-file=.env scripts/organize/verify.ts [--tree]5 */6import { prisma } from "../../lib/prisma";7import { sharedSpacesInScope } from "./common";89async function main() {10  const spaces = await sharedSpacesInScope();11  let problems = 0;12  const totalFiles = await prisma.file.count({ where: { deletedAt: null } });13  console.log(`Fichiers actifs (toute la base) : ${totalFiles}`);14  for (const s of spaces) {15    const folders = await prisma.folder.findMany({ where: { sharedSpaceId: s.id }, include: { _count: { select: { files: true, children: true } } } });16    const fids = folders.map((f) => f.id);17    const files = await prisma.file.findMany({ where: { deletedAt: null, folderId: { in: fids } }, select: { id: true, name: true, folderId: true } });18    if (!files.length && !folders.length) continue;19    // Dossiers vides20    for (const f of folders) if (f._count.files === 0 && f._count.children === 0) { console.log(`  ⚠ dossier vide : ${s.name} / ${f.name}`); problems++; }21    // Parents dans le même espace22    const byId = new Map(folders.map((f) => [f.id, f]));23    for (const f of folders) if (f.parentId && !byId.has(f.parentId)) { console.log(`  ⚠ parent hors espace : ${f.name}`); problems++; }24    // Unicité des noms25    const seen = new Set<string>();26    for (const f of files) { const k = `${f.folderId}::${f.name.toLowerCase()}`; if (seen.has(k)) { console.log(`  ⚠ nom en double : ${f.name}`); problems++; } seen.add(k); }27    // Arbre28    const roots = folders.filter((f) => !f.parentId).sort((a, b) => a.name.localeCompare(b.name, "fr"));29    console.log(`\n📁 ${s.name} — ${files.length} fichiers, ${folders.length} dossiers`);30    for (const r of roots) {31      console.log(`   ${r.name} (${r._count.files})`);32      const kids = folders.filter((f) => f.parentId === r.id).sort((a, b) => a.name.localeCompare(b.name, "fr"));33      for (const k of kids) {34        console.log(`      └ ${k.name} (${k._count.files})`);35        if (process.argv.includes("--tree")) for (const fi of files.filter((x) => x.folderId === k.id).sort((a, b) => a.name.localeCompare(b.name)).slice(0, 6)) console.log(`          · ${fi.name}`);36      }37      if (process.argv.includes("--tree")) for (const fi of files.filter((x) => x.folderId === r.id).sort((a, b) => a.name.localeCompare(b.name)).slice(0, 6)) console.log(`        · ${fi.name}`);38    }39  }40  const orphans = await prisma.file.count({ where: { deletedAt: null, folderId: null } });41  console.log(`\nFichiers à la racine (hors dossier) : ${orphans} · problèmes détectés : ${problems}`);42  await prisma.$disconnect();43  process.exit(problems ? 1 : 0);44}4546main().catch((e) => { console.error(e); process.exit(1); });47