diff --git a/resources/i18n/en-GB.edn b/resources/i18n/en-GB.edn index aeb391c..a7b8789 100644 --- a/resources/i18n/en-GB.edn +++ b/resources/i18n/en-GB.edn @@ -75,6 +75,8 @@ :email-prompt "Email address" ;; text of the email widget prompt on edit user page :file-or-directory "File or directory" ;; 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" ;; Text introducing the link to an uploaded file :file-upload-prompt "File to upload" ;; prompt string for the file upload widget diff --git a/resources/public/content/stylesheet.css b/resources/public/content/stylesheet.css index 81c51aa..187b346 100644 --- a/resources/public/content/stylesheet.css +++ b/resources/public/content/stylesheet.css @@ -209,6 +209,10 @@ th { display: block; } +#uploaded-image { + float: right; +} + .change { background-color: rgb( 223, 223, 223); border: thin solid silver; diff --git a/resources/public/content/uploads/smeagol.png b/resources/public/content/uploads/smeagol.png new file mode 100644 index 0000000..09787cb Binary files /dev/null and b/resources/public/content/uploads/smeagol.png differ diff --git a/resources/templates/upload.html b/resources/templates/upload.html index fd370d0..a91865e 100644 --- a/resources/templates/upload.html +++ b/resources/templates/upload.html @@ -3,12 +3,12 @@
{% if uploaded %} {% if is-image %} - Uploaded image -

+ Uploaded image + {% i18n file-upload-link-text %}: - ![Uploaded image](uploads/{{uploaded}}) + ![Uploaded image](content/uploads/{{uploaded}})

{% else %}

@@ -24,6 +24,10 @@

+

+ + +

diff --git a/src/smeagol/routes/wiki.clj b/src/smeagol/routes/wiki.clj index 8a538b9..15b3a68 100644 --- a/src/smeagol/routes/wiki.clj +++ b/src/smeagol/routes/wiki.clj @@ -156,9 +156,17 @@ "Render a form to allow the upload of a file." [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) - 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" (merge (util/standard-params request) {:title (util/get-message :file-upload-title request) diff --git a/src/smeagol/uploads.clj b/src/smeagol/uploads.clj index dbc31af..27ddceb 100644 --- a/src/smeagol/uploads.clj +++ b/src/smeagol/uploads.clj @@ -29,19 +29,20 @@ ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defn avoid-name-collisions - "Find a filename within this `path`, based on this `file-name`, that does not - reference an existing file. It is assumed that `path` ends with a path separator. - Returns a filename hwich does not currently reference a file within the path." - [path file-name] - (if (.exists (File. (str path file-name))) - (let [parts (cs/split file-name #"\.") - prefix (cs/join "." (butlast parts)) - suffix (last parts)] - (first - (filter #(not (.exists (File. (str path %)))) - (map #(str prefix "." % "." suffix) (range))))) - file-name)) +;; No longer used as uploaded files now go into Git. +;; (defn avoid-name-collisions +;; "Find a filename within this `path`, based on this `file-name`, that does not +;; reference an existing file. It is assumed that `path` ends with a path separator. +;; Returns a filename hwich does not currently reference a file within the path." +;; [path file-name] +;; (if (.exists (File. (str path file-name))) +;; (let [parts (cs/split file-name #"\.") +;; prefix (cs/join "." (butlast parts)) +;; suffix (last parts)] +;; (first +;; (filter #(not (.exists (File. (str path %)))) +;; (map #(str prefix "." % "." suffix) (range))))) +;; file-name)) (defn store-upload @@ -49,11 +50,10 @@ 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 an HTTP POST operation of a form with type `multipart/form-data`." - [params] + [params path] (let [upload (:upload params) tmp-file (:tempfile upload) - path (str (io/resource-path) "uploads/") - filename (avoid-name-collisions path (:filename upload))] + filename (:filename upload)] (timbre/info (str "Storing upload file: " upload)) (if tmp-file