diff options
author | Tim <contact@bytim.eu> | 2025-04-22 22:16:58 +0200 |
---|---|---|
committer | Tim <contact@bytim.eu> | 2025-04-22 22:16:58 +0200 |
commit | b4c10a07cf8e721c7f46379cc9af076939319510 (patch) | |
tree | 1cdcaae3f430356cfd04e2c8d9dbbd60013aec3f /src/pics | |
parent | 75b3890d28038e3fbcd5fb7085e150decdcdd633 (diff) | |
download | pics-b4c10a07cf8e721c7f46379cc9af076939319510.tar.xz pics-b4c10a07cf8e721c7f46379cc9af076939319510.zip |
Support discord embeds
Diffstat (limited to 'src/pics')
-rw-r--r-- | src/pics/handler/view.clj | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/src/pics/handler/view.clj b/src/pics/handler/view.clj index 34ee712..2fd7710 100644 --- a/src/pics/handler/view.clj +++ b/src/pics/handler/view.clj @@ -12,24 +12,35 @@ ruresp/file-response)) (defn handle [req] - (let [file (->> (.listFiles (File. "./img/")) + (let [id (get-in req [:reitit.core/match :path-params :id]) + file (->> (.listFiles (File. "./img/")) (filter #(cstr/starts-with? (.getName ^File %) - (str (get-in req [:reitit.core/match :path-params :id]) "."))) + (str 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")] + (-> (let [last-modified (Date. (.lastModified ^File file)) + date-format (SimpleDateFormat. "dd.MM.yyyy") + date-string (.format date-format last-modified) + server-url (str "http://" (:server-name req) (when (not= (:server-port req) 80) + (str ":" (:server-port req)))) + src-url (str server-url "/src/" (.getName ^File file))] + [:html + [:head + [:title (str "pics - upload from " date-string)] + [:meta {:name "robots" :content "noindex,nofollow"}] + + [:meta {:property "og:title" :content "You received a Screenshot!"}] + [:meta {:property "og:description" :content (str "Uploaded on " date-string)}] + [:meta {:property "og:url" :content src-url}] + [:meta {:property "og:type" :content "website"}] + [:meta {:property "og:image" :content src-url}]] + [: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}}] [:div {:style {:position :fixed :bottom 0 :text-align :center @@ -39,7 +50,7 @@ :border-radius "1em" :display :inline-block :padding "0.3em"}} - (str "Uploaded on " (.format date-format last-modified))]])]] + (str "Uploaded on " date-string)]]]]) hiccup/html str ruresp/response) |