# HG changeset patch # User Kim Alvefur # Date 1611767595 -3600 # Node ID 76fc73d390921574fd5641eb3089e0cebb2ee3aa # Parent 494761f5d7da8c7e2a139c279f292c57b3cef47f mod_http_file_share: Factor out function for generating full filename diff -r 494761f5d7da -r 76fc73d39092 plugins/mod_http_file_share.lua --- a/plugins/mod_http_file_share.lua Wed Jan 27 17:48:12 2021 +0100 +++ b/plugins/mod_http_file_share.lua Wed Jan 27 18:13:15 2021 +0100 @@ -57,6 +57,10 @@ -- Convenience wrapper for logging file sizes local function B(bytes) return hi.format(bytes, "B", "b"); end +local function get_filename(slot, create) + return dm.getpath(slot, module.host, module.name, "bin", create) +end + function may_upload(uploader, filename, filesize, filetype) -- > boolean, error local uploader_host = jid.host(uploader); if not ((access:empty() and prosody.hosts[uploader_host]) or access:contains(uploader) or access:contains(uploader_host)) then @@ -171,7 +175,7 @@ -- so we also check the final file size on completion. end - local filename = dm.getpath(upload_info.slot, module.host, module.name, "bin", true); + local filename = get_filename(upload_info.slot, true); if not request.body_sink then @@ -229,7 +233,7 @@ if request.headers.if_modified_since == last_modified then return 304; end - local filename = dm.getpath(slot_id, module.host, module.name, "bin"); + local filename = get_filename(slot_id); local handle, ferr = errors.coerce(io.open(filename)); if not handle then return ferr or 410;