From 445e4970a74ea120b1c4a37a2148ae4d85eed9c7 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Tue, 14 Jul 2026 11:24:08 +0200 Subject: [PATCH] :sparkles: Add Ladybug graph export to debug UI --- backend/resources/app/templates/debug.tmpl | 14 ++++++++++++ backend/src/app/http/debug.clj | 25 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/backend/resources/app/templates/debug.tmpl b/backend/resources/app/templates/debug.tmpl index 42894b570c..44097517fd 100644 --- a/backend/resources/app/templates/debug.tmpl +++ b/backend/resources/app/templates/debug.tmpl @@ -222,6 +222,20 @@ Debug Main Page +
+ Export graph (Ladybug): + Given a FILE-ID, builds the graph projection and downloads + the `.lbug` database file. + +
+
+ +
+
+ +
+
+
Import binfile: Import penpot file in binary format. diff --git a/backend/src/app/http/debug.clj b/backend/src/app/http/debug.clj index 979c9951f8..f9b40370c5 100644 --- a/backend/src/app/http/debug.clj +++ b/backend/src/app/http/debug.clj @@ -21,6 +21,7 @@ [app.config :as cf] [app.db :as db] [app.features.file-migrations :as feat.fmig] + [app.graph.ingest :as graph.ingest] [app.http.session :as session] [app.rpc.commands.auth :as auth] [app.rpc.commands.files-create :refer [create-file]] @@ -33,6 +34,7 @@ [app.storage.tmp :as tmp] [app.util.template :as tmpl] [cuerdas.core :as str] + [datoteka.fs :as fs] [datoteka.io :as io] [emoji.core :as emj] [integrant.core :as ig] @@ -326,6 +328,28 @@ "content-disposition" (str "attachmen; filename=" (first file-ids) ".penpot")}})))) +(defn graph-export-handler + "Build (or rebuild) the Ladybug graph for a file and stream the `.lbug` + database. MVP: synchronous ingest on each request." + [cfg {:keys [params]}] + (let [file-id (some-> params :file-id parse-uuid)] + (when-not file-id + (ex/raise :type :validation + :code :missing-arguments + :hint "missing file-id")) + + (let [{:keys [db-path]} (graph.ingest/ingest-file! cfg file-id :skip-stats? true)] + (when-not (fs/exists? db-path) + (ex/raise :type :internal + :code :graph-file-not-found + :hint "graph database file missing after ingest" + :file-id (str file-id) + :db-path db-path)) + {::yres/status 200 + ::yres/body (io/input-stream db-path) + ::yres/headers {"content-type" "application/octet-stream" + "content-disposition" (str "attachment; filename=" file-id ".lbug")}}))) + (defn import-handler [{:keys [::db/pool] :as cfg} {:keys [params ::session/profile-id] :as request}] (when-not (contains? params :file) @@ -573,6 +597,7 @@ ["/handle-team-features" {:handler (partial handle-team-features cfg)}] ["/file-export" {:handler (partial export-handler cfg)}] + ["/graph-export" {:handler (partial graph-export-handler cfg)}] ["/file-import" {:handler (partial import-handler cfg)}] ["/file-raw-export-import" {:handler (partial raw-export-import-handler cfg)}]]]])