diff --git a/src/web.lisp b/src/web.lisp index 59ae56d..76ba963 100644 --- a/src/web.lisp +++ b/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