Software / code / prosody-modules
Comparison
mod_invites_api/mod_invites_api.lua @ 5628:a74b07764d3f
mod_invites_api: use the nice `module:http_url()` to get the correct url.
| author | Trần H. Trung <xmpp:trần.h.trung@trung.fun> |
|---|---|
| date | Thu, 27 Jul 2023 18:33:12 +0700 |
| parent | 5595:f7410850941f |
| child | 5629:160868fdddd6 |
comparison
equal
deleted
inserted
replaced
| 5627:89b6d0e09b86 | 5628:a74b07764d3f |
|---|---|
| 8 -- Who can see and use the contact invite command. It is strongly recommened to | 8 -- Who can see and use the contact invite command. It is strongly recommened to |
| 9 -- keep this available to all local users. To allow/disallow invite-registration | 9 -- keep this available to all local users. To allow/disallow invite-registration |
| 10 -- on the server, use the option above instead. | 10 -- on the server, use the option above instead. |
| 11 local allow_contact_invites = module:get_option_boolean("allow_contact_invites", true); | 11 local allow_contact_invites = module:get_option_boolean("allow_contact_invites", true); |
| 12 | 12 |
| 13 local api_key_store, api_key_store_kv, invites, date, config, path; | 13 local api_key_store, api_key_store_kv, invites, date, config, path, url_base; |
| 14 -- COMPAT: workaround to avoid executing inside prosodyctl | 14 -- COMPAT: workaround to avoid executing inside prosodyctl |
| 15 if prosody.shutdown then | 15 if prosody.shutdown then |
| 16 module:depends("http"); | 16 module:depends("http"); |
| 17 api_key_store = module:open_store("invite_api_keys", "map"); | 17 api_key_store = module:open_store("invite_api_keys", "map"); |
| 18 invites = module:depends("invites"); | 18 invites = module:depends("invites"); |
| 106 callback(key_id, key_info); | 106 callback(key_id, key_info); |
| 107 end | 107 end |
| 108 end | 108 end |
| 109 | 109 |
| 110 local function get_url(id, token) | 110 local function get_url(id, token) |
| 111 local config, path = module:get_option("http_paths"); | 111 local url_base = module:context(module.host):http_url(module.name, "/"..module.name); |
| 112 if config then | 112 return url_base.."?key="..id.."/"..token.."&redirect=true"; |
| 113 for k, v in pairs(config) do | |
| 114 if k == module.name then | |
| 115 path = v; | |
| 116 break; | |
| 117 else | |
| 118 path = "/"..module.name; | |
| 119 end | |
| 120 end | |
| 121 else path = "/"..module.name ; end | |
| 122 | |
| 123 local url_base = module:get_option_string("http_external_link", module.host); | |
| 124 return url_base..path.."?key="..id.."/"..token.."&redirect=true"; | |
| 125 end | 113 end |
| 126 | 114 |
| 127 function module.command(arg) | 115 function module.command(arg) |
| 128 if #arg < 2 then | 116 if #arg < 2 then |
| 129 print("========================================================================"); | 117 print("========================================================================"); |