Comparison

plugins/mod_http_file_share.lua @ 13056:c38b1c63aa5c

mod_http_file_share: use util.human.io.parse_duration Updated by Zash, the original patch by Jonas had put the duration parsing function in util.datetime but MattJ later did the same thing but differently in f4d7fe919969
author Jonas Schäfer <jonas@wielicki.name>
date Thu, 28 Apr 2022 20:40:59 +0200
parent 12977:74b9e05af71e
child 13168:536055476912
comparison
equal deleted inserted replaced
13055:e732f9dfdfc8 13056:c38b1c63aa5c
17 local urlencode = require "prosody.util.http".urlencode; 17 local urlencode = require "prosody.util.http".urlencode;
18 local dt = require "prosody.util.datetime"; 18 local dt = require "prosody.util.datetime";
19 local hi = require "prosody.util.human.units"; 19 local hi = require "prosody.util.human.units";
20 local cache = require "prosody.util.cache"; 20 local cache = require "prosody.util.cache";
21 local lfs = require "lfs"; 21 local lfs = require "lfs";
22 local parse_duration = require "prosody.util.human.io".parse_duration;
22 23
23 local unknown = math.abs(0/0); 24 local unknown = math.abs(0/0);
24 local unlimited = math.huge; 25 local unlimited = math.huge;
25 26
26 local namespace = "urn:xmpp:http:upload:0"; 27 local namespace = "urn:xmpp:http:upload:0";
37 local secret = module:get_option_string(module.name.."_secret", require"prosody.util.id".long()); 38 local secret = module:get_option_string(module.name.."_secret", require"prosody.util.id".long());
38 local external_base_url = module:get_option_string(module.name .. "_base_url"); 39 local external_base_url = module:get_option_string(module.name .. "_base_url");
39 local file_size_limit = module:get_option_number(module.name .. "_size_limit", 10 * 1024 * 1024); -- 10 MB 40 local file_size_limit = module:get_option_number(module.name .. "_size_limit", 10 * 1024 * 1024); -- 10 MB
40 local file_types = module:get_option_set(module.name .. "_allowed_file_types", {}); 41 local file_types = module:get_option_set(module.name .. "_allowed_file_types", {});
41 local safe_types = module:get_option_set(module.name .. "_safe_file_types", {"image/*","video/*","audio/*","text/plain"}); 42 local safe_types = module:get_option_set(module.name .. "_safe_file_types", {"image/*","video/*","audio/*","text/plain"});
42 local expiry = module:get_option_number(module.name .. "_expires_after", 7 * 86400); 43 local expiry_str = module:get_option_string(module.name .. "_expires_after", "1w");
44 local expiry, parse_err = parse_duration(expiry_str);
45 if expiry == nil then
46 module:log("error", "Could not parse "..module.name.."_expire_after string %q: %s", expiry_str, parse_err);
47 return false;
48 end
43 local daily_quota = module:get_option_number(module.name .. "_daily_quota", file_size_limit*10); -- 100 MB / day 49 local daily_quota = module:get_option_number(module.name .. "_daily_quota", file_size_limit*10); -- 100 MB / day
44 local total_storage_limit = module:get_option_number(module.name.."_global_quota", unlimited); 50 local total_storage_limit = module:get_option_number(module.name.."_global_quota", unlimited);
45 51
46 local create_jwt, verify_jwt = require "prosody.util.jwt".init("HS256", secret); 52 local create_jwt, verify_jwt = require "prosody.util.jwt".init("HS256", secret);
47 53