diff options
author | steckbrief <steckbrief@chefmail.de> | 2018-10-20 19:01:24 +0200 |
---|---|---|
committer | steckbrief <steckbrief@chefmail.de> | 2018-10-20 19:01:24 +0200 |
commit | 4dca5c1160880faf05c87db3a268e2143ee8924d (patch) | |
tree | 16f4ce1b28bc0670cf9d6ee06a722e13137d3681 /prosody-module/mod_http_upload_external/mod_http_upload_external.lua | |
parent | cf3467ce1f1327856821bd4b10217ec7ddacff80 (diff) |
adds basic rsm 'https://xmpp.org/extensions/xep-0059.html' functionality for file-listing
Diffstat (limited to 'prosody-module/mod_http_upload_external/mod_http_upload_external.lua')
-rw-r--r-- | prosody-module/mod_http_upload_external/mod_http_upload_external.lua | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/prosody-module/mod_http_upload_external/mod_http_upload_external.lua b/prosody-module/mod_http_upload_external/mod_http_upload_external.lua index f6f724f..cc68e2a 100644 --- a/prosody-module/mod_http_upload_external/mod_http_upload_external.lua +++ b/prosody-module/mod_http_upload_external/mod_http_upload_external.lua @@ -21,6 +21,7 @@ local http = (string.len(external_url) >= 5 and string.sub(external_url,1,5) == local json = require"util.json"; local dataform = require "util.dataforms".new; local ltn12 = require"ltn12"; +local rsm = require"util.rsm"; -- depends module:depends("disco"); @@ -45,8 +46,15 @@ if filetransfer_manager_ui_url then end local function listfiles(origin, orig_from, stanza, request) + local rsmSet = rsm.get(request); + local limit = rsmSet and rsmSet.max or -1; + local descending = rsmSet and rsmSet.before or false; + local index = rsmSet and rsmSet.index or 0; + --local before, after = rsmSet and rsmSet.before, rsmSet and rsmSet.after; + --if type(before) ~= "string" then before = nil; end + -- build the body - local reqbody = "xmpp_server_key=" .. xmpp_server_key .. "&slot_type=list&user_jid=" .. orig_from; + local reqbody = "xmpp_server_key=" .. xmpp_server_key .. "&slot_type=list&user_jid=" .. orig_from .. "&offset=" .. index .. "&limit=" .. limit .. "&descending=" .. tostring(descending); -- the request local respbody, statuscode = http.request(external_url, reqbody); -- respbody is nil in case the server is not reachable @@ -54,8 +62,10 @@ local function listfiles(origin, orig_from, stanza, request) respbody = string.gsub(respbody, "\\/", "/"); end - local filelistempty = true; local list; + local count = 0; + local first = {}; + first.index = index; -- check the response if statuscode == 500 then @@ -82,8 +92,10 @@ local function listfiles(origin, orig_from, stanza, request) return true; else -- process json response - list = respobj.list; - filelistempty = list == nil or next(list) == nil; + if respobj.list then + list = respobj.list.files; + count = respobj.list.count; + end end else origin.send(st.error_reply(stanza, "cancel", "undefined-condition", "status code: " .. statuscode .. " response: " ..respbody)); @@ -93,7 +105,7 @@ local function listfiles(origin, orig_from, stanza, request) local addedfiles = 0; local reply = st.reply(stanza); reply:tag("list", {xmlns=xmlns_filetransfer_http}); - if filelistempty == false then + if count > 0 then for i, file in ipairs(list) do local url = file.url; if url == "" then @@ -118,9 +130,10 @@ local function listfiles(origin, orig_from, stanza, request) end end end - if filelistempty or addedfiles == 0 then + if count == 0 or addedfiles == 0 then reply:tag("empty"):up(); end + reply:add_child(rsm.generate{first = first, count = count}) origin.send(reply); return true; end |