From 59c272ece9a4177887bbcaa0a0923d26ec254191 Mon Sep 17 00:00:00 2001 From: Eric Ihli Date: Fri, 24 Sep 2021 22:02:47 -0500 Subject: [PATCH] Update image handler to serve files relatively --- README.org | 18 ++++++++++++ .../public/images/course-regenerate-128.png | Bin 0 -> 311 bytes web/src/com/darklimericks/server/handlers.clj | 4 +-- .../com/darklimericks/server/limericks.clj | 7 +++-- web/src/com/darklimericks/util/identicon.clj | 26 +++++++++++++----- 5 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 web/resources/public/images/course-regenerate-128.png diff --git a/README.org b/README.org index 37721ab..8c57621 100644 --- a/README.org +++ b/README.org @@ -36,3 +36,21 @@ The world's largest metal limericks archive on the Web. Requires [[https://github.com/tachyons-css/tachyons/][Tachyons CSS]]. There is a symlink in ~web/resources/public~ to the pre-built ~tachyons.css~ and ~tachyons.min.css~ found in the repo. Build ~.jar~ with ~clojure -X:depstar uberjar :jar prhyme.jar~. + +* Deployment + +Since I'm developing this independently, it's not a very robust deployment system. + +It's nice to have some parts of the repo available on the server; the db/kv scripts for example. + +But obviously the album images and the data in the db/kv are going to be different between local and prod. + +You can use ~rsync~ with ~--exclude~ to only sync over the code bits. + +~rsync --exclude '*/data/*' --exclude '*/images/*' -aLP ./ root@darklimericks.com:/root/darklimericks/~ + +Note the ~-L~ to follow symlinks. Locally, I'm symlinking tachyons.css. + +The other shortcut I'm taking is that images are stored and served relative to the path of the running application. + +That means you need to launch the jar file from the ~web~ directory. diff --git a/web/resources/public/images/course-regenerate-128.png b/web/resources/public/images/course-regenerate-128.png new file mode 100644 index 0000000000000000000000000000000000000000..d9c34eea97820939f72a61731d90ece62aa3f828 GIT binary patch literal 311 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1SEZ8zRdwr|2$nBLn>~)y?cX1N#{!sd&PW zX8O|mJRjC_05wVQGc (:album/name album) - string/lower-case - (string/replace #" " "-")) 128)) + (let [icon (identicon/generate + (-> (:album/name album) + string/lower-case + (string/replace #" " "-")) 128)])) (db.limericks/insert-user-limerick db session-id diff --git a/web/src/com/darklimericks/util/identicon.clj b/web/src/com/darklimericks/util/identicon.clj index 5c23aa5..b7f4b9f 100644 --- a/web/src/com/darklimericks/util/identicon.clj +++ b/web/src/com/darklimericks/util/identicon.clj @@ -106,18 +106,30 @@ (defn generate "Make a new avatar." [identifier size] - (let - [tile-size (quot size tiles-per-side) - md5 (digest/md5 identifier) - icon (BufferedImage. size size BufferedImage/TYPE_INT_RGB) - [r g b] (get-color (first (to-numbers md5))) - color (Color. r g b) - draw (.createGraphics icon)] + (let [tile-size (quot size tiles-per-side) + md5 (digest/md5 identifier) + icon (BufferedImage. size size BufferedImage/TYPE_INT_RGB) + [r g b] (get-color (first (to-numbers md5))) + color (Color. r g b) + draw (.createGraphics icon)] (fill-background draw size) (.setColor draw color) (draw-it draw tile-size 0 (to-bools md5)) (ImageIO/write icon "png" (File. (file-name identifier size))) file-name)) +(defn generate-sans-write + "Make a new avatar." + [identifier size] + (let [tile-size (quot size tiles-per-side) + md5 (digest/md5 identifier) + icon (BufferedImage. size size BufferedImage/TYPE_INT_RGB) + [r g b] (get-color (first (to-numbers md5))) + color (Color. r g b) + draw (.createGraphics icon)] + (fill-background draw size) + (.setColor draw color) + (draw-it draw tile-size 0 (to-bools md5)))) + (comment (generate "foobar-bazz" 128))