hook up gen image url action
This commit is contained in:
parent
1ca64db2ad
commit
6f78e10132
4 changed files with 13 additions and 7 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -2,3 +2,4 @@
|
||||||
.lsp
|
.lsp
|
||||||
config.edn
|
config.edn
|
||||||
.clj-kondo
|
.clj-kondo
|
||||||
|
db.db
|
||||||
|
|
|
||||||
BIN
db.db
BIN
db.db
Binary file not shown.
|
|
@ -40,16 +40,16 @@
|
||||||
|
|
||||||
(defn init-db [path]
|
(defn init-db [path]
|
||||||
(sqlite/execute! path
|
(sqlite/execute! path
|
||||||
["create table if not exists images (title TEXT, created TEXT);"])
|
["drop table images;"])
|
||||||
(sqlite/execute! path
|
(sqlite/execute! path
|
||||||
["delete from images;"]))
|
["create table if not exists images (path TEXT, created TEXT);"]))
|
||||||
|
|
||||||
(defn save-to-db [db-path record]
|
(defn save-to-db [db-path record]
|
||||||
(let [fmt DateTimeFormatter/ISO_LOCAL_DATE_TIME
|
(let [fmt DateTimeFormatter/ISO_LOCAL_DATE_TIME
|
||||||
formatted-date (-> record :date (.format fmt))
|
formatted-date (-> record :date (.format fmt))
|
||||||
file-name (record :file-name)]
|
file-name (record :file-name)]
|
||||||
(sqlite/execute! db-path
|
(sqlite/execute! db-path
|
||||||
["insert into images (title, created) values (?, ?);" file-name formatted-date])))
|
["insert into images (path, created) values (?, ?);" file-name formatted-date])))
|
||||||
|
|
||||||
(defn run []
|
(defn run []
|
||||||
(let [db-path (:db-path config)]
|
(let [db-path (:db-path config)]
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,11 @@
|
||||||
(:require
|
(:require
|
||||||
[image-service-cli.index :as index]
|
[image-service-cli.index :as index]
|
||||||
[image-service-cli.config :refer [config]]
|
[image-service-cli.config :refer [config]]
|
||||||
|
[clojure.pprint :refer [pprint]]
|
||||||
|
[pod.babashka.go-sqlite3 :as sql]
|
||||||
[cheshire.core :as json]
|
[cheshire.core :as json]
|
||||||
|
|
||||||
[com.travisshears.gum-utils :as utils]))
|
[com.travisshears.gum-utils :as utils]))
|
||||||
|
|
||||||
;; user=> (pprint (sql/query (image-service-cli.config/config :db-path) "select * from images i order by i.created desc limit 10;"))
|
|
||||||
|
|
||||||
(defn base64-encode [data]
|
(defn base64-encode [data]
|
||||||
(let [bytes (.getBytes data)
|
(let [bytes (.getBytes data)
|
||||||
encoder (Base64/getEncoder)]
|
encoder (Base64/getEncoder)]
|
||||||
|
|
@ -24,9 +23,15 @@
|
||||||
encoded-config (base64-encode (json/encode img-config))]
|
encoded-config (base64-encode (json/encode img-config))]
|
||||||
(str (:final-host config) encoded-config)))
|
(str (:final-host config) encoded-config)))
|
||||||
|
|
||||||
|
(defn gen-url-action []
|
||||||
|
(let [items (->> (sql/query (image-service-cli.config/config :db-path) "select * from images i order by i.created desc limit 100;")
|
||||||
|
(map #(hash-map :item % :value (:path %))))
|
||||||
|
max-dimension (utils/prompt-for "Max dimension: ")]
|
||||||
|
(printf "url: %s\n" (get-image-url (:path (utils/select items)) max-dimension))))
|
||||||
|
|
||||||
(defn -main [& args]
|
(defn -main [& args]
|
||||||
(case (first args)
|
(case (first args)
|
||||||
;; "upload" (create/run)
|
;; "upload" (create/run)
|
||||||
;; "ls" (delete/run)
|
"gen" (gen-url-action)
|
||||||
"index" (index/run)
|
"index" (index/run)
|
||||||
(println "Missing command. Try upload, ls, or index.")))
|
(println "Missing command. Try upload, ls, or index.")))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue