Просмотр исходного кода

enhance(rtc): deprecate <wrap-ensure-id&access-token

rcmerci 1 год назад
Родитель
Сommit
a2b3efa86f

+ 3 - 18
src/main/frontend/common/async_util.cljc

@@ -1,10 +1,9 @@
 (ns frontend.common.async-util
 (ns frontend.common.async-util
   "Some cljs.core.async relate macros and fns, used in worker and frontend
   "Some cljs.core.async relate macros and fns, used in worker and frontend
    namespaces. See also: https://gist.github.com/vvvvalvalval/f1250cec76d3719a8343"
    namespaces. See also: https://gist.github.com/vvvvalvalval/f1250cec76d3719a8343"
-  #?(:cljs (:require [promesa.core :as p]
-                     [logseq.common.util :as common-util]
+  #?(:cljs (:require [cljs.core.async.impl.channels :refer [ManyToManyChannel]]
                      [clojure.core.async :as async]
                      [clojure.core.async :as async]
-                     [cljs.core.async.impl.channels :refer [ManyToManyChannel]])))
+                     [logseq.common.util :as common-util])))
 
 
 #?(:cljs
 #?(:cljs
    (defn throw-err
    (defn throw-err
@@ -15,20 +14,6 @@
   [port]
   [port]
   `(throw-err (cljs.core.async/<! ~port)))
   `(throw-err (cljs.core.async/<! ~port)))
 
 
-#?(:cljs
-   (defn c->p
-     "Converts a Core.async channel to a Promise"
-     [chan]
-     (let [d (p/deferred)]
-       (if chan
-         (async/go
-           (let [result (async/<! chan)]
-             (if (instance? ExceptionInfo result)
-               (p/reject! d result)
-               (p/resolve! d result))))
-         (p/resolve! d nil))
-       d)))
-
 #?(:cljs
 #?(:cljs
    (defn drain-chan
    (defn drain-chan
      "drop all stuffs in CH, and return all of them"
      "drop all stuffs in CH, and return all of them"
@@ -87,4 +72,4 @@
                  ;; so we stop the whole go-loop
                  ;; so we stop the whole go-loop
                    (nil? e))
                    (nil? e))
                (async/close! ch))))
                (async/close! ch))))
-         ch)))
+         ch)))

+ 15 - 16
src/main/frontend/components/repo.cljs

