Make yenu work out of the box

This commit is contained in:
Aaron Fischer 2017-05-11 20:56:21 +02:00
parent 44546efb0d
commit 1877d81ac7
7 changed files with 34 additions and 11 deletions

View file

@ -3,4 +3,7 @@
:creator-password "creator" :creator-password "creator"
:user-password "user" :user-password "user"
;; when :nrepl-port is set the application starts the nREPL server on load ;; 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"
}

View file

@ -1,4 +1,7 @@
{:production true {:production true
:creator-password "xxx" :creator-password "xxx"
:user-password "yyy" :user-password "yyy"
:port 3000} :port 3000
:database-url "jdbc:sqlite:yenu.db"
}

View file

@ -4,7 +4,8 @@
[mount.core :refer [args defstate]])) [mount.core :refer [args defstate]]))
(defstate env :start (load-config (defstate env :start (load-config
:merge :merge
[(args) [(args)
(source/from-system-props) (source/from-system-props)
(source/from-env)])) (source/from-props-file "yenu.properties")
(source/from-env)]))

View file

@ -6,6 +6,7 @@
[yenu.config :refer [env]] [yenu.config :refer [env]]
[clojure.tools.cli :refer [parse-opts]] [clojure.tools.cli :refer [parse-opts]]
[clojure.tools.logging :as log] [clojure.tools.logging :as log]
[yenu.helpers.images :as image]
[mount.core :as mount]) [mount.core :as mount])
(:gen-class)) (:gen-class))
@ -51,6 +52,7 @@
(some #{"migrate" "rollback"} args) (some #{"migrate" "rollback"} args)
(do (do
(mount/start #'yenu.config/env) (mount/start #'yenu.config/env)
(image/create-needed-folders)
(migrations/migrate args (select-keys env [:database-url])) (migrations/migrate args (select-keys env [:database-url]))
(System/exit 0)) (System/exit 0))
:else :else

View file

@ -21,11 +21,11 @@
(.getPath (io/file (env :user-dir) "data" postfix))))) (.getPath (io/file (env :user-dir) "data" postfix)))))
(defn create-needed-folders [] (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"))) (fs/mkdirs (data-path "to-process")))
(if (not (fs/exists? (data-path "gallery"))) (if-not (fs/exists? (data-path "gallery"))
(map #(fs/mkdirs (data-path "gallery" %)) (run! #(fs/mkdirs (data-path "gallery" %))
["normal" "raw" "thumbnails"]))) ["normal" "raw" "thumbnails"])))
(defn target-image-filename [image-file-path] (defn target-image-filename [image-file-path]
(let [file (io/file image-file-path)] (let [file (io/file image-file-path)]
@ -77,6 +77,9 @@
(fs/delete file) (fs/delete file)
false)))) false))))
(defn remove-temp-image [filepath]
(fs/delete filepath))
(defn scale-image-and-save [filepath] (defn scale-image-and-save [filepath]
(let [image-hash (target-image-filename filepath) (let [image-hash (target-image-filename filepath)
file-extension (fs/extension filepath) file-extension (fs/extension filepath)

View file

@ -69,6 +69,7 @@
(POST "/upload" [file title description tags] (POST "/upload" [file title description tags]
(let [filename (upload-file file) (let [filename (upload-file file)
imghash (images/scale-image-and-save filename)] imghash (images/scale-image-and-save filename)]
(images/remove-temp-image filename)
(if imghash (if imghash
(do (do
(add-image-to-database imghash title description tags) (add-image-to-database imghash title description tags)

10
yenu.properties Normal file
View file

@ -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