Comparison

plugins/mod_http_file_share.lua @ 12977:74b9e05af71e

plugins: Prefix module imports with prosody namespace
author Kim Alvefur <zash@zash.se>
date Fri, 24 Mar 2023 13:15:28 +0100
parent 12722:cd993fd7b60d
child 13056:c38b1c63aa5c
comparison
equal deleted inserted replaced
12976:a187600ec7d6 12977:74b9e05af71e
6 -- 6 --
7 -- XEP-0363: HTTP File Upload 7 -- XEP-0363: HTTP File Upload
8 -- Again, from the top! 8 -- Again, from the top!
9 9
10 local t_insert = table.insert; 10 local t_insert = table.insert;
11 local jid = require "util.jid"; 11 local jid = require "prosody.util.jid";
12 local st = require "util.stanza"; 12 local st = require "prosody.util.stanza";
13 local url = require "socket.url"; 13 local url = require "socket.url";
14 local dm = require "core.storagemanager".olddm; 14 local dm = require "prosody.core.storagemanager".olddm;
15 local errors = require "util.error"; 15 local errors = require "prosody.util.error";
16 local dataform = require "util.dataforms".new; 16 local dataform = require "prosody.util.dataforms".new;
17 local urlencode = require "util.http".urlencode; 17 local urlencode = require "prosody.util.http".urlencode;
18 local dt = require "util.datetime"; 18 local dt = require "prosody.util.datetime";
19 local hi = require "util.human.units"; 19 local hi = require "prosody.util.human.units";
20 local cache = require "util.cache"; 20 local cache = require "prosody.util.cache";
21 local lfs = require "lfs"; 21 local lfs = require "lfs";
22 22
23 local unknown = math.abs(0/0); 23 local unknown = math.abs(0/0);
24 local unlimited = math.huge; 24 local unlimited = math.huge;
25 25
32 32
33 local uploads = module:open_store("uploads", "archive"); 33 local uploads = module:open_store("uploads", "archive");
34 local persist_stats = module:open_store("upload_stats", "map"); 34 local persist_stats = module:open_store("upload_stats", "map");
35 -- id, <request>, time, owner 35 -- id, <request>, time, owner
36 36
37 local secret = module:get_option_string(module.name.."_secret", require"util.id".long()); 37 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"); 38 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 39 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", {}); 40 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"}); 41 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); 42 local expiry = module:get_option_number(module.name .. "_expires_after", 7 * 86400);
43 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
44 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);
45 45
46 local create_jwt, verify_jwt = require "util.jwt".init("HS256", secret); 46 local create_jwt, verify_jwt = require "prosody.util.jwt".init("HS256", secret);
47 47
48 local access = module:get_option_set(module.name .. "_access", {}); 48 local access = module:get_option_set(module.name .. "_access", {});
49 49
50 if not external_base_url then 50 if not external_base_url then
51 module:depends("http"); 51 module:depends("http");
450 return response:send_file(handle); 450 return response:send_file(handle);
451 end 451 end
452 452
453 if expiry >= 0 and not external_base_url then 453 if expiry >= 0 and not external_base_url then
454 -- TODO HTTP DELETE to the external endpoint? 454 -- TODO HTTP DELETE to the external endpoint?
455 local array = require "util.array"; 455 local array = require "prosody.util.array";
456 local async = require "util.async"; 456 local async = require "prosody.util.async";
457 local ENOENT = require "util.pposix".ENOENT; 457 local ENOENT = require "prosody.util.pposix".ENOENT;
458 458
459 local function sleep(t) 459 local function sleep(t)
460 local wait, done = async.waiter(); 460 local wait, done = async.waiter();
461 module:add_timer(t, done) 461 module:add_timer(t, done)
462 wait(); 462 wait();