@@ -1,29 +1,28 @@
 (ns frontend.components.repo
 (ns frontend.components.repo
-  (:require [frontend.config :as config]
+  (:require [cljs.core.async :as async :refer [<! go]]
+            [clojure.string :as string]
+            [electron.ipc :as ipc]
+            [frontend.config :as config]
             [frontend.context.i18n :refer [t]]
             [frontend.context.i18n :refer [t]]
             [frontend.db :as db]
             [frontend.db :as db]
-            [frontend.handler.repo :as repo-handler]
+            [frontend.handler.db-based.rtc :as rtc-handler]
             [frontend.handler.file-based.nfs :as nfs-handler]
             [frontend.handler.file-based.nfs :as nfs-handler]
+            [frontend.handler.file-sync :as file-sync]
+            [frontend.handler.graph :as graph]
+            [frontend.handler.notification :as notification]
+            [frontend.handler.repo :as repo-handler]
             [frontend.handler.route :as route-handler]
             [frontend.handler.route :as route-handler]
+            [frontend.handler.user :as user-handler]
+            [frontend.mobile.util :as mobile-util]
             [frontend.state :as state]
             [frontend.state :as state]
             [frontend.ui :as ui]
             [frontend.ui :as ui]
             [frontend.util :as util]
             [frontend.util :as util]
-            [rum.core :as rum]
-            [frontend.mobile.util :as mobile-util]
+            [frontend.util.fs :as fs-util]
             [frontend.util.text :as text-util]
             [frontend.util.text :as text-util]
-            [promesa.core :as p]
-            [electron.ipc :as ipc]
             [goog.object :as gobj]
             [goog.object :as gobj]
-            [cljs.core.async :as async :refer [go <!]]
-            [clojure.string :as string]
-            [frontend.handler.file-sync :as file-sync]
-            [frontend.handler.notification :as notification]
-            [frontend.util.fs :as fs-util]
-            [frontend.handler.user :as user-handler]
             [logseq.shui.ui :as shui]
             [logseq.shui.ui :as shui]
-            [frontend.handler.db-based.rtc :as rtc-handler]
-            [frontend.handler.graph :as graph]
-            [frontend.common.async-util :as async-util]))
+            [promesa.core :as p]
+            [rum.core :as rum]))
 
 
 (rum/defc normalized-graph-label
 (rum/defc normalized-graph-label
   [{:keys [url remote? GraphName GraphUUID] :as graph} on-click]
   [{:keys [url remote? GraphName GraphUUID] :as graph} on-click]
@@ -432,7 +431,7 @@
                              (->
                              (->
                               (p/do
                               (p/do
                                 (state/set-state! :rtc/uploading? true)
                                 (state/set-state! :rtc/uploading? true)
-                                (js/Promise. (rtc-handler/new-task--rtc-create-graph! repo))
+                                (rtc-handler/<rtc-create-graph! repo)
                                 (state/set-state! :rtc/uploading? false)
                                 (state/set-state! :rtc/uploading? false)
                                 (rtc-handler/<rtc-start! repo))
                                 (rtc-handler/<rtc-start! repo))
                               (p/catch (fn [error]
                               (p/catch (fn [error]

+ 43 - 45
src/main/frontend/handler/db_based/rtc.cljs

@@ -1,29 +1,28 @@
 (ns frontend.handler.db-based.rtc
 (ns frontend.handler.db-based.rtc
   "RTC handler"
   "RTC handler"
-  (:require [frontend.common.missionary-util :as c.m]
-            [frontend.config :as config]
+  (:require [frontend.config :as config]
             [frontend.db :as db]
             [frontend.db :as db]
             [frontend.handler.notification :as notification]
             [frontend.handler.notification :as notification]
             [frontend.handler.user :as user-handler]
             [frontend.handler.user :as user-handler]
             [frontend.state :as state]
             [frontend.state :as state]
             [logseq.db :as ldb]
             [logseq.db :as ldb]
             [logseq.db.sqlite.common-db :as sqlite-common-db]
             [logseq.db.sqlite.common-db :as sqlite-common-db]
-            [missionary.core :as m]
             [promesa.core :as p]))
             [promesa.core :as p]))
 
 
-(defn new-task--rtc-create-graph!
+(defn <rtc-create-graph!
   [repo]
   [repo]
-  (m/sp
-    (when-let [^js worker @state/*db-worker]
-      (m/? user-handler/task--ensure-id&access-token)
-      (let [token (state/get-auth-id-token)
-            repo-name (sqlite-common-db/sanitize-db-name repo)]
-        (c.m/<? (.rtc-async-upload-graph worker repo token repo-name))))))
+  (when-let [^js worker @state/*db-worker]
+    (p/do!
+     (js/Promise. user-handler/task--ensure-id&access-token)
+     (let [token (state/get-auth-id-token)
+           repo-name (sqlite-common-db/sanitize-db-name repo)]
+       (.rtc-async-upload-graph worker repo token repo-name)))))
 
 
 (defn <rtc-delete-graph!
 (defn <rtc-delete-graph!
   [graph-uuid]
   [graph-uuid]
   (when-let [^js worker @state/*db-worker]
   (when-let [^js worker @state/*db-worker]
-    (user-handler/<wrap-ensure-id&access-token
+    (p/do!
+     (js/Promise. user-handler/task--ensure-id&access-token)
      (let [token (state/get-auth-id-token)]
      (let [token (state/get-auth-id-token)]
        (.rtc-delete-graph worker token graph-uuid)))))
        (.rtc-delete-graph worker token graph-uuid)))))
 
 
@@ -31,23 +30,23 @@
   [graph-name graph-uuid timeout-ms]
   [graph-name graph-uuid timeout-ms]
   (when-let [^js worker @state/*db-worker]
   (when-let [^js worker @state/*db-worker]
     (state/set-state! :rtc/downloading-graph-uuid graph-uuid)
     (state/set-state! :rtc/downloading-graph-uuid graph-uuid)
-    (user-handler/<wrap-ensure-id&access-token
-     (p/let [token (state/get-auth-id-token)
-             download-info-uuid* (.rtc-request-download-graph worker token graph-uuid)
-             download-info-uuid (ldb/read-transit-str download-info-uuid*)
-             result (.rtc-wait-download-graph-info-ready worker token download-info-uuid graph-uuid timeout-ms)
-             {:keys [_download-info-uuid
-                     download-info-s3-url
-                     _download-info-tx-instant
-                     _download-info-t
-                     _download-info-created-at]
-              :as result} (ldb/read-transit-str result)]
-       (->
-        (when (not= result :timeout)
-          (assert (some? download-info-s3-url) result)
-          (.rtc-download-graph-from-s3 worker graph-uuid graph-name download-info-s3-url))
-        (p/finally
-          #(state/set-state! :rtc/downloading-graph-uuid nil)))))))
+    (p/let [_ (js/Promise. user-handler/task--ensure-id&access-token)
+            token (state/get-auth-id-token)
+            download-info-uuid* (.rtc-request-download-graph worker token graph-uuid)
+            download-info-uuid (ldb/read-transit-str download-info-uuid*)
+            result (.rtc-wait-download-graph-info-ready worker token download-info-uuid graph-uuid timeout-ms)
+            {:keys [_download-info-uuid
+                    download-info-s3-url
+                    _download-info-tx-instant
+                    _download-info-t
+                    _download-info-created-at]
+             :as result} (ldb/read-transit-str result)]
+      (->
+       (when (not= result :timeout)
+         (assert (some? download-info-s3-url) result)
+         (.rtc-download-graph-from-s3 worker graph-uuid graph-name download-info-s3-url))
+       (p/finally
+         #(state/set-state! :rtc/downloading-graph-uuid nil))))))
 
 
 (defn <rtc-stop!
 (defn <rtc-stop!
   []
   []
@@ -78,23 +77,22 @@
 
 
 (defn <get-remote-graphs
 (defn <get-remote-graphs
   []
   []
-  (let [^js worker @state/*db-worker]
-    (user-handler/<wrap-ensure-id&access-token
-     (let [token (state/get-auth-id-token)]
-       (when worker
-         (p/let [result (.rtc-get-graphs worker token)
-                 graphs (ldb/read-transit-str result)
-                 result (->> graphs
-                             (remove (fn [graph] (= (:graph-status graph) "deleting")))
-                             (mapv (fn [graph]
-                                     (merge
-                                      (let [url (str config/db-version-prefix (:graph-name graph))]
-                                        {:url url
-                                         :GraphName (:graph-name graph)
-                                         :GraphUUID (:graph-uuid graph)
-                                         :rtc-graph? true})
-                                      (dissoc graph :graph-uuid :graph-name)))))]
-           (state/set-state! :rtc/graphs result)))))))
+  (when-let [^js worker @state/*db-worker]
+    (p/let [_ (js/Promise. user-handler/task--ensure-id&access-token)
+            token (state/get-auth-id-token)
+            result (.rtc-get-graphs worker token)
+            graphs (ldb/read-transit-str result)
+            result (->> graphs
+                        (remove (fn [graph] (= (:graph-status graph) "deleting")))
+                        (mapv (fn [graph]
+                                (merge
+                                 (let [url (str config/db-version-prefix (:graph-name graph))]
+                                   {:url url
+                                    :GraphName (:graph-name graph)
+                                    :GraphUUID (:graph-uuid graph)
+                                    :rtc-graph? true})
+                                 (dissoc graph :graph-uuid :graph-name)))))]
+      (state/set-state! :rtc/graphs result))))
 
 
 (defn <rtc-get-users-info
 (defn <rtc-get-users-info
   []
   []

+ 1 - 0
src/main/frontend/handler/user.clj

@@ -2,6 +2,7 @@
   "Macros.")
   "Macros.")
 
 
 (defmacro <wrap-ensure-id&access-token
 (defmacro <wrap-ensure-id&access-token
+  "Deprecated"
   [& body]
   [& body]
   `(cljs.core.async/go
   `(cljs.core.async/go
      (if-some [exp# (cljs.core.async/<! (<ensure-id&access-token))]
      (if-some [exp# (cljs.core.async/<! (<ensure-id&access-token))]