# HG changeset patch # User bsw # Date 1331143640 -3600 # Node ID 08ba83dd47c0e44d7e010814d4037b67af678487 # Parent 08a6b6e9de8497fbf9b8c54aaf6bac7d06f15049 Add support for files only available to logged in members diff -r 08a6b6e9de84 -r 08ba83dd47c0 app/main/index/document.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/main/index/document.lua Wed Mar 07 19:07:20 2012 +0100 @@ -0,0 +1,52 @@ +if not config.document_dir then + error("feature not enabled") +end + +slot.put_into("title", _"Download documents") + +slot.select("actions", function() + ui.link{ + content = function() + ui.image{ static = "icons/16/cancel.png" } + slot.put(_"Cancel") + end, + module = "index", + view = "index" + } +end) + +util.help("index.document", _"Download documents") + +local file_list = os.listdir(config.document_dir) + +local tmp = {} +for i, filename in ipairs(file_list) do + if not filename:find("^%.") then + tmp[#tmp+1] = filename + end +end + +local file_list = tmp + +table.sort(file_list, function(a, b) return a > b end) + +ui.list{ + records = file_list, + columns = { + { + content = function(filename) + slot.put(encode.html(filename)) + end + }, + { + content = function(filename) + ui.link{ + content = _"Download", + module = "index", + view = "document_file", + params = { filename = filename } + } + end + } + } +} \ No newline at end of file diff -r 08a6b6e9de84 -r 08ba83dd47c0 app/main/index/document_file.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/main/index/document_file.lua Wed Mar 07 19:07:20 2012 +0100 @@ -0,0 +1,15 @@ +if not config.document_dir then + error("feature not enabled") +end + +local filename = param.get("filename") + +local file = assert(io.open(encode.file_path(config.document_dir, filename)), "file not found") + +print('Content-type: application/octet-stream') +print('Content-disposition: attachment; filename=' .. filename) +print('') + +io.stdout:write(file:read("*a")) + +exit()