Fix QR image update issue

Previously the QR image did not get updated when the contract balance
changed and we generated a new one. This happened because Github
caches external images and our image's URL did not change after
updating. Now we generate the QR image hash based on also the balance,
so the URL changes when balance is updated.

Fixes: #13
This commit is contained in:
Teemu Patja 2017-01-19 19:03:40 +02:00
parent b3909f4e60
commit 5d704b626e
No known key found for this signature in database
GPG Key ID: F5B7035E6580FD4C
2 changed files with 8 additions and 7 deletions

View File

@ -108,12 +108,12 @@
(repos/delete-hook user repo hook-id (auth-params token))))
(defn github-comment-hash
[user repo issue-number]
(digest/sha-256 (str "SALT_Yoh2looghie9jishah7aiphahphoo6udiju" user repo issue-number)))
[user repo issue-number balance]
(digest/sha-256 (str "SALT_Yoh2looghie9jishah7aiphahphoo6udiju" user repo issue-number balance)))
(defn- get-qr-url
[user repo issue-number]
(let [hash (github-comment-hash user repo issue-number)]
[user repo issue-number balance]
(let [hash (github-comment-hash user repo issue-number balance)]
(str (server-address) (format "/qr/%s/%s/bounty/%s/%s/qr.png" user repo issue-number hash))))
(defn- md-url
@ -128,7 +128,7 @@
(defn generate-comment
[user repo issue-number balance]
(let [image-url (md-image "QR Code" (get-qr-url user repo issue-number))
(let [image-url (md-image "QR Code" (get-qr-url user repo issue-number balance))
balance (str balance " ETH")
site-url (md-url (server-address) (server-address))]
(format "Current balance: %s\n%s\n%s" balance image-url site-url)))

View File

@ -6,14 +6,15 @@
[commiteth.util.images :refer :all]
[clj.qrgen :as qr]
[commiteth.eth.core :as eth]
[commiteth.github.core :as github])
[commiteth.github.core :as github]
[clojure.tools.logging :as log])
(:import [javax.imageio ImageIO]
[java.io InputStream]))
(defn ^InputStream generate-qr-code
[address]
(qr/as-input-stream
(qr/from (str "ethereum:" address) :size [256 256])))
(qr/from (str "ethereum:" address) :size [256 256])))
(defn generate-html
[address balance issue-url]