Changeset

6165:11650fe276c0

mod_storage_metronome_readonly: Add support for migrating to mod_http_file_share
author Link Mauve <linkmauve@linkmauve.fr>
date Mon, 27 Jan 2025 19:17:49 +0100
parents 6164:eedeed1bccf7
children 6166:8eec0a296218
files mod_storage_metronome_readonly/README.markdown mod_storage_metronome_readonly/mod_storage_metronome_readonly.lua
diffstat 2 files changed, 68 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mod_storage_metronome_readonly/README.markdown	Sat Jan 25 00:18:08 2025 +0100
+++ b/mod_storage_metronome_readonly/README.markdown	Mon Jan 27 19:17:49 2025 +0100
@@ -33,7 +33,7 @@
 
 To run the actual migration, run this command:
 
-    ./prosodyctl mod_migrate kl.netlib.re roster,vcard,private,cloud_notify,pep,pep-archive,offline-archive,archive-archive sql
+    ./prosodyctl mod_migrate <host> roster,vcard,private,cloud_notify,pep,pep-archive,offline-archive,archive-archive sql
 
 It will create a file in `/var/lib/metronome/prosody.sqlite`, after which you
 can change your configuration file to point to it, or alternatively you can
--- a/mod_storage_metronome_readonly/mod_storage_metronome_readonly.lua	Sat Jan 25 00:18:08 2025 +0100
+++ b/mod_storage_metronome_readonly/mod_storage_metronome_readonly.lua	Mon Jan 27 19:17:49 2025 +0100
@@ -17,6 +17,27 @@
         return s and (s:gsub("%W", function (c) return string.format("%%%02x", c:byte()); end));
 end
 
+local file = io.open("/etc/mime.types");
+local mimes = {};
+while true do
+	local line = file:read("*l");
+	if not line then
+		break;
+	end
+	if line ~= "" then
+		local first_char = line:sub(1, 1);
+		if first_char ~= "#" then
+			--local line:match("(%S+)%s+"));
+			local match = line:gmatch("%S+");
+			local mime = match();
+			for ext in match do
+				mimes[ext] = mime;
+			end
+		end
+	end
+end
+file:close();
+
 local driver = {};
 
 function driver:open(store, typ)
@@ -246,26 +267,60 @@
 
 		return function()
 			local item = iter();
-			print(item)
 			if item == nil then
 				if list.close then
 					list:close();
 				end
 				return
 			end
-			print(0)
 			local key = id();
 			local when = item.attr and datetime.parse(item.attr.stamp);
 			local with = "";
-			print(1)
 			item.key, item.when, item.with = nil, nil, nil;
 			item.attr.stamp = nil;
 			-- COMPAT Stored data may still contain legacy XEP-0091 timestamp
 			item.attr.stamp_legacy = nil;
 			item = st.deserialize(item);
-			print(key, when, with, item)
 			return key, item, when, with;
 		end
+	elseif self.store == "uploads" then
+		local list = {};
+
+		for user in datamanager.users(host, "http_upload", "list") do
+			local data, err = datamanager.list_open(user, host, "http_upload");
+			if not data then
+				if err then
+					return data, err;
+				end
+				return function()
+				end;
+			end
+
+			for _, stuff in ipairs(data) do
+				local dir = stuff.dir;
+				local size = tostring(stuff.size);
+				local time = stuff.time;
+				local filename = stuff.filename;
+				local ext = filename:match(".*%.(%S+)"):lower();
+				local mime = mimes[ext] or "application/octet-stream";
+				local stanza = st.stanza("request", { xmlns = "urn:xmpp:http:upload:0", size = size, ["content-type"] = mime, filename = filename })
+				list[dir] = {user, time, stanza};
+			end
+		end
+
+		local iter = pairs(list);
+		local key = nil;
+		local payload;
+		return function()
+			key, payload = iter(list, key);
+			if not key then
+				return;
+			end
+			local with = payload[1];
+			local when = payload[2];
+			local stanza = payload[3];
+			return key, stanza, when, with;
+		end;
 	else
 		return nil, "unsupported-store";
 	end
@@ -316,6 +371,14 @@
 		end;
 	elseif self.store == "offline" then
 		return datamanager.users(host, self.store, "list");
+	elseif self.store == "uploads" then
+		local done = false;
+		return function()
+			if not done then
+				done = true;
+				return "";
+			end
+		end;
 	else
 		return nil, "unsupported-store";
 	end