fix rings & noirs resource upload & serve location

This commit is contained in:
jem 2019-01-08 17:42:24 +01:00
parent 4026e23946
commit 1136e792d4
3 changed files with 23 additions and 9 deletions

View file

@ -6,7 +6,12 @@
[selmer.middleware :refer [wrap-error-page]]
[prone.middleware :refer [wrap-exceptions]]
[ring.middleware.anti-forgery :refer [wrap-anti-forgery]]
[noir-exception.core :refer [wrap-internal-error]]))
[ring.middleware.file :refer [wrap-file]]
[ring.middleware.resource :refer [wrap-resource]]
[ring.middleware.content-type :refer [wrap-content-type]]
[ring.middleware.not-modified :refer [wrap-not-modified]]
[noir-exception.core :refer [wrap-internal-error]]
[smeagol.util :as util]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;
@ -44,7 +49,12 @@
(def production-middleware
[#(wrap-internal-error % :log (fn [e] (timbre/error e)))])
[#(wrap-internal-error % :log (fn [e] (timbre/error e)))
#(wrap-file % util/content-dir
{:index-files? false :prefer-handler? true})
#(wrap-resource % "public")
#(wrap-content-type %)
#(wrap-not-modified %)])
(defn load-middleware []

View file

@ -52,6 +52,7 @@
"Process `source-text` and save it to the specified `file-path`, committing it
to Git and finally redirecting to wiki-page."
[params suffix request]
(timbre/trace (format "process-source: '%s'" request))
(let [source-text (:src params)
page (:page params)
file-name (str page suffix)
@ -122,6 +123,7 @@
(defn wiki-page
"Render the markdown page specified in this `request`, if any. If none found, redirect to edit-page"
[request]
(timbre/trace (format "wiki-page: '%s'" request))
(or
(show-sanity-check-error)
(let [params (keywordize-keys (:params request))
@ -163,7 +165,7 @@
"Render a form to allow the upload of a file."
[request]
(let [params (keywordize-keys (:params request))
data-path (str (io/resource-path) "/content/uploads/")
data-path (str util/content-dir "/content/uploads/")
git-repo (hist/load-or-init-repo util/content-dir)
upload (:upload params)
uploaded (if upload (ul/store-upload params data-path))

View file

@ -56,6 +56,8 @@
filename (:filename upload)]
(timbre/info
(str "Storing upload file: " upload))
(timbre/debug
(str "store-upload mv file: " tmp-file " to: " path filename))
(if tmp-file
(do
(.renameTo tmp-file