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

52 lines
1.2 KiB
Lua

local get = {}
get.fetch = function(user, cnd, limit)
local db = require("db.model").get(user,"blogs",nil)
if not db then return nil end
local exp = {}
exp[1] = {["="] = { publish = 1 }}
if cnd then
exp[2] = cnd
else
end
local cond = { exp = {["and"] = exp }, order = { ctime = "DESC" }}
if limit then
cond.limit = limit
end
local data, sort = db:find(cond)
db:close()
return data, sort
end
get.top = function(user, limit)
return get.fetch(user, nil, limit)
end
get.id = function(user, id)
return get.fetch(user, { ["="] = { id = id } }, nil)
end
get.afterof = function(user, id, limit)
return get.fetch(user, { [">"] = { id = id } }, limit)
end
get.beforeof = function(user, id, limit)
return get.fetch(user, { ["<"] = { id = id } }, limit)
end
get.nextof = function(user, id)
return get.afterof(user, id, 1)
end
get.prevof = function(user, id)
return get.beforeof(user, id, 1)
end
get.bytag = function(user, b64tag, limit)
local tag = bytes.__tostring(std.b64decode(b64tag.."=="))
return get.fetch(user, { ["LIKE"] = { tags = "%%"..tag.."%%" } }, limit)
end
return get