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
This commit is contained in:
Teemu Patja 2017-03-03 16:26:11 +02:00
parent 442f5c7821
commit 716856830b
No known key found for this signature in database
GPG Key ID: F5B7035E6580FD4C
2 changed files with 19 additions and 18 deletions

View File

@ -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"

View File

@ -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)))))