Skip to content

Commit

Permalink
enhance(sync): add connectivity-testing (logseq#10112)
Browse files Browse the repository at this point in the history
* enhance(sync): add connectivity-testing

* update connectivity-testing s3 url
  • Loading branch information
RCmerci authored Aug 31, 2023
1 parent 92ad2e4 commit 98bff93
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 41 deletions.
9 changes: 6 additions & 3 deletions src/main/frontend/config.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

(goog-define ENABLE-FILE-SYNC-PRODUCTION false)

;; this is a feature flag to enable the account tab
;; this is a feature flag to enable the account tab
;; when it launches (when pro plan launches) it should be removed
(def ENABLE-SETTINGS-ACCOUNT-TAB false)

Expand All @@ -44,7 +44,9 @@
(def REGION "us-east-1")
(def USER-POOL-ID "us-east-1_dtagLnju8")
(def IDENTITY-POOL-ID "us-east-1:d6d3b034-1631-402b-b838-b44513e93ee0")
(def OAUTH-DOMAIN "logseq-prod.auth.us-east-1.amazoncognito.com"))
(def OAUTH-DOMAIN "logseq-prod.auth.us-east-1.amazoncognito.com")
(def CONNECTIVITY-TESTING-S3-URL "https://logseq-connectivity-testing-prod.s3.us-east-1.amazonaws.com/logseq-connectivity-testing")
)

(do (def FILE-SYNC-PROD? false)
(def LOGIN-URL
Expand All @@ -56,7 +58,8 @@
(def REGION "us-east-2")
(def USER-POOL-ID "us-east-2_kAqZcxIeM")
(def IDENTITY-POOL-ID "us-east-2:cc7d2ad3-84d0-4faf-98fe-628f6b52c0a5")
(def OAUTH-DOMAIN "logseq-test2.auth.us-east-2.amazoncognito.com")))
(def OAUTH-DOMAIN "logseq-test2.auth.us-east-2.amazoncognito.com")
(def CONNECTIVITY-TESTING-S3-URL "https://logseq-connectivity-testing-prod.s3.us-east-1.amazonaws.com/logseq-connectivity-testing")))

;; Feature flags
;; =============
Expand Down
95 changes: 57 additions & 38 deletions src/main/frontend/fs/sync.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3332,55 +3332,74 @@
(when-let [graph-uuid (second @graphs-txid)]
(get-pwd graph-uuid)))


(defn- <connectivity-testing
[]
(go
(let [api-url (str "https://" config/API-DOMAIN "/logseq/version")
r1 (http/get api-url)
r2 (http/get config/CONNECTIVITY-TESTING-S3-URL)
r1* (<! r1)
r2* (<! r2)
ok? (and (= 200 (:status r1*))
(= 200 (:status r2*))
(= "OK" (:body r2*)))]
(if ok?
(println :connectivity-testing-succ)
(notification/show! (str (t :file-sync/connectivity-testing-failed)
(print-str [config/CONNECTIVITY-TESTING-S3-URL api-url])) :warning false))
ok?)))

(declare network-online-cursor)

(defn <sync-start
[]
(when-not (false? (state/enable-sync?))
(go
(when (false? @*sync-entered?)
(reset! *sync-entered? true)
(let [*sync-state (atom (sync-state))
current-user-uuid (<! (user/<user-uuid))
(go
(when (and (state/enable-sync?)
(false? @*sync-entered?)
(<! (<connectivity-testing)))
(reset! *sync-entered? true)
(let [*sync-state (atom (sync-state))
current-user-uuid (<! (user/<user-uuid))
;; put @graph-uuid & get-current-repo together,
;; prevent to get older repo dir and current graph-uuid.
_ (<! (p->c (persist-var/-load graphs-txid)))
[user-uuid graph-uuid txid] @graphs-txid
txid (or txid 0)
repo (state/get-current-repo)]
(when-not (instance? ExceptionInfo current-user-uuid)
(when (and repo
@network-online-cursor
user-uuid graph-uuid txid
(graph-sync-off? graph-uuid)
(user/logged-in?)
(not (config/demo-graph? repo)))
(try
(when-let [sm (sync-manager-singleton current-user-uuid graph-uuid
(config/get-repo-dir repo) repo
txid *sync-state)]
(when (check-graph-belong-to-current-user current-user-uuid user-uuid)
(if-not (<! (<check-remote-graph-exists graph-uuid)) ; remote graph has been deleted
(clear-graphs-txid! repo)
(do
(state/set-file-sync-state graph-uuid @*sync-state)
(state/set-file-sync-manager graph-uuid sm)
_ (<! (p->c (persist-var/-load graphs-txid)))
[user-uuid graph-uuid txid] @graphs-txid
txid (or txid 0)
repo (state/get-current-repo)]
(when-not (instance? ExceptionInfo current-user-uuid)
(when (and repo
@network-online-cursor
user-uuid graph-uuid txid
(graph-sync-off? graph-uuid)
(user/logged-in?)
(not (config/demo-graph? repo)))
(try
(when-let [sm (sync-manager-singleton current-user-uuid graph-uuid
(config/get-repo-dir repo) repo
txid *sync-state)]
(when (check-graph-belong-to-current-user current-user-uuid user-uuid)
(if-not (<! (<check-remote-graph-exists graph-uuid)) ; remote graph has been deleted
(clear-graphs-txid! repo)
(do
(state/set-file-sync-state graph-uuid @*sync-state)
(state/set-file-sync-manager graph-uuid sm)

;; update global state when *sync-state changes
(add-watch *sync-state ::update-global-state
(fn [_ _ _ n]
(state/set-file-sync-state graph-uuid n)))
(add-watch *sync-state ::update-global-state
(fn [_ _ _ n]
(state/set-file-sync-state graph-uuid n)))

(state/set-state! [:file-sync/graph-state :current-graph-uuid] graph-uuid)
(state/set-state! [:file-sync/graph-state :current-graph-uuid] graph-uuid)

(.start sm)
(.start sm)

(offer! remote->local-full-sync-chan true)
(offer! full-sync-chan true)))))
(catch :default e
(prn "Sync start error: ")
(log/error :exception e)))))
(reset! *sync-entered? false))))))
(offer! remote->local-full-sync-chan true)
(offer! full-sync-chan true)))))
(catch :default e
(prn "Sync start error: ")
(log/error :exception e)))))
(reset! *sync-entered? false)))))

(defn- restart-if-stopped!
[is-active?]
Expand Down
1 change: 1 addition & 0 deletions src/resources/dicts/en.edn
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@
:file-sync/other-user-graph "Current local graph is bound to other user's remote graph. So can't start syncing."
:file-sync/graph-deleted "The current remote graph has been deleted"
:file-sync/rsapi-cannot-upload-err "Unable to start synchronization, please check if the local time is correct."
:file-sync/connectivity-testing-failed "Network connection testing failed. Please check your network settings. Test URLs: "

:notification/clear-all "Clear all"

Expand Down
1 change: 1 addition & 0 deletions src/resources/dicts/zh-cn.edn
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@
:file-sync/other-user-graph "当前本地图谱绑定在其他用户的远程图谱上。因此无法启动同步。"
:file-sync/graph-deleted "当前远程图谱已经删除"
:file-sync/rsapi-cannot-upload-err "无法同步,请检查本机时间是否准确"
:file-sync/connectivity-testing-failed "网络连接检查失败,请检查网络设置。测试URLs: "

:notification/clear-all "清除全部通知"

Expand Down

0 comments on commit 98bff93

Please sign in to comment.