From 471d3978ae976ba493276c8093ea96dc44e7c6f3 Mon Sep 17 00:00:00 2001 From: rcmerci Date: Thu, 9 Nov 2023 23:02:48 +0800 Subject: [PATCH] enhance(rtc): support receive s3-presign-url from ws-conn --- src/main/frontend/async_util.cljc | 19 +++++ src/main/frontend/db/rtc/const.cljs | 9 ++- src/main/frontend/db/rtc/core.cljs | 70 +++++++++++-------- src/main/frontend/db/rtc/op_mem_layer.cljs | 3 +- src/main/frontend/db/rtc/ws.cljs | 66 +++++++++++------ .../frontend/modules/outliner/pipeline.cljs | 27 +++---- src/main/frontend/persist_db/node.cljs | 12 ++-- src/test/frontend/db/rtc/mock.cljs | 2 +- 8 files changed, 131 insertions(+), 77 deletions(-) create mode 100644 src/main/frontend/async_util.cljc diff --git a/src/main/frontend/async_util.cljc b/src/main/frontend/async_util.cljc new file mode 100644 index 0000000000..db363dbba8 --- /dev/null +++ b/src/main/frontend/async_util.cljc @@ -0,0 +1,19 @@ +(ns frontend.async-util) + +(defmacro go-try + [& body] + `(cljs.core.async/go + (try + ~@body + (catch :default e# + e#)))) + + +#?(:cljs + (defn throw-err + [v] + (if (instance? ExceptionInfo v) (throw v) v))) + +(defmacro remote-ops repo)) - local-tx (op-mem-layer/get-local-tx repo) - r (with-sub-data-from-ws state - (remote-ops repo)) + local-tx (op-mem-layer/get-local-tx repo) + r (js (rtc-const/data-to-ws-encoder decoded-message)))))) (declare (.-readyState ws) WebSocketOPEN)) - (let [ws-opened-ch (chan) - token (state/get-auth-id-token) - ws* (ws-listen token (:data-from-ws-chan state) ws-opened-ch)] - ( (.-readyState ws) WebSocketOPEN)) + (let [ws-opened-ch (chan) + token (state/get-auth-id-token) + ws* (ws-listen token (:data-from-ws-chan state) ws-opened-ch)] + (clj (js/JSON.parse body) :keywordize-keys true) + {:req-id (get-req-id) + :ex-message "get s3 object failed" + :ex-data {:type :get-s3-object-failed :status status :body body}})) + resp)] + (rtc-const/data-from-ws-coercer resp*))))) (defn stop diff --git a/src/main/frontend/modules/outliner/pipeline.cljs b/src/main/frontend/modules/outliner/pipeline.cljs index c58531f054..57f11abcbb 100644 --- a/src/main/frontend/modules/outliner/pipeline.cljs +++ b/src/main/frontend/modules/outliner/pipeline.cljs @@ -1,19 +1,19 @@ (ns frontend.modules.outliner.pipeline - (:require [frontend.config :as config] - [frontend.db :as db] - [frontend.db.react :as react] - [frontend.modules.outliner.file :as file] - [logseq.outliner.datascript-report :as ds-report] - [logseq.outliner.pipeline :as outliner-pipeline] - [frontend.state :as state] - [frontend.util :as util] - [promesa.core :as p] - [frontend.persist-db :as persist-db] + (:require [clojure.core.async :as async :refer [c]] + [electron.ipc :as ipc] [frontend.persist-db.protocol :as protocol] [promesa.core :as p])) @@ -17,10 +18,11 @@ (p/resolved nil)) (c + (ipc/ipc :db-transact-data repo + (pr-str + {:blocks added-blocks + :deleted-block-uuids deleted-block-uuids})))) ( s js/JSON.parse (js->clj :keywordize-keys true) - rtc-const/data-to-ws-decoder)] + rtc-const/data-to-ws-coercer)] (handler-fn msg push-data-to-client-chan))) (set-handler-fn [_ f]