|
@@ -1,21 +1,29 @@
|
|
local announce = require 'gluon.announce'
|
|
local announce = require 'gluon.announce'
|
|
local deflate = require 'deflate'
|
|
local deflate = require 'deflate'
|
|
local json = require 'luci.jsonc'
|
|
local json = require 'luci.jsonc'
|
|
|
|
+local nixio = require 'nixio'
|
|
|
|
+local fs = require 'nixio.fs'
|
|
|
|
|
|
|
|
+local memoize = {}
|
|
|
|
|
|
-local function collect(type)
|
|
|
|
- return announce.collect_dir('/lib/gluon/announce/' .. type .. '.d')
|
|
|
|
|
|
+nixio.chdir('/lib/gluon/announce/')
|
|
|
|
+
|
|
|
|
+for dir in fs.glob('*.d') do
|
|
|
|
+ local name = dir:sub(1, -3)
|
|
|
|
+ memoize[name] = announce.collect_dir(dir)
|
|
end
|
|
end
|
|
|
|
|
|
|
|
+local function collect(type)
|
|
|
|
+ return memoize[type] and memoize[type]()
|
|
|
|
+end
|
|
|
|
|
|
module('gluon.announced', package.seeall)
|
|
module('gluon.announced', package.seeall)
|
|
|
|
|
|
function handle_request(query)
|
|
function handle_request(query)
|
|
- if query:match('^nodeinfo$') then
|
|
|
|
- return json.stringify(collect('nodeinfo'))
|
|
|
|
- end
|
|
|
|
|
|
+ collectgarbage()
|
|
|
|
|
|
local m = query:match('^GET ([a-z ]+)$')
|
|
local m = query:match('^GET ([a-z ]+)$')
|
|
|
|
+ local ret
|
|
if m then
|
|
if m then
|
|
local data = {}
|
|
local data = {}
|
|
|
|
|
|
@@ -27,7 +35,16 @@ function handle_request(query)
|
|
end
|
|
end
|
|
|
|
|
|
if next(data) then
|
|
if next(data) then
|
|
- return deflate.compress(json.stringify(data))
|
|
|
|
|
|
+ ret = deflate.compress(json.stringify(data))
|
|
|
|
+ end
|
|
|
|
+ elseif query:match('^[a-z]+$') then
|
|
|
|
+ local ok, data = pcall(collect, query)
|
|
|
|
+ if ok then
|
|
|
|
+ ret = json.stringify(data)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
+
|
|
|
|
+ collectgarbage()
|
|
|
|
+
|
|
|
|
+ return ret
|
|
end
|
|
end
|