feat(sync): support dev&prod env

pull/4878/head
rcmerci 2022-04-11 13:32:29 +08:00 committed by Andelf
parent 7da03c0526
commit f072a29727
6 changed files with 24 additions and 5 deletions

View File

@ -36,7 +36,7 @@
"https-proxy-agent": "5.0.0",
"@sentry/electron": "2.5.1",
"posthog-js": "1.10.2",
"@andelf/rsapi": "0.0.5",
"@andelf/rsapi": "0.0.7",
"electron-deeplink": "1.0.9"
},
"devDependencies": {

View File

@ -1,6 +1,8 @@
(ns electron.file-sync-rsapi
(:require ["@andelf/rsapi" :as rsapi]))
(defn set-env [env] (rsapi/setEnv env))
(defn get-local-files-meta [graph-uuid base-path file-paths]
(rsapi/getLocalFilesMeta graph-uuid base-path (clj->js file-paths)))

View File

@ -413,6 +413,9 @@
;; file-sync-rs-apis ;;
;;;;;;;;;;;;;;;;;;;;;;;
(defmethod handle :set-env [_ args]
(apply rsapi/set-env (rest args)))
(defmethod handle :get-local-files-meta [_ args]
(apply rsapi/get-local-files-meta (rest args)))

View File

@ -17,9 +17,18 @@
(def test? false)
;; TODO: add :closure-defines in shadow-cljs.edn when prod env is ready
;; prod env
;; (goog-define FILE-SYNC-PROD? true)
;; (goog-define LOGIN-URL
;; "https://logseq.auth.us-east-1.amazoncognito.com/oauth2/authorize?client_id=7ns5v1pu8nrbs04rvdg67u4a7c&response_type=code&scope=email+openid+phone&redirect_uri=logseq%3A%2F%2Fauth-callback")
;; (goog-define API-DOMAIN "api-prod.logseq.com")
;; dev env
(goog-define FILE-SYNC-PROD? false)
(goog-define LOGIN-URL
"https://logseq-test.auth.us-east-2.amazoncognito.com/oauth2/authorize?client_id=4fi79en9aurclkb92e25hmu9ts&response_type=code&scope=email+openid+phone&redirect_uri=logseq%3A%2F%2Fauth-callback")
(goog-define API-DOMAIN "api.logseq.com")
;; :TODO: How to do this?
;; (defonce desktop? ^boolean goog.DESKTOP)

View File

@ -149,7 +149,7 @@
(defn- request-once [api-name body token]
(go
(let [resp (http/post (str "https://api.logseq.com/file-sync/" api-name)
(let [resp (http/post (str "https://" config/API-DOMAIN "/file-sync/" api-name)
{:oauth-token token
:body (js/JSON.stringify (clj->js body))})]
{:resp (<! resp)
@ -369,6 +369,7 @@
;; `RSAPI` call apis through rsapi package, supports operations on files
(defprotocol IRSAPI
(set-env [this prod?] "set environment")
(get-local-files-meta [this graph-uuid base-path filepaths] "get local files' metadata")
(get-local-all-files-meta [this graph-uuid base-path] "get all local files' metadata")
(rename-local-file [this graph-uuid base-path from to])
@ -425,6 +426,7 @@
(<! (user/refresh-id-token&access-token))
(state/get-auth-id-token)))
IRSAPI
(set-env [_ prod?] (go (<! (p->c (ipc/ipc "set-env" (if prod? "prod" "dev"))))))
(get-local-all-files-meta [_ graph-uuid base-path]
(go
(let [r (<! (retry-rsapi #(p->c (ipc/ipc "get-local-all-files-meta" graph-uuid base-path))))]
@ -1197,6 +1199,9 @@
(config/get-repo-dir (state/get-current-repo)) (state/get-current-repo)
txid *sync-state full-sync-chan stop-sync-chan remote->local-sync-chan local->remote-sync-chan
local-changes-chan)]
;; set-env
(set-env rsapi config/FILE-SYNC-PROD?)
;; drain `local-changes-chan`
(->> (repeatedly #(poll! local-changes-chan))
(take-while identity))

View File

@ -151,7 +151,7 @@
(defn login-callback [code]
(go
(let [resp (<! (http/get (str "https://api.logseq.com/auth_callback?code=" code)))]
(let [resp (<! (http/get (str "https://" config/API-DOMAIN "/auth_callback?code=" code)))]
(if (= 200 (:status resp))
(-> resp
(:body)
@ -166,7 +166,7 @@
[]
(when-let [refresh-token (state/get-auth-refresh-token)]
(go
(let [resp (<! (http/get (str "https://api.logseq.com/auth_refresh_token?refresh_token=" refresh-token)))]
(let [resp (<! (http/get (str "https://" config/API-DOMAIN "/auth_refresh_token?refresh_token=" refresh-token)))]
(if (= 400 (:status resp))
;; invalid refresh_token
(do