From d1e8e0b5dcbeb913aa8c692202a2fe2661693ec3 Mon Sep 17 00:00:00 2001 From: Thomas Hintz Date: Sun, 24 May 2026 10:28:46 -0700 Subject: [PATCH] Working snapshot create webflow. --- src/nassella.scm | 72 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 12 deletions(-) diff --git a/src/nassella.scm b/src/nassella.scm index 11e1cdd..5909d33 100644 --- a/src/nassella.scm +++ b/src/nassella.scm @@ -13,6 +13,7 @@ (chicken file) (chicken condition) (chicken sort) + (chicken random) (rename srfi-1 (delete srfi1:delete)) srfi-13 @@ -1935,18 +1936,65 @@ chmod -R 777 /opt/keys"))) (Form-Nav (@ (back-to ,(conc "/backups/" instance-id)) (submit-button "Create")))))))))) (post "/backups/:instance_id/create-submit" - (let ((instance-id (alist-ref "instance_id" (current-params) equal?)) - (app-config (with-db/transaction - (lambda (db) - (get-user-app-config db (session-user-id) instance-id))))) - ;; TODO make requests to instance control - ;; get the root domain and subdomain for instance control - ;; then call subdomain.rootdomain/hooks/queue-restic-snapshot - ;; content-type application/json - ;; data: 'path "/" 'tag tag 'request_id (generate-one?) 'version 0 - ;; then run through hmac ((hmac "instance-control-secret-key" sha256-primitive) data) - ;; then make a new page to redirect the user to that polls for status page using the request id - (redirect (conc "/config/wizard/review/" instance-id)))) + (let* ((instance-id (alist-ref "instance_id" (current-params) equal?)) + (app-config (with-db/transaction + (lambda (db) + (get-user-app-config db (session-user-id) instance-id)))) + (request-id (conc (truncate (time->seconds (current-time))) "-" (pseudo-random-integer 10000)))) + (send-instance-control-command + (alist-ref 'root-domain app-config) + (alist-ref 'subdomain (alist-ref 'instance-control (alist-ref 'config app-config))) + "queue-restic-snapshot" + (alist-ref 'webhooks-secret (alist-ref 'instance-control (alist-ref 'config app-config))) + `((path . "/") ;; unused for now but we do want root until we support backing up individual apps + (tag . ,(alist-ref 'tag (current-params))) + ;; effectively a guid, we just want something unique + (request_id . ,request-id) + (version . 0))) + (redirect (conc "/backups/" instance-id "/create-success/" request-id)))) + +(get/widgets + ("/backups/:instance_id/create-success/:request_id" + (let* ((instance-id (alist-ref "instance_id" (current-params) equal?)) + (request-id (alist-ref "request_id" (current-params) equal?)) + (app-config (with-db/transaction + (lambda (db) + (get-user-app-config db (session-user-id) instance-id)))) + (status-result + (send-instance-control-command + (alist-ref 'root-domain app-config) + (alist-ref 'subdomain (alist-ref 'instance-control (alist-ref 'config app-config))) + "restic-snapshot-status" + (alist-ref 'webhooks-secret (alist-ref 'instance-control (alist-ref 'config app-config))) + `((request_id . ,request-id) + (version . 0)))) + (complete (string=? (alist-ref 'status status-result) "complete"))) + (if complete + '() + '((meta (@ (http-equiv "refresh") (content "5"))))))) + (let* ((instance-id (alist-ref "instance_id" (current-params) equal?)) + (request-id (alist-ref "request_id" (current-params) equal?)) + (app-config (with-db/transaction + (lambda (db) + (get-user-app-config db (session-user-id) instance-id)))) + (status-result + (send-instance-control-command + (alist-ref 'root-domain app-config) + (alist-ref 'subdomain (alist-ref 'instance-control (alist-ref 'config app-config))) + "restic-snapshot-status" + (alist-ref 'webhooks-secret (alist-ref 'instance-control (alist-ref 'config app-config))) + `((request_id . ,request-id) + (version . 0)))) + (complete (string=? (alist-ref 'status status-result) "complete"))) + `(App + (Main-Container + (VStack + (h1 ,(if complete "Snapshot Complete" "Snapshot In Progress...")) + (div + (a (@ (href "/dashboard")) "Dashboard") + ,@(if complete + '() + " (snapshot will continue in the background if you leave this page)"))))))) (schematra-install)