From 5d704b626e0f83cccb60451e0c0dfaa2706f3060 Mon Sep 17 00:00:00 2001 From: Teemu Patja Date: Thu, 19 Jan 2017 19:03:40 +0200 Subject: [PATCH] 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 --- src/clj/commiteth/github/core.clj | 10 +++++----- src/clj/commiteth/routes/qrcodes.clj | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/clj/commiteth/github/core.clj b/src/clj/commiteth/github/core.clj index ce2c327..91f0bdb 100644 --- a/src/clj/commiteth/github/core.clj +++ b/src/clj/commiteth/github/core.clj @@ -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))) diff --git a/src/clj/commiteth/routes/qrcodes.clj b/src/clj/commiteth/routes/qrcodes.clj index 89c420b..44296a4 100644 --- a/src/clj/commiteth/routes/qrcodes.clj +++ b/src/clj/commiteth/routes/qrcodes.clj @@ -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]