This commit is contained in:
Simon Brooke 2017-09-10 22:55:48 +01:00
parent 1353e27f92
commit 843a1d084b
6 changed files with 39 additions and 21 deletions

View file

@ -75,6 +75,8 @@
:email-prompt "Email address" ;; text of the email widget prompt on edit user page :email-prompt "Email address" ;; text of the email widget prompt on edit user page
:file-or-directory "File or directory" :file-or-directory "File or directory"
;; used in sanity check report ;; used in sanity check report
:file-summary-prompt "Description/what's changed"
;; prompt for the file upload summary input
:file-upload-link-text "You may link to this file using a link of the form" :file-upload-link-text "You may link to this file using a link of the form"
;; Text introducing the link to an uploaded file ;; Text introducing the link to an uploaded file
:file-upload-prompt "File to upload" ;; prompt string for the file upload widget :file-upload-prompt "File to upload" ;; prompt string for the file upload widget

View file

@ -209,6 +209,10 @@ th {
display: block; display: block;
} }
#uploaded-image {
float: right;
}
.change { .change {
background-color: rgb( 223, 223, 223); background-color: rgb( 223, 223, 223);
border: thin solid silver; border: thin solid silver;

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View file

@ -3,12 +3,12 @@
<div id="content" class="auth"> <div id="content" class="auth">
{% if uploaded %} {% if uploaded %}
{% if is-image %} {% if is-image %}
<img alt="Uploaded image" src="uploads/{{uploaded}}"/>
<p> <p>
<img id="uploaded-image" alt="Uploaded image" src="content/uploads/{{uploaded}}"/>
{% i18n file-upload-link-text %}: {% i18n file-upload-link-text %}:
<code>![Uploaded image](uploads/{{uploaded}})</code> <code>![Uploaded image](content/uploads/{{uploaded}})</code>
</p> </p>
{% else %} {% else %}
<p> <p>
@ -24,6 +24,10 @@
<label for="upload">{% i18n file-upload-prompt %}</label> <label for="upload">{% i18n file-upload-prompt %}</label>
<input name="upload" id="upload" type="file" required/> <input name="upload" id="upload" type="file" required/>
</p> </p>
<p class="widget">
<label for="summary">{% i18n file-summary-prompt %}</label>
<input name="summary" id="summary" type="text" required/>
</p>
<p class="widget"> <p class="widget">
<label for="submit">{% i18n save-prompt %}</label> <label for="submit">{% i18n save-prompt %}</label>
<input name="submit" id="submit" type="submit" class="action" value="{% i18n save-label %}"/> <input name="submit" id="submit" type="submit" class="action" value="{% i18n save-label %}"/>

View file

@ -156,9 +156,17 @@
"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) "/uploads/") data-path (str (io/resource-path) "/content/uploads/")
git-repo (get-git-repo)
upload (:upload params) upload (:upload params)
uploaded (if upload (ul/store-upload params))] uploaded (if upload (ul/store-upload params data-path))
user (session/get :user)
summary (format "%s: %s" user (or (:summary params) "no summary"))]
(if
uploaded
(do
(git/git-add git-repo uploaded)
(git/git-commit git-repo summary {:name user :email (auth/get-email user)})))
(layout/render "upload.html" (layout/render "upload.html"
(merge (util/standard-params request) (merge (util/standard-params request)
{:title (util/get-message :file-upload-title request) {:title (util/get-message :file-upload-title request)

View file

@ -29,19 +29,20 @@
;;;; ;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn avoid-name-collisions ;; No longer used as uploaded files now go into Git.
"Find a filename within this `path`, based on this `file-name`, that does not ;; (defn avoid-name-collisions
reference an existing file. It is assumed that `path` ends with a path separator. ;; "Find a filename within this `path`, based on this `file-name`, that does not
Returns a filename hwich does not currently reference a file within the path." ;; reference an existing file. It is assumed that `path` ends with a path separator.
[path file-name] ;; Returns a filename hwich does not currently reference a file within the path."
(if (.exists (File. (str path file-name))) ;; [path file-name]
(let [parts (cs/split file-name #"\.") ;; (if (.exists (File. (str path file-name)))
prefix (cs/join "." (butlast parts)) ;; (let [parts (cs/split file-name #"\.")
suffix (last parts)] ;; prefix (cs/join "." (butlast parts))
(first ;; suffix (last parts)]
(filter #(not (.exists (File. (str path %)))) ;; (first
(map #(str prefix "." % "." suffix) (range))))) ;; (filter #(not (.exists (File. (str path %))))
file-name)) ;; (map #(str prefix "." % "." suffix) (range)))))
;; file-name))
(defn store-upload (defn store-upload
@ -49,11 +50,10 @@
The issue with storing an upload is moving it into place. The issue with storing an upload is moving it into place.
If `params` are passed as a map, it is expected that this is a map from If `params` are passed as a map, it is expected that this is a map from
an HTTP POST operation of a form with type `multipart/form-data`." an HTTP POST operation of a form with type `multipart/form-data`."
[params] [params path]
(let [upload (:upload params) (let [upload (:upload params)
tmp-file (:tempfile upload) tmp-file (:tempfile upload)
path (str (io/resource-path) "uploads/") filename (:filename upload)]
filename (avoid-name-collisions path (:filename upload))]
(timbre/info (timbre/info
(str "Storing upload file: " upload)) (str "Storing upload file: " upload))
(if tmp-file (if tmp-file