refactor(rtc): remake rtc-download-info-list

pull/11293/head
rcmerci 2024-05-05 21:30:01 +08:00
parent 1db86be435
commit 91a1372dfb
3 changed files with 22 additions and 24 deletions

View File

@ -67,7 +67,6 @@
(reset! *sqlite sqlite) (reset! *sqlite sqlite)
nil))) nil)))
(def repo-path "/db.sqlite") (def repo-path "/db.sqlite")
(defn- <export-db-file (defn- <export-db-file
@ -104,9 +103,9 @@
ffirst)] ffirst)]
(try (try
(let [data (sqlite-util/transit-read content)] (let [data (sqlite-util/transit-read content)]
(if-let [addresses (:addresses data)] (if-let [addresses (:addresses data)]
(assoc data :addresses (bean/->js addresses)) (assoc data :addresses (bean/->js addresses))
data)) data))
(catch :default _e ; TODO: remove this once db goes to test (catch :default _e ; TODO: remove this once db goes to test
(edn/read-string content)))))) (edn/read-string content))))))
@ -630,11 +629,7 @@
(rtc-download-info-list (rtc-download-info-list
[this token graph-uuid] [this token graph-uuid]
(async-util/c->p (js/Promise. (rtc-core2/new-task--download-info-list token graph-uuid)))
(async/go
(let [state (or @rtc-core/*state
(<! (rtc-core/<init-state token false)))]
(<? (rtc-updown/<download-info-list state graph-uuid))))))
(rtc-snapshot-graph (rtc-snapshot-graph
[this token graph-uuid] [this token graph-uuid]
@ -679,10 +674,10 @@
(comment (comment
(defn <remove-all-files! (defn <remove-all-files!
"!! Dangerous: use it only for development." "!! Dangerous: use it only for development."
[] []
(p/let [all-files (<list-all-files) (p/let [all-files (<list-all-files)
files (filter #(= (.-kind %) "file") all-files) files (filter #(= (.-kind %) "file") all-files)
dirs (filter #(= (.-kind %) "directory") all-files) dirs (filter #(= (.-kind %) "directory") all-files)
_ (p/all (map (fn [file] (.remove file)) files))] _ (p/all (map (fn [file] (.remove file)) files))]
(p/all (map (fn [dir] (.remove dir)) dirs))))) (p/all (map (fn [dir] (.remove dir)) dirs)))))

View File

@ -313,6 +313,11 @@
(let [{:keys [get-ws-create-task]} (new-task--get-ws-create--memoized (get-ws-url token))] (let [{:keys [get-ws-create-task]} (new-task--get-ws-create--memoized (get-ws-url token))]
(r.upload-download/new-task--request-download-graph get-ws-create-task graph-uuid))) (r.upload-download/new-task--request-download-graph get-ws-create-task graph-uuid)))
(defn new-task--download-info-list
[token graph-uuid]
(let [{:keys [get-ws-create-task]} (new-task--get-ws-create--memoized (get-ws-url token))]
(r.upload-download/new-task--download-info-list get-ws-create-task graph-uuid)))
;;; ================ API (ends) ================ ;;; ================ API (ends) ================
;;; subscribe debug state ;;; ;;; subscribe debug state ;;;

View File

@ -70,7 +70,6 @@
nil) nil)
(throw (ex-info "upload-graph failed" {:upload-resp upload-resp}))))))) (throw (ex-info "upload-graph failed" {:upload-resp upload-resp})))))))
(def ^:private block-type-kw->str (def ^:private block-type-kw->str
{:block-type/property "property" {:block-type/property "property"
:block-type/class "class" :block-type/class "class"
@ -183,6 +182,12 @@
(r.client/send&recv get-ws-create-task {:action "download-graph" (r.client/send&recv get-ws-create-task {:action "download-graph"
:graph-uuid graph-uuid}))) :graph-uuid graph-uuid})))
(defn new-task--download-info-list
[get-ws-create-task graph-uuid]
(m/join :download-info-list
(r.client/send&recv get-ws-create-task {:action "download-info-list"
:graph-uuid graph-uuid})))
(defn <wait-download-info-ready (defn <wait-download-info-ready
[state download-info-uuid graph-uuid timeout-ms] [state download-info-uuid graph-uuid timeout-ms]
(let [init-interval 1000 (let [init-interval 1000
@ -227,10 +232,3 @@
(<! (op-mem-layer/<sync-to-idb-layer! repo)) (<! (op-mem-layer/<sync-to-idb-layer! repo))
(<! (p->c (.storeMetadata worker-obj repo (pr-str {:graph/uuid graph-uuid})))) (<! (p->c (.storeMetadata worker-obj repo (pr-str {:graph/uuid graph-uuid}))))
(worker-state/set-rtc-downloading-graph! false))))))) (worker-state/set-rtc-downloading-graph! false)))))))
(defn <download-info-list
[state graph-uuid]
(go-try
(:download-info-list
(<? (ws/<send&receive state {:action "download-info-list"
:graph-uuid graph-uuid})))))