Browse Source

begin defroutes for viewing files in /storage/media.

I need to work on this functionality a bit more. This is an end of
session commit. Started it and it works but needs expanding.

I could do with adding file-type checks and changing 'octet/stream' to
something like 'image/png' depending on the file-type (storage in
DB). This will stop the browser from downloading every file in
/storage/media and allow the files which can be viewed in the
browser (like images).
stable
Craig Oates 2 years ago
parent
commit
7a6f330497
  1. 10
      src/web.lisp
  2. 5
      templates/user/storage.html

10
src/web.lisp

@ -738,6 +738,15 @@
(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)))
(defroute ("/storage/manage" :method :GET) ()
(hermetic:auth (:logged-in)
;; Authorised
@ -843,7 +852,6 @@
(utils:set-alert "You are not authorised to view this page.")
(redirect "/login"))))))
;; TODO: FINISH WORKING ON /STORAGE/DELETE DEFROUTE -- NEED TO TEST IT.
(defroute ("/storage/delete/:slug" :method :POST) (&key slug)
(destructuring-bind
(&key authenticity-token &allow-other-keys)

5
templates/user/storage.html

@ -26,7 +26,9 @@
{% for item in files %}
<div>
<p>
<!-- Change to image (include at least) when feature ready. -->
<!-- Change to image (include at least) when feature ready. -->
<a href="/storage/view/{{item.slug}}">
<img src="/storage/media/{{item.slug}}"></a>
<a href="/storage/media/{{item.slug}}">{{item.name}}</a>
{% if roles.administrator %}
<form action="/storage/rename/{{item.slug}}" method="POST">
@ -42,5 +44,4 @@
</p>
</div>
{% endfor %}
{% endblock %}

Loading…
Cancel
Save