Skip to content

Instantly share code, notes, and snippets.

@andrey-utkin
Created November 13, 2023 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrey-utkin/0bb9c4e0e3d8d69d93cc09168509a705 to your computer and use it in GitHub Desktop.
Save andrey-utkin/0bb9c4e0e3d8d69d93cc09168509a705 to your computer and use it in GitHub Desktop.
diff -r 15c1801e8901 mod_http_upload/mod_http_upload.lua
--- a/mod_http_upload/mod_http_upload.lua Mon Nov 13 12:37:21 2023 +0100
+++ b/mod_http_upload/mod_http_upload.lua Mon Nov 13 15:33:32 2023 +0000
@@ -117,7 +117,7 @@
local storage_path = module:get_option_string(module.name .. "_path", join_path(prosody.paths.data, module.name));
lfs.mkdir(storage_path);
-local function expire(username, host)
+local function expire(username, host, max_age)
if not max_age then return true; end
local uploads, err = datamanager.list_load(username, host, module.name);
if err then return false, err; end
@@ -429,22 +429,46 @@
function module.command(args)
datamanager = require "core.storagemanager".olddm;
-- luacheck: ignore 421/user
- if args[1] == "expire" and args[2] then
- local split = require "util.jid".prepped_split;
- for i = 2, #args do
- local user, host = split(args[i]);
- if user then
- assert(expire(user, host));
- else
- for user in assert(datamanager.users(host, module.name, "list")) do
- expire(user, host);
+ if args[1] == "expire" then
+ if #args >= 2 then
+ local split = require "util.jid".prepped_split;
+ for i = 2, #args do
+ local user, host = split(args[i]);
+ if user then
+ assert(expire(user, host, max_age));
+ else
+ for user in assert(datamanager.users(host, module.name, "list")) do
+ expire(user, host, max_age);
+ end
end
end
+ else
+ print("prosodyctl mod_http_upload expire [host or user@host]+")
+ print("\tProcess upload expiry for the given list of hosts and/or users");
+ return 1;
end
- else
- print("prosodyctl mod_http_upload expire [host or user@host]+")
- print("\tProcess upload expiry for the given list of hosts and/or users");
- return 1;
end
+
+ if args[1] == "expire-after" then
+ if #args >= 3 then
+ local max_age = args[2]
+ local split = require "util.jid".prepped_split;
+ for i = 3, #args do
+ local user, host = split(args[i]);
+ if user then
+ assert(expire(user, host, max_age));
+ else
+ for user in assert(datamanager.users(host, module.name, "list")) do
+ expire(user, host, max_age);
+ end
+ end
+ end
+ else
+ print("prosodyctl mod_http_upload expire-after <max-age> [host or user@host]+")
+ print("\tProcess upload expiry with custom max age for the given list of hosts and/or users");
+ return 1;
+ end
+ end
+
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment