diff --git a/src/web.lisp b/src/web.lisp index 0e270f5..cdbe155 100644 --- a/src/web.lisp +++ b/src/web.lisp @@ -1161,47 +1161,43 @@ (:administrator) ;; Authorised (cond ((utils:string-is-nil-or-empty? archive-slug) - (utils:set-alert "No archive slug provided. Thumbnail not updated." - "missing-data") + (utils:set-alert + "No archive slug provided. Thumbnail not updated." + "missing-data") (redirect "/user/archive")) - ((null (nera:get-archive-entry :slug archive-slug)) - (utils:set-alert "Cannot file thumbnail's archive entry. Nothing updated." - "missing-data") + (utils:set-alert + "Cannot file thumbnail's archive entry. Nothing updated." + "missing-data") (redirect "/user/archive")) - ((not (str:contains? "image" (caddr thumbnail-file) :ignore-case t)) - (utils:set-alert "File uploaded is not an image. Thumbnail not updated." - "invalid-data") + (utils:set-alert + "File uploaded is not an image. Thumbnail not updated." + "invalid-data") (redirect (format nil "/edit/archive/~a" archive-slug))) - - (t (storage:remove-file "" "archive" - (archive::thumbnail-slug-of - (nera:get-archive-entry :slug archive-slug))) - (storage:store-file "" "archive" - (cadr thumbnail-file) - thumbnail-file) - (nera:update-archive-entry-property - :slug archive-slug - :property 'archive::thumbnail-file-type-of - :value (caddr thumbnail-file)) - (nera:update-archive-entry-property - :slug archive-slug - :property 'archive::thumbnail-slug-of - :value (cadr thumbnail-file)) - (utils:create-thumbnail - "archive" - (archive::thumbnail-slug-of - (nera:get-archive-entry :slug archive-slug)) - t) - - ;; Integrate updating Meilisearch here. - + (t (let ((archive-entry (nera:get-archive-entry :slug archive-slug))) + (storage:remove-file + "" "archive" (archive::thumbnail-slug-of archive-entry)) + (storage:store-file + "" "archive" (cadr thumbnail-file) thumbnail-file) + (nera:update-archive-entry-property + :slug archive-slug + :property 'archive::thumbnail-file-type-of + :value (caddr thumbnail-file)) + (nera:update-archive-entry-property + :slug archive-slug + :property 'archive::thumbnail-slug-of + :value (cadr thumbnail-file)) + (utils:create-thumbnail + "archive" (archive::thumbnail-slug-of archive-entry) t) + ;; Meilisearch DB doesn't need updating because nothing + ;; has changed from its perspective. (utils:set-alert "Thumbnail updated." "success") - (redirect (format nil "/edit/archive/~a" archive-slug)))) + (redirect (format nil "/edit/archive/~a" archive-slug))))) ;; Not Authorised - (progn (utils:set-alert "You are not authorised to delete this archive entry." - "error") + (progn (utils:set-alert + "You are not authorised to delete this archive entry." + "error") (redirect "/login"))))))) (defroute ("/rename/archive-entry" :method :POST) () @@ -1214,39 +1210,50 @@ (:administrator) ;; Authorised (cond ((find t (mapcar #'utils:string-is-nil-or-empty? - `(,id ,archive-slug ,new-title))) - (utils:set-alert "Title and meta-data not provided. Archive entry not renamed." - "missing-data") + `(,id ,archive-slug ,new-title))) + (utils:set-alert + "Title and meta-data not provided. Archive entry not renamed." + "missing-data") (redirect "/user/archive")) - ((null (nera:get-archive-entry :slug archive-slug)) - (utils:set-alert "Cannot file archive entry. Archive entry not updated." - "invalid-data") + (utils:set-alert + "Cannot file archive entry. Archive entry not updated." + "invalid-data") (redirect "/user/archive")) - - (t (storage:rename-content-file - "" "archive" - (archive::slug-of (nera:get-archive-entry :id (parse-integer id))) - (utils:format-filename (format nil "~a.html" new-title))) - (nera:update-archive-entry-property - :slug archive-slug - :property 'archive::title-of - :value new-title) - (nera:update-archive-entry-property - :slug archive-slug - :property 'archive::slug-of - :value (utils:format-filename (format nil "~a.html" new-title))) - - ;; Integrate updating Meilisearch here. - - (utils:set-alert "Archive entry updated." "success") - (redirect - (format nil - "/edit/archive/~a" - (utils:format-filename (format nil "~a.html" new-title)))))) + (t (let ((archive-entry + (nera:get-archive-entry :id (parse-integer id)))) + (storage:rename-content-file + "" "archive" (archive::slug-of archive-entry) + (utils:format-filename (format nil "~a.html" new-title))) + (nera:update-archive-entry-property + :slug archive-slug + :property 'archive::title-of + :value new-title) + (nera:update-archive-entry-property + :slug archive-slug + :property 'archive::slug-of + :value (utils:format-filename (format nil "~a.html" new-title))) + (search:submit-entry + (search:build-payload + (archive::search-id-of archive-entry) + new-title + (format nil "view/archive/~a.html" + (utils:slugify new-title)) + (format nil + "storage/thumb/archive/~a.html" + (utils:slugify new-title)) + (mito.dao.mixin:object-created-at archive-entry) + (archive::keywords-of archive-entry))) + (utils:set-alert "Archive entry updated." "success") + (redirect + (format nil + "/edit/archive/~a" + (utils:format-filename + (format nil "~a.html" new-title))))))) ;; Not Authorised - (progn (utils:set-alert "You are not authorised to delete this archive entry." - "error") + (progn (utils:set-alert + "You are not authorised to delete this archive entry." + "error") (redirect "/login"))))))) (defroute ("/edit/archive-keywords" :method :POST) () @@ -1312,27 +1319,28 @@ (:administrator) ;; Authorised (cond ((utils:string-is-nil-or-empty? slug) - (utils:set-alert "Cannot find archive entry in database. Nothing deleted." - "missing-data") + (utils:set-alert + "Cannot find archive entry in database. Nothing deleted." + "missing-data") (redirect "/user/archive")) - ((and (null (storage:file-exists-p "" "archive" slug)) (null (nera:get-archive-entry :slug slug))) - (utils:set-alert "Unable to find archive entry. Nothing deleted." - "invalid-data") + (utils:set-alert + "Unable to find archive entry. Nothing deleted." + "invalid-data") (redirect "/user/archive")) - ((and (null (storage:file-exists-p "" "archive" slug)) (not (null (nera:get-archive-entry :slug slug)))) (nera:delete-archive-entry :slug slug) - (utils:set-alert "Couldn't find archive entry files. Deleted from database only." - "invalid-data") + (utils:set-alert + "Couldn't find archive entry files. Deleted from database only." + "invalid-data") (redirect "/user/archive")) - ((and (not (null (storage:file-exists-p "" "archive" slug))) (null (nera:get-archive-entry :slug slug))) - (utils:set-alert "Couldn't find archive entry in database. Deleted files only." - "invalid-data") + (utils:set-alert + "Couldn't find archive entry in database. Deleted files only." + "invalid-data") ;; The thumbnail in not know about here because it was ;; linked to the text file via the database. You will need ;; to delete the thumbnail manually at this point but the @@ -1340,22 +1348,19 @@ ;; was already needed. (storage:remove-file "" "archive" slug) (redirect "/user/archive")) - - (t (storage:remove-file "" "archive" slug) ; Archive Entry - ;; Archive Entry Thumbnail + (t (storage:remove-file "" "archive" slug) (storage:remove-file "" "archive" (archive::thumbnail-slug-of (nera:get-archive-entry :slug slug))) - ;; Meilisearch DB Entry (search:delete-entry (archive::search-id-of (nera:get-archive-entry :slug slug))) - ;; DB Entry (nera:delete-archive-entry :slug slug) (utils:set-alert "Archive entry deleted." "success") (redirect "/user/archive"))) ;; Not Authorised - (progn (utils:set-alert "You are not authorised to delete this archive entry." - "error") + (progn (utils:set-alert + "You are not authorised to delete this archive entry." + "error") (redirect "/login"))))))) (defroute ("/search" :method :GET) ()