From 716856830b015470993bb737b39f8eaa1d8ce03f Mon Sep 17 00:00:00 2001 From: Teemu Patja Date: Fri, 3 Mar 2017 16:26:11 +0200 Subject: [PATCH] Github comment image related fixes and improvements * fix crash with QR image GET request for non-existing image/bounty * take comment hash verifcation back to use * improve QR handler error handling * add missing parameter to function call --- src/clj/commiteth/github/core.clj | 4 ++-- src/clj/commiteth/routes/qrcodes.clj | 33 ++++++++++++++-------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/clj/commiteth/github/core.clj b/src/clj/commiteth/github/core.clj index 1fc9241..483c897 100644 --- a/src/clj/commiteth/github/core.clj +++ b/src/clj/commiteth/github/core.clj @@ -197,8 +197,8 @@ (assoc req :body (json/generate-string (or raw-query proper-query))))) (defn update-comment - [owner repo comment-id issue-number contract-address balance] - (let [comment (generate-comment owner repo issue-number contract-address balance)] + [owner repo comment-id issue-number contract-address balance balance-str] + (let [comment (generate-comment owner repo issue-number contract-address balance balance-str)] (log/debug (str "Updating " owner "/" repo "/" issue-number " comment #" comment-id " with contents: " comment)) (let [req (make-patch-request "repos/%s/%s/issues/comments/%s" diff --git a/src/clj/commiteth/routes/qrcodes.clj b/src/clj/commiteth/routes/qrcodes.clj index 501bb87..132d44b 100644 --- a/src/clj/commiteth/routes/qrcodes.clj +++ b/src/clj/commiteth/routes/qrcodes.clj @@ -12,25 +12,26 @@ (context "/qr" [] (GET "/:owner/:repo/bounty/:issue{[0-9]{1,9}}/:hash/qr.png" [owner repo issue hash] (log/debug "qr PNG GET" owner repo issue hash) - (when-let [{address :contract_address + (if-let [{address :contract_address repo :repo issue-id :issue_id balance :balance} (bounties/get-bounty owner repo (Integer/parseInt issue))] - (log/debug "address:" address) - (log/debug owner repo issue balance) - (log/debug hash (github/github-comment-hash owner repo issue balance)) - (if (and address - ;; TODO: temporarily disabled, for some reason hash is sometimes different (perhaps balance data type) - #_(= hash (github/github-comment-hash owner repo issue balance))) - (let [{png-data :png_data} (comment-images/get-image-data issue-id hash) - image-byte-stream (ByteArrayInputStream. png-data) - response {:status 200 - :content-type "image/png" - :headers {"cache-control" "no-cache"} - :body image-byte-stream}] - (log/debug "response" response) - response) - (bad-request)))))) + (do + (log/debug "address:" address) + (log/debug owner repo issue balance) + (log/debug hash (github/github-comment-hash owner repo issue balance)) + (if (and address + (= hash (github/github-comment-hash owner repo issue balance))) + (if-let [{png-data :png_data} + (comment-images/get-image-data + issue-id hash)] + (do (log/debug "PNG found") + {:status 200 + :content-type "image/png" + :headers {"cache-control" "no-cache"} + :body (ByteArrayInputStream. png-data)}) + (log/debug "PNG not found")))) + (bad-request)))))