From 1877d81ac793785b3bf890cb2a4b6672f2f8e5a0 Mon Sep 17 00:00:00 2001 From: Aaron Fischer Date: Thu, 11 May 2017 20:56:21 +0200 Subject: [PATCH] Make yenu work out of the box --- env/dev/resources/config.edn | 5 ++++- env/prod/resources/config.edn | 5 ++++- src/clj/yenu/config.clj | 9 +++++---- src/clj/yenu/core.clj | 4 +++- src/clj/yenu/helpers/images.clj | 11 +++++++---- src/clj/yenu/routes/admin.clj | 1 + yenu.properties | 10 ++++++++++ 7 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 yenu.properties diff --git a/env/dev/resources/config.edn b/env/dev/resources/config.edn index 75955df..b28c332 100644 --- a/env/dev/resources/config.edn +++ b/env/dev/resources/config.edn @@ -3,4 +3,7 @@ :creator-password "creator" :user-password "user" ;; when :nrepl-port is set the application starts the nREPL server on load - :nrepl-port 7000} + :nrepl-port 7000 + + :database-url "jdbc:sqlite:yenu_dev.db" + } diff --git a/env/prod/resources/config.edn b/env/prod/resources/config.edn index ec36ac6..8d8c40b 100644 --- a/env/prod/resources/config.edn +++ b/env/prod/resources/config.edn @@ -1,4 +1,7 @@ {:production true :creator-password "xxx" :user-password "yyy" - :port 3000} + :port 3000 + + :database-url "jdbc:sqlite:yenu.db" + } diff --git a/src/clj/yenu/config.clj b/src/clj/yenu/config.clj index a44fe8a..7be81b6 100644 --- a/src/clj/yenu/config.clj +++ b/src/clj/yenu/config.clj @@ -4,7 +4,8 @@ [mount.core :refer [args defstate]])) (defstate env :start (load-config - :merge - [(args) - (source/from-system-props) - (source/from-env)])) + :merge + [(args) + (source/from-system-props) + (source/from-props-file "yenu.properties") + (source/from-env)])) diff --git a/src/clj/yenu/core.clj b/src/clj/yenu/core.clj index 656c739..513dda4 100644 --- a/src/clj/yenu/core.clj +++ b/src/clj/yenu/core.clj @@ -6,6 +6,7 @@ [yenu.config :refer [env]] [clojure.tools.cli :refer [parse-opts]] [clojure.tools.logging :as log] + [yenu.helpers.images :as image] [mount.core :as mount]) (:gen-class)) @@ -51,8 +52,9 @@ (some #{"migrate" "rollback"} args) (do (mount/start #'yenu.config/env) + (image/create-needed-folders) (migrations/migrate args (select-keys env [:database-url])) (System/exit 0)) :else (start-app args))) - + diff --git a/src/clj/yenu/helpers/images.clj b/src/clj/yenu/helpers/images.clj index 1bd94bc..c2daa20 100644 --- a/src/clj/yenu/helpers/images.clj +++ b/src/clj/yenu/helpers/images.clj @@ -21,11 +21,11 @@ (.getPath (io/file (env :user-dir) "data" postfix))))) (defn create-needed-folders [] - (if (not (fs/exists? (data-path "to-process"))) + (if-not (fs/exists? (data-path "to-process")) (fs/mkdirs (data-path "to-process"))) - (if (not (fs/exists? (data-path "gallery"))) - (map #(fs/mkdirs (data-path "gallery" %)) - ["normal" "raw" "thumbnails"]))) + (if-not (fs/exists? (data-path "gallery")) + (run! #(fs/mkdirs (data-path "gallery" %)) + ["normal" "raw" "thumbnails"]))) (defn target-image-filename [image-file-path] (let [file (io/file image-file-path)] @@ -77,6 +77,9 @@ (fs/delete file) false)))) +(defn remove-temp-image [filepath] + (fs/delete filepath)) + (defn scale-image-and-save [filepath] (let [image-hash (target-image-filename filepath) file-extension (fs/extension filepath) diff --git a/src/clj/yenu/routes/admin.clj b/src/clj/yenu/routes/admin.clj index 21c7fed..0c1bfe5 100644 --- a/src/clj/yenu/routes/admin.clj +++ b/src/clj/yenu/routes/admin.clj @@ -69,6 +69,7 @@ (POST "/upload" [file title description tags] (let [filename (upload-file file) imghash (images/scale-image-and-save filename)] + (images/remove-temp-image filename) (if imghash (do (add-image-to-database imghash title description tags) diff --git a/yenu.properties b/yenu.properties new file mode 100644 index 0000000..eb6a018 --- /dev/null +++ b/yenu.properties @@ -0,0 +1,10 @@ +domain=localhost +port=3000 + +# Passwords +user-password=user +creator-password=creator + +# Content stuff +images_per_page=25 +footer=© 2013 - 2017 Aaron & Beatrice Fischer \ No newline at end of file