Mercurial > prosody-modules
comparison mod_nodeinfo2/mod_nodeinfo2.lua @ 3786:58e484426d13
mod_nodeinfo2: Fix traceback on non-existing data
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 29 Dec 2019 23:41:32 +0100 |
parents | 741a1e400de4 |
children | e3b673df3906 |
comparison
equal
deleted
inserted
replaced
3785:6273705e3830 | 3786:58e484426d13 |
---|---|
36 half_year_users = nil; | 36 half_year_users = nil; |
37 month_users = nil; | 37 month_users = nil; |
38 week_users = nil; | 38 week_users = nil; |
39 end | 39 end |
40 | 40 |
41 local data = main_store:get("nodeinfo2"); | 41 local data = main_store:get("nodeinfo2") or { message_count = 0 }; |
42 | 42 |
43 module:provides("http", { | 43 module:provides("http", { |
44 default_path = "/.well-known/x-nodeinfo2"; | 44 default_path = "/.well-known/x-nodeinfo2"; |
45 route = { | 45 route = { |
46 GET = function (event) | 46 GET = function (event) |
47 local stats, changed_only, extras = get_stats(); | 47 local stats, changed_only, extras = get_stats(); |
48 for stat, _ in pairs(stats) do | 48 for stat, _ in pairs(stats) do |
49 if stat == "/"..module.host.."/mod_measure_message_e2ee/message:rate" then | 49 if stat == "/"..module.host.."/mod_measure_message_e2ee/message:rate" then |
50 local new_message_count = extras[stat].total; | 50 local new_message_count = extras[stat].total; |
51 if not data or new_message_count ~= data.message_count then | 51 if new_message_count ~= data.message_count then |
52 data = { message_count = new_message_count }; | 52 data = { message_count = new_message_count }; |
53 main_store:set("nodeinfo2", data); | 53 main_store:set("nodeinfo2", data); |
54 end | 54 end |
55 end | 55 end |
56 end | 56 end |