Diff

mod_http_muc_log/mod_http_muc_log.lua @ 3593:0b670831ace3

mod_http_muc_log: Correctly build absolute URLs Handles case of http_path being "/", where :http_url() ends with a slash, so there would be two slashes.
author Kim Alvefur <zash@zash.se>
date Mon, 13 May 2019 10:50:00 +0200
parent 3592:61a9c087730a
child 3594:b66111f75e4b
line wrap: on
line diff
--- a/mod_http_muc_log/mod_http_muc_log.lua	Mon May 13 00:23:04 2019 +0200
+++ b/mod_http_muc_log/mod_http_muc_log.lua	Mon May 13 10:50:00 2019 +0200
@@ -59,6 +59,22 @@
 	end
 end
 
+local function get_absolute_link(room, date)
+	local link = url.parse(module:http_url());
+	local path = url.parse_path(link.path);
+	if room then
+		table.insert(path, room);
+		if date then
+			table.insert(path, date)
+			path.is_directory = false;
+		else
+			path.is_directory = true;
+		end
+	end
+	link.path = url.build_path(path)
+	return url.build(link)
+end
+
 -- Whether room can be joined by anyone
 local function open_room(room) -- : boolean
 	if type(room) == "string" then
@@ -84,7 +100,7 @@
 	local room = event.room;
 	if open_room(room) then
 		table.insert(event.form, { name = "muc#roominfo_logs", type="text-single" });
-		event.formdata["muc#roominfo_logs"] = module:http_url() .. "/" .. get_link(jid_split(event.room.jid), nil);
+		event.formdata["muc#roominfo_logs"] = get_absolute_link(jid_split(event.room.jid), nil);
 	end
 end);