diff --git a/backend/src/app/rpc/commands/files_snapshot.clj b/backend/src/app/rpc/commands/files_snapshot.clj index c4a2fa3ce..ced6a64de 100644 --- a/backend/src/app/rpc/commands/files_snapshot.clj +++ b/backend/src/app/rpc/commands/files_snapshot.clj @@ -41,8 +41,8 @@ FROM file_change WHERE file_id = ? AND created_at < ? - AND label is not null - ORDER BY created_at desc + AND label IS NOT NULL + ORDER BY created_at DESC LIMIT ?") (defn get-file-snapshots @@ -50,7 +50,6 @@ :or {limit Long/MAX_VALUE}}] (let [start-at (or start-at (dt/now)) limit (min limit 20)] - (->> (db/exec! conn [sql:get-file-snapshots file-id start-at limit]) (mapv (fn [row] (update row :created-at dt/format-instant :rfc1123)))))) diff --git a/common/src/app/common/json.cljc b/common/src/app/common/json.cljc index 7b576e513..2b6fd0e6b 100644 --- a/common/src/app/common/json.cljc +++ b/common/src/app/common/json.cljc @@ -73,7 +73,6 @@ (str x)))] (f x)))) - #?(:cljs (defn ->clj [o & {:keys [key-fn val-fn] :or {key-fn read-kebab-key val-fn identity}}] diff --git a/frontend/src/debug.cljs b/frontend/src/debug.cljs index 58869b2f0..818028f52 100644 --- a/frontend/src/debug.cljs +++ b/frontend/src/debug.cljs @@ -12,6 +12,7 @@ [app.common.files.validate :as cfv] [app.common.json :as json] [app.common.logging :as l] + [app.common.schema :as sm] [app.common.transit :as t] [app.common.types.file :as ctf] [app.common.uri :as u] @@ -482,7 +483,7 @@ (rx/map http/conditional-decode-transit) (rx/mapcat rp/handle-response) (rx/subs! (fn [{:keys [id]}] - (println "Snapshot saved:" (str id))) + (println "Snapshot saved:" (str id) label)) (fn [cause] (js/console.log "EE:" cause)))))) @@ -490,13 +491,21 @@ [label file-id] (when-let [file-id (or (d/parse-uuid file-id) (:current-file-id @st/state))] - (->> (http/send! {:method :post - :uri (u/join cf/public-uri "api/rpc/command/restore-file-snapshot") - :body (http/transit-data {:file-id file-id :label label})}) - (rx/map http/conditional-decode-transit) - (rx/mapcat rp/handle-response) - (rx/subs! (fn [_] - (println "Snapshot restored " label) + (let [snapshot-id (sm/parse-uuid label) + label (if snapshot-id nil label) + params (cond-> {:file-id file-id} + (uuid? snapshot-id) + (assoc :id snapshot-id) + + (string? label) + (assoc :label label))] + (->> (http/send! {:method :post + :uri (u/join cf/public-uri "api/rpc/command/restore-file-snapshot") + :body (http/transit-data params)}) + (rx/map http/conditional-decode-transit) + (rx/mapcat rp/handle-response) + (rx/subs! (fn [_] + (println "Snapshot restored " (or snapshot-id label))) #_(.reload js/location)) - (fn [cause] - (js/console.log "EE:" cause)))))) + (fn [cause] + (js/console.log "EE:" cause))))))