Comparison

plugins/mod_http_file_share.lua @ 11355:89efa3f2966b

mod_http_file_share: Collect statistics of files uploaded
author Kim Alvefur <zash@zash.se>
date Tue, 02 Feb 2021 22:08:51 +0100
parent 11350:3287dbdde33e
child 11356:43e5429ab355
comparison
equal deleted inserted replaced
11354:10fba62332c5 11355:89efa3f2966b
60 }); 60 });
61 61
62 local upload_cache = cache.new(1024); 62 local upload_cache = cache.new(1024);
63 local quota_cache = cache.new(1024); 63 local quota_cache = cache.new(1024);
64 64
65 local measure_uploads = module:measure("upload", "sizes");
66
65 -- Convenience wrapper for logging file sizes 67 -- Convenience wrapper for logging file sizes
66 local function B(bytes) return hi.format(bytes, "B", "b"); end 68 local function B(bytes) return hi.format(bytes, "B", "b"); end
67 69
68 local function get_filename(slot, create) 70 local function get_filename(slot, create)
69 return dm.getpath(slot, module.host, module.name, "bin", create) 71 return dm.getpath(slot, module.host, module.name, "bin", create)
253 uploaded, err = false, 413; 255 uploaded, err = false, 413;
254 end 256 end
255 if uploaded then 257 if uploaded then
256 module:log("debug", "Upload of %q completed, %s", filename, B(final_size)); 258 module:log("debug", "Upload of %q completed, %s", filename, B(final_size));
257 assert(os.rename(filename.."~", filename)); 259 assert(os.rename(filename.."~", filename));
260 measure_uploads(final_size);
258 261
259 upload_cache:set(upload_info.slot, { 262 upload_cache:set(upload_info.slot, {
260 name = upload_info.filename; 263 name = upload_info.filename;
261 size = tostring(upload_info.filesize); 264 size = tostring(upload_info.filesize);
262 type = upload_info.filetype; 265 type = upload_info.filetype;