Browse Source

rafactor /storage/view route and add a route/process for thumbnails.

When uploading a file, a thumbnail is made (if an image, using the
Image Magick program with Bash). This file is not stored in the
database. It is a file-system only thing. The reason for adding this
is some I can create HTML templates/defroutes which show a list of the
images in /storage/media without saturating the viewers bandwidth.
stable
Craig Oates 2 years ago
parent
commit
13d1e31c13
  1. 29
      src/web.lisp

29
src/web.lisp

@ -15,7 +15,8 @@
#:utils
#:validation
#:user
#:nera-db)
#:nera-db
#:files)
(:export #:*web*))
(in-package #:ritherdon-archive.web)
@ -738,14 +739,22 @@
(progn (utils:set-alert "You are not authorised to delete page.")
(redirect "/login")))))))
;; TODO: Add condition branches for file-type.
;; This is working but I could do with adding content-types for images
;; and text so the browser doesn't always down the asset/media/file.
(defroute ("/storage/view/:slug" :method :GET) (&key slug)
(if (storage:file-exists-p "" "media" slug)
`(200 (:content-type "octet/stream")
,(storage:open-binary-file "" "media" slug))
(on-exception *web* 404)))
`(200 (:content-type
,(files::file-type-of
(nera:get-storage-file :slug slug)))
,(storage:open-binary-file "" "media" slug))
(on-exception *web* 404)))
(defroute ("/storage/thumb/:slug" :method :GET) (&key slug)
(if (storage:file-exists-p "" "media" slug)
`(200 (:content-type
,(files::file-type-of
(nera:get-storage-file :slug slug)))
,(storage:open-binary-file "" "media"
(format nil "thumbnail-~a" slug)))
(on-exception *web* 404)))
(defroute ("/storage/manage" :method :GET) ()
(hermetic:auth (:logged-in)
@ -782,6 +791,12 @@
(nera:add-storage-file file-name
(utils:slugify file-name)
(caddr storage-file))
(utils:run-bash-command
(format nil "convert ~a -resize 512x512\\> ~a"
(storage:file-exists-p "" "media" (utils:slugify file-name))
(storage:make-path "" "media"
(format nil "thumbnail-~a"
(utils:slugify file-name)))))
(utils:set-alert "File uploaded.")
(redirect "/storage/manage")))
;; Not Authorised

Loading…
Cancel
Save