Browse Source

refactor code calling get-storage-file and add storage/rename route.

stable
Craig Oates 2 years ago
parent
commit
0331999136
  1. 60
      src/web.lisp

60
src/web.lisp

@ -738,6 +738,19 @@
(progn (utils:set-alert "You are not authorised to delete page.")
(redirect "/login")))))))
(defroute ("/storage/manage" :method :GET) ()
(hermetic:auth (:logged-in)
;; Authorised
(let ((alert (utils:get-and-reset-alert)))
(render #P"/user/storage.html"
(append (auth:auth-user-data)
`(:alert ,alert
:files ,(nera:get-all-storage-files)
:system-data ,(nera:system-data)))))
;; Not Authorised
(progn (utils:set-alert "You are not logged in.")
(redirect "/login"))))
(defroute ("/storage/upload" :method :POST) ()
(destructuring-bind
(&key file-name storage-file authenticity-token &allow-other-keys)
@ -749,10 +762,10 @@
(:logged-in)
;; Authorised
(cond ((utils:string-is-nil-or-empty? (cadr storage-file))
(utils:set-alert "No file provided..")
(redirect "/dashboard"))
(utils:set-alert "No file provided.")
(redirect "/storage/manage"))
((not (null (nera:get-storage-file file-name)))
((not (null (nera:get-storage-file :filename file-name)))
(utils:set-alert "File with that name already exists. File not saved.")
(redirect "/storage/manage"))
@ -799,19 +812,36 @@
(utils:set-alert "You are not authorised to view this page.")
(redirect "/login")))))))
(defroute ("/storage/rename/:slug" :method :POST) (&key slug)
(destructuring-bind
(&key new-file-name authenticity-token &allow-other-keys)
(utils:request-params
(lack.request:request-body-parameters ningle:*request*))
(if (not (string= authenticity-token (auth:csrf-token)))
`(,+forbidden+ (:content-type "text/plain") ("Denied"))
(hermetic:auth
(:logged-in)
;; Authorised
(cond ((utils:string-is-nil-or-empty? new-file-name)
(utils:set-alert "No file name provided. Nothing updated.")
(redirect "/storage/manage"))
(defroute ("/storage/manage" :method :GET) ()
(hermetic:auth (:logged-in)
;; Authorised
(let ((alert (utils:get-and-reset-alert)))
(render #P"/user/storage.html"
(append (auth:auth-user-data)
`(:alert ,alert
:files ,(nera:get-all-storage-files)
:system-data ,(nera:system-data)))))
;; Not Authorised
(progn (utils:set-alert "You are not logged in.")
(redirect "/login"))))
((not (null (nera:get-storage-file :filename new-file-name)))
(utils:set-alert "File with that name already exists. File not saved.")
(redirect "/storage/manage"))
(t (storage:rename-content-file
"" "media" (files::name-of (nera:get-storage-file :slug slug))
new-file-name)
(nera:rename-storage-file
(files::name-of (nera:get-storage-file :slug slug))
new-file-name)
(utils:set-alert "File uploaded.")
(redirect "/storage/manage")))
;; Not Authorised
(progn
(utils:set-alert "You are not authorised to view this page.")
(redirect "/login"))))))
;;
;; Error pages

Loading…
Cancel
Save