gen image url after upload

This commit is contained in:
Travis Shears 2025-07-14 11:37:39 +02:00
parent a6a70f3c72
commit 0f3f31fc7e
2 changed files with 8 additions and 28 deletions

View file

@ -9,6 +9,10 @@
[cheshire.core :as json]
[com.travisshears.gum-utils :as utils]))
(defn if-yes-prompt [txt cb]
(when (re-find #"yes|y" (utils/prompt-for (str txt " [y/n/yes/no]")))
(cb)))
(defn base64-encode [data]
(let [bytes (.getBytes data)
encoder (Base64/getEncoder)]
@ -36,7 +40,10 @@
dir-from-cli)]
(printf "uploading file %s to dir %s\n" file-path dir)
(shell {:extra-env {"AWS_PROFILE" (:aws-profile config)}} "aws s3 cp " file-path (str "s3://" (:s3-bucket config) "/" (:s3-root config) dir "/"))
(db/insert-image (str dir "/" file-path))))
(db/insert-image (str dir "/" file-path))
(if-yes-prompt "Gen image url?" (fn []
(let [max-dimension (utils/prompt-for "Max dimension: ")]
(printf "url: %s\n" (get-image-url (str dir "/" file-path) max-dimension)))))))
(defn -main [& args]
(case (first args)

View file

@ -1,27 +0,0 @@
(ns image-service-cli.upload
(:require
[babashka.http-client :as http]
[clojure.pprint :refer [pprint]]
[cli-cms.config :refer [config]]
[cheshire.core :as json]
[clojure.string :as str]
[cli-cms.cli-utils :as utils]))
(defn fetch-snippets []
(let [res (http/get (str (:backend-host config) "/api/snippets?limit=25"))]
(json/parse-string (:body res) true)))
(defn fetch-snippet [id]
(let [res (http/get (str (:backend-host config) "/api/snippet") {:query-params {"id" id}})]
(json/parse-string (:body res) true)))
(defn view [snippet]
(utils/color-print (str "title: " (:title snippet)) "4")
(utils/color-print (str "slug: " (:slug snippet)) "4")
(utils/color-print (str "tags: " (str/join ", " (:tags snippet))) "4")
(utils/color-print "markdown: " "4")
(utils/print-markdown (:markdown snippet)))
(defn run []
(let [snippet-to-view (utils/select (map #(hash-map :value (:slug %) :item %) (fetch-snippets)))]
(view (fetch-snippet (:id snippet-to-view)))))