From b7fcdc9af08870224b05cb236e49eecd8c3e8b6d Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Fri, 4 Sep 2020 10:17:36 +0800 Subject: [PATCH] Fix Github contents api auth issue --- web/src/main/frontend/github.cljs | 4 ++-- web/src/main/frontend/handler/file.cljs | 7 ++++--- web/src/main/frontend/handler/git.cljs | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/web/src/main/frontend/github.cljs b/web/src/main/frontend/github.cljs index 8e4bc3fc6..5f604f706 100644 --- a/web/src/main/frontend/github.cljs +++ b/web/src/main/frontend/github.cljs @@ -11,7 +11,7 @@ (defn get-content [token repo-url path ref ok-handler error-handler] (let [[owner repo-name] (util/get-git-owner-and-repo repo-url) - token (str "Basic "(b64/encodeString (str token ":x-oauth-basic"))) + token (str "Basic " (b64/encodeString (str owner ":" token))) url (util/format (str API "repos/%s/%s/contents/%s?ref=%s") owner repo-name @@ -35,7 +35,7 @@ (defn get-repo-permission [token repo-url current-user-name true-handler false-handler] (let [[owner repo-name] (util/get-git-owner-and-repo repo-url) - token (str "Basic "(b64/encodeString (str token ":x-oauth-basic"))) + token (str "Basic "(b64/encodeString (str owner ":" token))) url (util/format (str API "repos/%s/%s/collaborators/%s/permission") owner repo-name diff --git a/web/src/main/frontend/handler/file.cljs b/web/src/main/frontend/handler/file.cljs index 6af3c1bf8..9442576aa 100644 --- a/web/src/main/frontend/handler/file.cljs +++ b/web/src/main/frontend/handler/file.cljs @@ -26,12 +26,13 @@ content) (p/catch (fn [e] + (println "Load file failed: " path) (js/console.error e))))) (defn load-multiple-files [repo-url paths] - (let [repo-dir (util/get-repo-dir repo-url)] - (doall (mapv #(fs/read-file repo-dir %) paths)))) + (doall + (mapv #(load-file repo-url %) paths))) (defn- keep-formats [files formats] @@ -97,7 +98,7 @@ (p/then (fn [contents] (ok-handler (cond-> - (zipmap files contents) + (zipmap files contents) (seq images) (merge (zipmap images (repeat (count images) ""))))))) diff --git a/web/src/main/frontend/handler/git.cljs b/web/src/main/frontend/handler/git.cljs index 359161233..f5214b567 100644 --- a/web/src/main/frontend/handler/git.cljs +++ b/web/src/main/frontend/handler/git.cljs @@ -75,6 +75,7 @@ true)] (reset! pushing? false) (state/clear-changed-files! repo) + (notification/clear! nil) (route-handler/redirect! {:to :home}))))) (defn git-set-username-email!