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]] [selmer.middleware :refer [wrap-error-page]]
[prone.middleware :refer [wrap-exceptions]] [prone.middleware :refer [wrap-exceptions]]
[ring.middleware.anti-forgery :refer [wrap-anti-forgery]] [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 (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 [] (defn load-middleware []

View file

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

View file

@ -56,9 +56,11 @@
filename (:filename upload)] filename (:filename upload)]
(timbre/info (timbre/info
(str "Storing upload file: " upload)) (str "Storing upload file: " upload))
(if tmp-file (timbre/debug
(do (str "store-upload mv file: " tmp-file " to: " path filename))
(.renameTo tmp-file (if tmp-file
(File. (str path filename))) (do
filename) (.renameTo tmp-file
(throw (Exception. "No file found?"))))) (File. (str path filename)))
filename)
(throw (Exception. "No file found?")))))