From 8d55ed7d611ffdb9b2c7900c4abce547c8b7980f Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sun, 25 Sep 2022 15:53:59 +0100 Subject: [PATCH] refactor /storage (I.E. get files) routes and /edit/archive/:slug. I added a new route to get files from the /archive directory but needed to expand on the original /storage/view/:slug route so I could seperate out the two (/storage/media and /storage/archive) directories. I added a check to make sure the archive entry requested (/edit/archive/:slug) exists and return a 404 if it doesn't. --- src/web.lisp | 63 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/src/web.lisp b/src/web.lisp index c730216..09a12e1 100644 --- a/src/web.lisp +++ b/src/web.lisp @@ -737,7 +737,7 @@ (progn (utils:set-alert "You are not authorised to delete page.") (redirect "/login"))))))) -(defroute ("/storage/view/:slug" :method :GET) (&key slug) +(defroute ("/storage/view/media/:slug" :method :GET) (&key slug) (if (storage:file-exists-p "" "media" slug) `(200 (:content-type ,(files::file-type-of @@ -745,7 +745,16 @@ ,(storage:open-binary-file "" "media" slug)) (on-exception *web* 404))) -(defroute ("/storage/thumb/:slug" :method :GET) (&key slug) +(defroute ("/storage/thumb/archive/:slug" :method :GET) (&key slug) + (if (nera:get-archive-entry :slug slug) + (let ((archive-entry (nera:get-archive-entry :slug slug))) + (format t "[THUMBNAIL] ~A~%" (archive::thumbnail-file-type-of archive-entry)) + `(200 (:content-type ,(archive::thumbnail-file-type-of archive-entry)) + ,(storage:open-binary-file + "" "archive" (archive::thumbnail-slug-of archive-entry)))) + (on-exception *web* 404))) + +(defroute ("/storage/thumb/page/:slug" :method :GET) (&key slug) (if (storage:file-exists-p "" "media" slug) `(200 (:content-type ,(files::file-type-of @@ -1029,30 +1038,40 @@ (redirect "/login"))))))) (defroute ("/edit/archive/:slug" :method :GET) (&key slug) - (hermetic:auth (:logged-in) - ;; Authorised - (let ((alert (utils:get-and-reset-alert))) - (render "/user/edit-archive.html" - (append (auth:auth-user-data) - `(:alert ,alert - :system-data ,(nera:system-data) - :db-data ,(nera:get-archive-entry :slug slug) - :data ,(storage:open-text-file - "" "archive" slug))))) - ;; Not Authorised - (progn - (utils:set-alert "You are not logged in.") - (redirect "/login")))) + (if (nera:get-archive-entry :slug slug) + (progn + (hermetic:auth (:logged-in) + ;; Authorised + (let ((alert (utils:get-and-reset-alert))) + (render "/user/edit-archive.html" + (append (auth:auth-user-data) + `(:alert ,alert + :system-data ,(nera:system-data) + :db-data ,(nera:get-archive-entry :slug slug) + :data ,(storage:open-text-file + "" "archive" slug))))) + ;; Not Authorised + (progn + (utils:set-alert "You are not logged in.") + (redirect "/login")))) + (on-exception *web* 404))) + +(defroute ("/edit/archive-thumbnail" :method :POST) () + (utils:set-alert "ROUTE NOT IMPLEMENTED") + (redirect "/user/archive")) -(defroute ("/rename/archive-entry" :method :POST) - (format nil "ROUTE NOT IMPLEMENTED")) +(defroute ("/rename/archive-entry" :method :POST) () + (utils:set-alert "ROUTE NOT IMPLEMENTED") + (redirect "/user/archive")) -(defroute ("/edit/archive" :method :POST) - (format nil "ROUTE NOT IMPLEMENTED")) +(defroute ("/edit/archive" :method :POST) () + (utils:set-alert "ROUTE NOT IMPLEMENTED") + (redirect "/user/archive")) -(defroute ("/edit/archive-thumbnail" :method :POST) - (format nil "ROUTE NOT IMPLEMENTED")) +(defroute ("/edit/archive-thumbnail" :method :POST) () + (utils:set-alert "ROUTE NOT IMPLEMENTED") + (redirect "/user/archive")) (defroute ("/archive/delete/entry" :method :POST) () (destructuring-bind