Software / code / prosody
Comparison
plugins/mod_http_file_share.lua @ 13209:c8d949cf6b09
plugins: Switch to :get_option_period() for time range options
Improves readability ("1 day" vs 86400) and centralizes validation.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 16 Jul 2023 20:49:33 +0200 |
| parent | 13176:0d1cd3185299 |
| child | 13213:50324f66ca2a |
comparison
equal
deleted
inserted
replaced
| 13208:a7c6ea1c5308 | 13209:c8d949cf6b09 |
|---|---|
| 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; | |
| 23 | 22 |
| 24 local unknown = math.abs(0/0); | 23 local unknown = math.abs(0/0); |
| 25 local unlimited = math.huge; | 24 local unlimited = math.huge; |
| 26 | 25 |
| 27 local namespace = "urn:xmpp:http:upload:0"; | 26 local namespace = "urn:xmpp:http:upload:0"; |
| 38 local secret = module:get_option_string(module.name.."_secret", require"prosody.util.id".long()); | 37 local secret = module:get_option_string(module.name.."_secret", require"prosody.util.id".long()); |
| 39 local external_base_url = module:get_option_string(module.name .. "_base_url"); | 38 local external_base_url = module:get_option_string(module.name .. "_base_url"); |
| 40 local file_size_limit = module:get_option_number(module.name .. "_size_limit", 10 * 1024 * 1024); -- 10 MB | 39 local file_size_limit = module:get_option_number(module.name .. "_size_limit", 10 * 1024 * 1024); -- 10 MB |
| 41 local file_types = module:get_option_set(module.name .. "_allowed_file_types", {}); | 40 local file_types = module:get_option_set(module.name .. "_allowed_file_types", {}); |
| 42 local safe_types = module:get_option_set(module.name .. "_safe_file_types", {"image/*","video/*","audio/*","text/plain"}); | 41 local safe_types = module:get_option_set(module.name .. "_safe_file_types", {"image/*","video/*","audio/*","text/plain"}); |
| 43 local expiry_str = module:get_option_string(module.name .. "_expires_after", "1w"); | 42 local expiry = module:get_option_period(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 | |
| 49 local daily_quota = module:get_option_number(module.name .. "_daily_quota", file_size_limit*10); -- 100 MB / day | 43 local daily_quota = module:get_option_number(module.name .. "_daily_quota", file_size_limit*10); -- 100 MB / day |
| 50 local total_storage_limit = module:get_option_number(module.name.."_global_quota", unlimited); | 44 local total_storage_limit = module:get_option_number(module.name.."_global_quota", unlimited); |
| 51 | 45 |
| 52 local create_jwt, verify_jwt = require"prosody.util.jwt".init("HS256", secret, secret, { default_ttl = 600 }); | 46 local create_jwt, verify_jwt = require"prosody.util.jwt".init("HS256", secret, secret, { default_ttl = 600 }); |
| 53 | 47 |