SPB Git

Repository Public

seed-next.sh 8.3 KB 101 lines shellscript

1#!/usr/bin/env bash2# Author: Simon-Pierre Boucher — contact@spboucher.ai3# File: Scripts/seed-next.sh4# Description: Adds to the TEST account what the 2.0 interface needs to be looked at and measured: real images (so thumbnails exist), a real PDF, text documents, nested folders, a folder of 1,000 small files, and a real version conflict. Synthetic content only; local test backend only.5#6# Usage: Scripts/seed-next.sh [--thousand] [--collab] [--conflict]7set -euo pipefail8cd "$(dirname "$0")/.."9. /tmp/spdrive-backend-dev/env10export SPDRIVE_URL="$SPDRIVE_TEST_URL" SPDRIVE_TOKEN="$SPDRIVE_TEST_TOKEN"11CLI="$(swift build --show-bin-path)/spdrive-cli"; [ -x "$CLI" ] || swift build -q --product spdrive-cli12api() { curl -fsS -X "$1" "$SPDRIVE_URL/api/v1$2" -H "Authorization: Bearer $SPDRIVE_TOKEN" -H 'content-type: application/json' -d "${3:-{\}}"; }13ROOT="$(api GET /sync/cursor '' | sed -E 's/.*"rootId":"([^"]+)".*/\1/')"14T="$(mktemp -d)"; trap 'rm -rf "$T"' EXIT15find_or_make() { "$CLI" find "$1" "$2" 2>/dev/null | cut -f2 | grep . || "$CLI" mkdir "$1" "$2" | cut -f2; }1617if ! "$CLI" find "$ROOT" "Atelier" >/dev/null 2>&1; then18  A="$("$CLI" mkdir "$ROOT" "Atelier" | cut -f2)"; P="$("$CLI" mkdir "$A" "Photos de chantier" | cut -f2)"; D="$("$CLI" mkdir "$A" "Dossiers clients" | cut -f2)"19  N="$("$CLI" mkdir "$D" "Maison Laurier" | cut -f2)"; "$CLI" mkdir "$N" "Plans" >/dev/null; "$CLI" mkdir "$N" "Devis" >/dev/null; "$CLI" mkdir "$N" "Correspondance" >/dev/null20  # real images drawn here (gradients and shapes): the server can make real thumbnails of them21  python3 - "$T" <<'PY'22import sys, struct, zlib, math23out = sys.argv[1]24def png(path, w, h, f):25    raw = bytearray()26    for y in range(h):27        raw.append(0)28        for x in range(w): raw.extend(f(x / w, y / h))29    def chunk(t, d): return struct.pack(">I", len(d)) + t + d + struct.pack(">I", zlib.crc32(t + d) & 0xffffffff)30    open(path, "wb").write(b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", w, h, 8, 2, 0, 0, 0)) + chunk(b"IDAT", zlib.compress(bytes(raw), 6)) + chunk(b"IEND", b""))31def c(v): return max(0, min(255, int(v)))32scenes = {33 "Façade nord": lambda x, y: (c(60 + 150 * y), c(90 + 120 * y), c(200 - 60 * y)) if y < 0.55 else ((c(150 + 60 * math.sin(x * 40)), c(110), c(80)) if abs(x - 0.5) < 0.3 else (c(70), c(120 + 40 * x), c(60))),34 "Toiture": lambda x, y: (c(200 - 120 * abs(x - 0.5) * 2 - 80 * y), c(80 + 60 * y), c(70 + 40 * x)) if y > abs(x - 0.5) * 1.1 else (c(120 + 100 * y), c(170 + 60 * y), c(235)),35 "Escalier": lambda x, y: (c(230 - 25 * int((x + y) * 9)), c(215 - 22 * int((x + y) * 9)), c(190 - 18 * int((x + y) * 9))),36 "Cuisine": lambda x, y: (c(245 - 90 * (int(x * 6) % 2)), c(240 - 60 * (int(y * 4) % 2)), c(225 - 110 * ((int(x * 6) + int(y * 4)) % 2))),37 "Jardin": lambda x, y: (c(40 + 60 * math.sin(x * 9) ** 2), c(120 + 100 * (1 - y) * math.cos(y * 5) ** 2), c(50 + 40 * y)),38 "Plan de masse": lambda x, y: (c(250), c(250), c(246)) if (int(x * 24) % 6 and int(y * 18) % 6) else (c(90), c(100), c(190)),39}40for name, f in scenes.items(): png(f"{out}/{name}.png", 720, 480, f)41PY42  for f in "$T"/*.png; do n="$(basename "$f" .png)"; sips -s format jpeg -s formatOptions 82 "$f" --out "$T/$n.jpg" >/dev/null; "$CLI" put "$T/$n.jpg" "$P" >/dev/null; done43  "$CLI" put "$T/Plan de masse.png" "$N" >/dev/null44  # a real one-page PDF45  python3 - "$T/Devis 2027-014.pdf" <<'PY'46import sys47lines = ["Devis 2027-014", "", "Maison Laurier - renovation de la cuisine", "Demolition ............ 1 800 $", "Armoires .............. 9 400 $", "Comptoir quartz ....... 3 150 $", "Total ................ 14 350 $"]48stream = "BT /F1 16 Tf 72 720 Td 20 TL " + " ".join("(%s) Tj T*" % l.replace("(", "\\(").replace(")", "\\)") for l in lines) + " ET"49objs = ["<< /Type /Catalog /Pages 2 0 R >>", "<< /Type /Pages /Kids [3 0 R] /Count 1 >>", "<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Contents 4 0 R /Resources << /Font << /F1 5 0 R >> >> >>",50        "<< /Length %d >>\nstream\n%s\nendstream" % (len(stream), stream), "<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>"]51pdf = "%PDF-1.4\n"; offs = []52for i, o in enumerate(objs): offs.append(len(pdf)); pdf += "%d 0 obj\n%s\nendobj\n" % (i + 1, o)53x = len(pdf); pdf += "xref\n0 %d\n0000000000 65535 f \n" % (len(objs) + 1) + "".join("%010d 00000 n \n" % o for o in offs) + "trailer\n<< /Size %d /Root 1 0 R >>\nstartxref\n%d\n%%%%EOF\n" % (len(objs) + 1, x)54open(sys.argv[1], "w").write(pdf)55PY56  "$CLI" put "$T/Devis 2027-014.pdf" "$N" >/dev/null57  printf '# Compte rendu de chantier\n\n- Dalle coulée lundi\n- Charpente livrée jeudi\n- Prochaine visite : le 4 décembre\n' > "$T/n.md"; "$CLI" put "$T/n.md" "$N" "Compte rendu de chantier.md" >/dev/null58  printf 'poste;montant\ndémolition;1800\narmoires;9400\ncomptoir;3150\n' > "$T/b.csv"; "$CLI" put "$T/b.csv" "$N" "Budget cuisine.csv" >/dev/null59  printf 'Bonjour,\nVoici le calendrier révisé.\n' > "$T/l.txt"; L="$("$CLI" put "$T/l.txt" "$N" "Lettre au client.txt" | cut -f2)"60  printf 'Bonjour,\nVoici le calendrier révisé, avec la livraison du 4 décembre.\n' > "$T/l.txt"; "$CLI" putversion "$T/l.txt" "$L" >/dev/null61  api PATCH "/folders/$N" '{"starred":true}' >/dev/null62  api POST /shares "{\"folderId\":\"$P\",\"label\":\"Pour l’architecte\"}" >/dev/null63  echo "seeded: Atelier ($A)"64else echo "Atelier already seeded"; fi6566for arg in "$@"; do case "$arg" in67--thousand)68  if ! "$CLI" find "$ROOT" "Mille fichiers" >/dev/null 2>&1; then69    M="$("$CLI" mkdir "$ROOT" "Mille fichiers" | cut -f2)"; mkdir "$T/k"70    for i in $(seq -w 1 1000); do printf 'pièce %s\n' "$i" > "$T/k/Pièce $i.txt"; done71    ls "$T/k" | xargs -P 8 -I{} "$CLI" put "$T/k/{}" "$M" >/dev/null72    echo "seeded: Mille fichiers ($M), $("$CLI" ls "$M" | wc -l | tr -d ' ') items"73  else echo "Mille fichiers already seeded"; fi ;;74--collab)75  # the SECOND test account shares two folders with the app's account (editor, and deposit-only), so that76  # "Partagés avec moi" has something real to browse; and the app's account gets a smart collection77  [ -n "${SPDRIVE_TEST_TOKEN2:-}" ] || { echo "no second account in the test backend"; exit 1; }78  api2() { curl -fsS -X "$1" "$SPDRIVE_URL/api/v1$2" -H "Authorization: Bearer $SPDRIVE_TEST_TOKEN2" -H 'content-type: application/json' -d "${3:-{\}}"; }79  ROOT2="$(api2 GET /sync/cursor '' | sed -E 's/.*"rootId":"([^"]+)".*/\1/')"80  if ! api GET /shared-with-me '' | grep -q "Studio partagé"; then81    E="$(SPDRIVE_TOKEN="$SPDRIVE_TEST_TOKEN2" "$CLI" mkdir "$ROOT2" "Équipe design" | cut -f2)"82    printf '# Charte graphique\n\nCouleur principale : violet. Typographie : New York pour les titres.\n' > "$T/charte.md"; SPDRIVE_TOKEN="$SPDRIVE_TEST_TOKEN2" "$CLI" put "$T/charte.md" "$E" "Charte graphique.md" >/dev/null83    printf 'lot;échéance\nmaquettes;2026-12-04\nicônes;2026-12-11\n' > "$T/plan.csv"; SPDRIVE_TOKEN="$SPDRIVE_TEST_TOKEN2" "$CLI" put "$T/plan.csv" "$E" "Planning.csv" >/dev/null84    SPDRIVE_TOKEN="$SPDRIVE_TEST_TOKEN2" "$CLI" mkdir "$E" "Maquettes" >/dev/null85    api2 POST "/folders/$E/members" "{\"email\":\"$SPDRIVE_TEST_EMAIL\",\"role\":\"editor\",\"workspaceName\":\"Studio partagé\"}" >/dev/null86    B="$(SPDRIVE_TOKEN="$SPDRIVE_TEST_TOKEN2" "$CLI" mkdir "$ROOT2" "Boîte de dépôt" | cut -f2)"87    api2 POST "/folders/$B/members" "{\"email\":\"$SPDRIVE_TEST_EMAIL\",\"role\":\"uploader\"}" >/dev/null88    echo "seeded: two folders shared with $SPDRIVE_TEST_EMAIL"89  else echo "shares already seeded"; fi90  if ! api GET /collections '' | grep -q "Images du chantier"; then91    api POST /collections '{"name":"Images du chantier","icon":"photo","color":"blue","rule":{"match":"all","conditions":[{"field":"kind","op":"is","value":"image"}],"sort":{"by":"updated","dir":"desc"}}}' >/dev/null92    api POST /collections '{"name":"Modifiés ce mois-ci","icon":"clock","color":"violet","rule":{"match":"all","conditions":[{"field":"modified","op":"within","value":30},{"field":"kind","op":"isNot","value":"video"}],"sort":{"by":"updated","dir":"desc"}}}' >/dev/null93    echo "seeded: two collections"94  fi ;;95--conflict)96  # a real conflict: the app's test account edits a file from an old version while "another device" already replaced it97  A="$(find_or_make "$ROOT" "Atelier")"98  printf 'Planning v1\n' > "$T/p.txt"; F="$("$CLI" put "$T/p.txt" "$A" "Planning $(date +%H%M%S).txt")"; ID="$(echo "$F" | cut -f2)"99  echo "conflict-base	$ID" ;;100esac; done101
Files main
Menu

Theme