🐛 Fix snapshot debug utils

This commit is contained in:
Andrey Antukh 2023-08-24 23:45:01 +02:00 committed by Andrés Moya
parent 90aab03a8f
commit 629322e505
3 changed files with 38 additions and 28 deletions

View file

@ -38,7 +38,6 @@
" from file_change " " from file_change "
" where file_id = ? " " where file_id = ? "
" and created_at < ? " " and created_at < ? "
" and label is not null "
" and data is not null " " and data is not null "
" order by created_at desc " " order by created_at desc "
" limit ?") " limit ?")

View file

@ -21,6 +21,7 @@
[app.main.data.workspace.changes :as dwc] [app.main.data.workspace.changes :as dwc]
[app.main.data.workspace.path.shortcuts] [app.main.data.workspace.path.shortcuts]
[app.main.data.workspace.shortcuts] [app.main.data.workspace.shortcuts]
[app.main.repo :as rp]
[app.main.store :as st] [app.main.store :as st]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.http :as http] [app.util.http :as http]
@ -457,38 +458,48 @@
(defn ^:export list-available-snapshots (defn ^:export list-available-snapshots
[file-id] [file-id]
(let [file-id (d/parse-uuid file-id)] (let [file-id (or (d/parse-uuid file-id)
(->> (http/send! {:method :post (:current-file-id @st/state))]
(->> (http/send! {:method :get
:uri (u/join cf/public-uri "api/rpc/command/get-file-snapshots") :uri (u/join cf/public-uri "api/rpc/command/get-file-snapshots")
:body (http/transit-data {:file-id file-id})}) :query {:file-id file-id}})
(rx/map http/conditional-decode-transit) (rx/map http/conditional-decode-transit)
(rx/map :body) (rx/mapcat rp/handle-response)
(rx/subs (fn [result] (rx/subs (fn [result]
(let [result (->> result (let [result (map (fn [row]
(map (fn [row] (update row :id str))
(update row :id str))))] result)]
(js/console.table (clj->js result)))))))) (js/console.table (clj->js result))))
(fn [cause]
(js/console.log "EE:" cause))))
nil))
(defn ^:export take-snapshot (defn ^:export take-snapshot
[file-id label] [label file-id]
(let [file-id (d/parse-uuid file-id)] (when-let [file-id (or (d/parse-uuid file-id)
(:current-file-id @st/state))]
(->> (http/send! {:method :post (->> (http/send! {:method :post
:uri (u/join cf/public-uri "api/rpc/command/take-file-snapshot") :uri (u/join cf/public-uri "api/rpc/command/take-file-snapshot")
:body (http/transit-data {:file-id file-id :label label})}) :body (http/transit-data {:file-id file-id :label label})})
(rx/map http/conditional-decode-transit) (rx/map http/conditional-decode-transit)
(rx/map :body) (rx/mapcat rp/handle-response)
(rx/subs (fn [{:keys [id]}] (rx/subs (fn [{:keys [id]}]
(println "Snapshot saved:" (str id))))))) (println "Snapshot saved:" (str id)))
(fn [cause]
(js/console.log "EE:" cause))))))
(defn ^:export restore-snapshot (defn ^:export restore-snapshot
[file-id id] [id file-id]
(let [file-id (d/parse-uuid file-id) (when-let [file-id (or (d/parse-uuid file-id)
id (d/parse-uuid id)] (:current-file-id @st/state))]
(when-let [id (d/parse-uuid id)]
(->> (http/send! {:method :post (->> (http/send! {:method :post
:uri (u/join cf/public-uri "api/rpc/command/restore-file-snapshot") :uri (u/join cf/public-uri "api/rpc/command/restore-file-snapshot")
:body (http/transit-data {:file-id file-id :id id})}) :body (http/transit-data {:file-id file-id :id id})})
(rx/map http/conditional-decode-transit) (rx/map http/conditional-decode-transit)
(rx/map :body) (rx/mapcat rp/handle-response)
(rx/subs (fn [_] (rx/subs (fn [_]
(println "Snapshot restored " id) (println "Snapshot restored " id)
#_(.reload js/location)))))) #_(.reload js/location))
(fn [cause]
(js/console.log "EE:" cause)))))))