Skip to content

Commit

Permalink
#47, #49: Auto-thumbnailing now working and configurable
Browse files Browse the repository at this point in the history
Not yet documented.
  • Loading branch information
simon-brooke committed Feb 10, 2020
1 parent 40f4f13 commit ba45ea5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
10 changes: 6 additions & 4 deletions resources/templates/upload.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{% extends "templates/base.html" %}
{% block content %}
<div id="content" class="auth">
{% if has-uploaded %}
{% if uploaded|not-empty %}
{% for upload in uploaded %}
{{upload.filename}}
{% if upload.is-image %)
{% if upload.is-image %}
<p>
<img id="uploaded-image" alt="Uploaded image" src="{{upload.resource}}"/>

{% i18n file-upload-link-text %}:
<!-- TODO: i18n needed -->
This is the {{upload.size|name}} file. {% i18n file-upload-link-text %}:

<code>![{{upload.filename}}]({{upload.resource}})</code>
</p>
Expand All @@ -19,6 +19,8 @@
<code>[{{upload.filename}}]({{upload.resource}})</code>
</p>
{% endif %}
<br clear="right"/>
<hr/>
{% endfor %}
{% else %}
<form action="{{servlet-context}}/upload" enctype="multipart/form-data" method="POST">
Expand Down
1 change: 0 additions & 1 deletion src/smeagol/routes/wiki.clj
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@
(layout/render "upload.html"
(merge (util/standard-params request)
{:title (util/get-message :file-upload-title request)
:has-uploaded (not (empty? uploaded))
:uploaded uploaded}))))

(defn version-page
Expand Down
33 changes: 18 additions & 15 deletions src/smeagol/uploads.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[me.raynes.fs :as fs]
[noir.io :as nio]
[smeagol.configuration :refer [config]]
[smeagol.util :as util]
[taoensso.timbre :as log])
(:import [java.io File]
[java.awt Image]
Expand Down Expand Up @@ -80,13 +81,13 @@
for the file with this `filename` on this `path`, provided that it is a
scalable image and is larger than the size."
([^String path ^String filename]
(if
(image? filename)
(let [original (buffered-image (File. (str path filename)))] ;; fs/file?
(map
#(auto-thumbnail path filename % original)
(keys (config :thumbnails))))
(log/info filename " cannot be thumbnailed.")))
(if
(image? filename)
(let [original (buffered-image (File. (str path filename)))] ;; fs/file?
(map
#(auto-thumbnail path filename % original)
(keys (config :thumbnails))))
(log/info filename " cannot be thumbnailed.")))
([^String path ^String filename size ^RenderedImage image]
(let [s (-> config :thumbnails size)
d (dimensions image)
Expand Down Expand Up @@ -117,14 +118,16 @@
(try
(let [p (io/file path filename)]
(.renameTo tmp-file p)
(remove
nil?
(cons
{:size :original
:filename filename
:location (str p)
:is-image (and (image? filename) true)}
(remove nil? (or (auto-thumbnail path filename) '())))))
(map
#(assoc % :resource (subs (:location %) (inc (count util/content-dir))))
(remove
nil?
(cons
{:size :original
:filename filename
:location (str p)
:is-image (and (image? filename) true)}
(remove nil? (or (auto-thumbnail path filename) '()))))))
(catch Exception x
(log/error (str "Failed to move " tmp-file " to " path filename "; " (type x) ": " (.getMessage x)))
(throw x)))
Expand Down

0 comments on commit ba45ea5

Please sign in to comment.