# HG changeset patch # User bsw # Date 1612003173 -3600 # Node ID ad6048ec34328acf603b765efbda5f8f800de7fc # Parent 8b3375b7f5903534286b7e18360275f5cddc49bf Fixed document download diff -r 8b3375b7f590 -r ad6048ec3432 app/main/index/document_file.lua --- a/app/main/index/document_file.lua Wed Jan 27 10:07:05 2021 +0100 +++ b/app/main/index/document_file.lua Sat Jan 30 11:39:33 2021 +0100 @@ -4,15 +4,20 @@ local filename = param.get("filename") -local file = assert(io.open(encode.file_path(config.document_dir, filename)), "file not found") +local file = io.open(encode.file_path(config.document_dir, filename)) + +if not file then + return execute.view { module = "index", view = "404" } +end if param.get("inline") then - print('Content-disposition: inline; filename=' .. filename) + request.add_header("Content-disposition", "inline; filename=" .. filename) else - print('Content-disposition: attachment; filename=' .. filename) + request.add_header("Content-disposition", "attachment; filename=" .. filename) end -print('') + +local data = file:read("*a") -io.stdout:write(file:read("*a")) +slot.set_layout(nil, content_type) +slot.put_into("data", data) -exit()