diff options
Diffstat (limited to 'src/pics/handler')
-rw-r--r-- | src/pics/handler/view.clj | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/pics/handler/view.clj b/src/pics/handler/view.clj new file mode 100644 index 0000000..34ee712 --- /dev/null +++ b/src/pics/handler/view.clj @@ -0,0 +1,46 @@ +(ns pics.handler.view + (:require [clojure.string :as cstr] + [ring.util.response :as ruresp] + [hiccup2.core :as hiccup]) + (:import java.io.File + java.util.Date + (java.text SimpleDateFormat))) + +(defn handle-src [req] + (->> (get-in req [:reitit.core/match :path-params :file-name]) + (str "./img/") + ruresp/file-response)) + +(defn handle [req] + (let [file (->> (.listFiles (File. "./img/")) + (filter #(cstr/starts-with? (.getName ^File %) + (str (get-in req [:reitit.core/match :path-params :id]) "."))) + first)] + (if (some? file) + (-> [:html + [:head + [:title "pics"] + [:meta {:name "robots" :content "noindex,nofollow"}]] + [:body {:style {:background-color :aquamarine}} + [:img {:src (str "/src/" (.getName ^File file)) + :style {:max-height "90%" + :max-width "90%" + :border-radius "1em" + :display :block + :margin :auto}}] + (let [last-modified (Date. (.lastModified ^File file)) + date-format (SimpleDateFormat. "dd.MM.yyyy")] + [:div {:style {:position :fixed + :bottom 0 + :text-align :center + :width "100%"}} + [:p {:style {:font-family "Arial, sans-serif" + :background-color :white + :border-radius "1em" + :display :inline-block + :padding "0.3em"}} + (str "Uploaded on " (.format date-format last-modified))]])]] + hiccup/html + str + ruresp/response) + (ruresp/not-found "Not found.")))) |