From 61e8ef91f80c7f02202bfaa2a1e3b75b1778d6b5 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sun, 2 Oct 2022 07:34:29 +0100 Subject: [PATCH] refactor file upload storage routes -- regarding thumbnails. The automatically generated thumbnails are no longer stored in the database. They are created, updated and deleted alongside it's main accompanying image -- as a file in the /storage/media directory. --- src/web.lisp | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/web.lisp b/src/web.lisp index 1cc9b05..a1c03e6 100644 --- a/src/web.lisp +++ b/src/web.lisp @@ -805,15 +805,14 @@ (nera:add-storage-file (caddr item) (utils:slugify (caddr item)) (cadddr item)) - + ;; Thumbnail not stored in the database. It + ;; is a hard-coded utility feature of the + ;; website. The thumbnail is created so + ;; large-scale images are not used at the + ;; thumbnail, increasing download sizes. (when (str:contains? "image" (cadddr item) :ignore-case t) (utils:create-thumbnail - "media" (utils:format-filename (caddr item)) nil) - (nera:add-storage-file - (format nil "thumbnail-~a" (caddr item)) - (utils:slugify (format nil "thumbnail-~a" (caddr item))) - (cadddr item)))) - + "media" (utils:format-filename (caddr item)) nil))) (utils:set-alert "Multi-File upload complete.") (redirect "/storage/manage"))) ;; Not Authorised @@ -840,17 +839,19 @@ (redirect "/storage/manage")) (t (storage:rename-content-file - "" "media" (files::slug-of (nera:get-storage-file :slug slug)) - (utils:slugify new-file-name)) + "" "media" (files::name-of (nera:get-storage-file :slug slug)) + (utils:format-filename new-file-name)) ;; Rename the thumbnail if there is one (not all files are images). - (when (storage:file-exists-p "" "media" (format nil "thumbnail-~a" slug)) + (when (storage:file-exists-p + "" "media" + (format nil "thumbnail-~a" ; slug)) + (files::name-of (nera:get-storage-file :slug slug)))) (storage:rename-content-file "" "media" (format nil "thumbnail-~a" - (files::slug-of + (files::name-of (nera:get-storage-file :slug slug))) - (utils:slugify (format nil "thumbnail-~a" new-file-name)))) - + (utils:format-filename (format nil "thumbnail-~a" new-file-name)))) (nera:rename-storage-file (files::name-of (nera:get-storage-file :slug slug)) new-file-name) @@ -878,9 +879,15 @@ "" "media" (files::name-of (nera:get-storage-file :slug slug))) (when (storage:file-exists-p - "" "media" (format nil "thumbnail-~a" slug)) + "" "media" + (format nil "thumbnail-~a" + (files::name-of + (nera:get-storage-file :slug slug)))) (storage:remove-file - "" "media" (format nil "thumbnail-~a" slug))) + "" "media" + (format nil "thumbnail-~a" (files::name-of + (nera:get-storage-file + :slug slug))))) (nera:delete-storage-file :slug slug) (utils:set-alert "File deleted.") (redirect "/storage/manage")))