1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2024-11-20 02:18:20 +01:00
antd-web-apps/blog/router.lua

43 lines
1.1 KiB
Lua
Raw Normal View History

2018-02-23 19:52:10 +01:00
BLOG_ROOT = __ROOT__.."/blog"
2018-03-07 14:18:25 +01:00
MAX_ENTRY = 15
LAST_QUERY = nil
2018-06-05 15:40:15 +02:00
BLOG_ADMIN = "mrsang"
local user = BLOG_ADMIN
2018-02-23 19:52:10 +01:00
local handle = function(p)
local args = {}
local sort = {}
local i = 1
for s in p:gmatch("%:*([^%:]*)") do
args[i] = s
table.insert(sort, i)
i = i+1
end
table.sort(sort)
local api = require("blog.api")
2018-03-07 14:18:25 +01:00
local minid = api.minid(user)
local maxid = api.maxid(user)
2018-02-23 19:52:10 +01:00
if #args == 0 or api == nil then
echo("Unknow request "..p)
elseif not api[args[1]] then
echo("Unknow action.."..args[1])
else
local action = args[1]
args[1] = user
local data, sort = api[action](table.unpack(args))
if data == nil then
echo("Cannot query data")
else
2018-03-07 14:18:25 +01:00
require("blog.view").render(action, data, sort, minid, maxid)
2018-02-23 19:52:10 +01:00
end
end
end
2018-02-25 01:57:42 +01:00
std.html()
local action = REQUEST.query.action
2018-03-07 14:18:25 +01:00
if not action then action = "r:top:"..MAX_ENTRY end
2018-02-25 01:57:42 +01:00
local r, s = action:find("^r:")
if r then
handle(action:sub(s+1))
else
echo("Unknow action "..action)
end