When I point the browser to a directory, I want to see a list of the files in that directory - how can I do this with hunchentoot?
vedm wrote:
When I point the browser to a directory, I want to see a list of the files in that directory - how can I do this with hunchentoot?
Unless someone has already got some code lying around for this and is willing to share, you'll have to write your own handler function that maps the URL to a directory, lists all files and directories of that directory, and writes them out in some HTML format. You'll probably want that handler to be the last one in the list, in case there is any URL ambiguity.
~phil
On 11/26/06, vedm mlist@rogers.com wrote:
When I point the browser to a directory, I want to see a list of the files in that directory - how can I do this with hunchentoot?
-- vedm
(defun get-uploaded-files () (let* ((pathnames nil)) (cl-fad:walk-directory (get-config-path :upload-path) (lambda (pathname) (push pathname pathnames))) pathnames))
To get a list of all the files.
(create-dynamic-directory-dispatcher (get-config-path :upload-path) "/files/") in the *dispatch-table* to make them downloadable.
Dispatcher defined as:
(defun join-directories (root relative-path) (let ((root-directory (pathname-directory root)) (relative-directory (pathname-directory relative-path))) (append root-directory (remove-if 'symbolp relative-directory))))
(defun create-dynamic-directory-dispatcher (directory prefix) (lambda (request) (let ((script-name (tbnl:script-name request)) (mismatch (mismatch (tbnl:script-name request) prefix :test #'char=))) (and mismatch (>= mismatch (length prefix)) (let ((path (make-pathname :directory (join-directories directory (subseq script-name mismatch)) :name (pathname-name script-name) :type (pathname-type script-name)))) (unless (or (cl-fad:directory-pathname-p path) (not (probe-file path))) (lambda () (tbnl:handle-static-file path))))))))
depends on cl-fad. The code is not exceptionally beautiful, yet it should give you enough ideas to do something more reasonable.
Ignas Mikalajūnas
On Sun, 26 Nov 2006 12:50:39 -0500, vedm mlist@rogers.com wrote:
When I point the browser to a directory, I want to see a list of the files in that directory - how can I do this with hunchentoot?
You'll have to write a handler to do that for you.
Cheers, Edi.