This commit is contained in:
1 parent
7224137ed2
commit
52cb59f33f
8 files changed
+60
-9
No files matched your search
@@ -29,11 +29,14 @@ local function summary(s)
|
||||
reason = s.reason, ms = s.ms, checked = s.checked }
|
||||
end
|
||||
|
||||
local function statusOf(params)
|
||||
return params.status == "on" and "on" or params.status == "off" and "off" or nil
|
||||
end
|
||||
|
||||
local function listing(params)
|
||||
local page = math.max(1, math.floor(tonumber(params.page) or 1))
|
||||
local size = math.min(200, math.max(1, math.floor(tonumber(params.size) or 50)))
|
||||
local status = params.status == "on" and "on" or params.status == "off" and "off" or nil
|
||||
local list, total = Sources.page(params.q and tostring(params.q) or nil, status, page, size)
|
||||
local list, total = Sources.page(params.q and tostring(params.q) or nil, statusOf(params), page, size)
|
||||
local sources = {}
|
||||
for _idx, s in ipairs(list) do sources[#sources + 1] = summary(s) end
|
||||
return { sources = sources, total = total, counts = Sources.counts() }
|
||||
@@ -161,6 +164,8 @@ function Remote.handle(method, action, params, cb)
|
||||
require("utils.awake").poke()
|
||||
if method == "GET" and action == "list" then
|
||||
cb(200, listing(params))
|
||||
elseif method == "GET" and action == "keys" then
|
||||
cb(200, { keys = Sources.keys(params.q and tostring(params.q) or nil, statusOf(params)) })
|
||||
elseif method == "POST" and action == "import" then
|
||||
-- 原始文件体落在临时文件里(路径在 params.temp);粘贴的文本由网页同样当文件体发来
|
||||
local path = params.temp
|
||||
|
||||
Reference in new issue
Block a user