mirror of
https://github.com/lxsang/antd-web-apps
synced 2025-07-26 18:49:47 +02:00
WIP: make code compatible with new SILK API
All checks were successful
gitea-sync/antd-web-apps/pipeline/head This commit looks good
All checks were successful
gitea-sync/antd-web-apps/pipeline/head This commit looks good
This commit is contained in:
@ -7,8 +7,13 @@ BaseController:subclass(
|
||||
)
|
||||
|
||||
local sectionsByCid = function(db, id)
|
||||
local cond = {exp = { ["and"] = {{["="] = {cid = id}}, {["= "] = {publish = 1}} }}, order = {start = "DESC"}}
|
||||
local data, a = db:find(cond)
|
||||
local data, a = db:find({
|
||||
where = {
|
||||
cid = id,
|
||||
publish = 1
|
||||
},
|
||||
order = {"start$desc"}
|
||||
})
|
||||
return data, a
|
||||
end
|
||||
|
||||
@ -16,8 +21,12 @@ function IndexController:index(...)
|
||||
local args = {...}
|
||||
-- now read all the data
|
||||
-- get all root sections as the toc
|
||||
local cond = {exp = {["="] = {pid = 0}}, order = {name = "ASC"}}
|
||||
local data, a = self.category:find(cond)
|
||||
local data, a = self.category:find({
|
||||
where = {
|
||||
pid = 0
|
||||
},
|
||||
order = {"name$asc"}
|
||||
})
|
||||
local toc = {}
|
||||
if not data then
|
||||
return self:error("Cannot query the ToC")
|
||||
@ -26,8 +35,12 @@ function IndexController:index(...)
|
||||
for key, cat in pairs(data) do
|
||||
cat.name = cat.name:gsub("^%d+%.", "")
|
||||
table.insert(toc, {cat.name, cat.id})
|
||||
cond = {exp = {["="] = {pid = cat.id}}, order = {name = "ASC"}}
|
||||
local children, b = self.category:find(cond)
|
||||
local children, b = self.category:find({
|
||||
where = {
|
||||
pid = cat.id
|
||||
},
|
||||
order = {"name$asc"}
|
||||
})
|
||||
if children and #children > 0 then
|
||||
for k, v in pairs(children) do
|
||||
v.sections = sectionsByCid(self.sections, v.id)
|
||||
|
@ -28,7 +28,7 @@ function UserController:photo(...)
|
||||
local prefix = data[1].photo:match("%a+://")
|
||||
local suffix = data[1].photo:gsub(prefix,"")
|
||||
local path = string.format("/home/%s/", self.registry.user)..suffix
|
||||
print(path)
|
||||
LOG_DEBUG("Photo path: %s", path)
|
||||
if ulib.exists(path) then
|
||||
local mime = std.mimeOf(path)
|
||||
std.sendFile(path)
|
||||
|
@ -3,32 +3,33 @@
|
||||
-- should be something like this
|
||||
-- ^\/apps\/+(.*)$ = /apps/router.lua?r=<1>&<query>
|
||||
-- some global variables
|
||||
DIR_SEP = "/"
|
||||
package.path = _SERVER["LIB_DIR"].."/lua/?.lua"
|
||||
require("silk.api")
|
||||
WWW_ROOT = __ROOT__.."/info"
|
||||
if HEADER.Host then
|
||||
HTTP_ROOT= "https://"..HEADER.Host
|
||||
else
|
||||
HTTP_ROOT = "https://info.lxsang.me"
|
||||
HTTP_ROOT = "https://info.iohub.dev"
|
||||
end
|
||||
-- class path: path.to.class
|
||||
BASE_FRW = ""
|
||||
-- class path: path.to.class
|
||||
CONTROLLER_ROOT = BASE_FRW.."info.controllers"
|
||||
MODEL_ROOT = BASE_FRW.."info.models"
|
||||
-- TODO remove me
|
||||
HTTP_ROOT = HTTP_ROOT.."/next/info"
|
||||
|
||||
CONTROLLER_ROOT = "info.controllers"
|
||||
MODEL_ROOT = "info.models"
|
||||
-- file path: path/to/file
|
||||
VIEW_ROOT = WWW_ROOT..DIR_SEP.."views"
|
||||
LOG_ROOT = WWW_ROOT..DIR_SEP.."logs"
|
||||
|
||||
-- require needed library
|
||||
require(BASE_FRW.."silk.api")
|
||||
|
||||
-- registry object store global variables
|
||||
local REGISTRY = {}
|
||||
-- set logging level
|
||||
REGISTRY.logger = Logger:new{ levels = {INFO = false, ERROR = true, DEBUG = false}}
|
||||
REGISTRY.logger = Logger:new{ level = Logger.INFO}
|
||||
REGISTRY.users_allowed = { phuong = true, mrsang = true, dany = true }
|
||||
REGISTRY.user = "mrsang"
|
||||
REGISTRY.db = DBHelper:new{db=REGISTRY.user}
|
||||
-- TODO change me
|
||||
REGISTRY.user = "dany"
|
||||
REGISTRY.dbfile = "/home/"..REGISTRY.user.."/databases/"..REGISTRY.user..".db"
|
||||
|
||||
REGISTRY.db = DBModel:new{db=REGISTRY.dbfile}
|
||||
REGISTRY.layout = 'default'
|
||||
REGISTRY.fileaccess = true
|
||||
|
||||
@ -67,10 +68,12 @@ function NotfoundController:index(...)
|
||||
self:error("404: Controller "..args[1].." not found : "..args[2])
|
||||
return
|
||||
end
|
||||
REQUEST.r = std.trim(REQUEST.r:gsub(user, ""), "/")
|
||||
LOG_DEBUG("Request: %s", REQUEST.r)
|
||||
REQUEST.r = ulib.trim(REQUEST.r:gsub(user, ""), "/")
|
||||
if REGISTRY.db then REGISTRY.db:close() end
|
||||
REGISTRY.user = user
|
||||
REGISTRY.db = DBHelper:new{db=REGISTRY.user}
|
||||
REGISTRY.dbfile = "/home/"..REGISTRY.user.."/databases/"..REGISTRY.user..".db"
|
||||
REGISTRY.db = DBModel:new{db=REGISTRY.dbfile}
|
||||
REGISTRY.db:open()
|
||||
router:delegate()
|
||||
end
|
||||
|
@ -29,8 +29,8 @@
|
||||
<span><?=entry.subtitle?></span>
|
||||
<span class="date">
|
||||
<?lua
|
||||
if entry["start"]:match("^20%d.*") and entry['end']:match("^20%d.*") then
|
||||
echo(entry.start.."-"..entry['end'])
|
||||
if tostring(entry["start"]):match("^20%d.*") and tostring(entry['end']):match("^20%d.*") then
|
||||
echo("%d-%d",entry["start"],entry['end'])
|
||||
end
|
||||
?>
|
||||
</span>
|
||||
@ -71,8 +71,8 @@
|
||||
<span><?=entry.subtitle?></span>
|
||||
<span class="date">
|
||||
<?lua
|
||||
if entry["start"]:match("^20%d.*") and entry['end']:match("^20%d.*") then
|
||||
echo(entry.start.."-"..entry['end'])
|
||||
if tostring(entry["start"]):match("^20%d.*") and tostring(entry['end']):match("^20%d.*") then
|
||||
echo("%d-%d",entry["start"],entry['end'])
|
||||
end
|
||||
?>
|
||||
</span>
|
||||
|
@ -3,11 +3,12 @@
|
||||
<head>
|
||||
<script type="text/javascript" src="<?=HTTP_ROOT?>/rst/gscripts/showdown.min.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="<?=HTTP_ROOT?>/style.css" />
|
||||
<link rel="stylesheet" type="text/css" href="<?=HTTP_ROOT?>/rst/font-awesome.css" />
|
||||
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" />
|
||||
|
||||
<?lua
|
||||
if not toc then
|
||||
?>
|
||||
<link rel="stylesheet" type="text/css" href="<?=HTTP_ROOT?>/rst/ubuntu-regular.css" />
|
||||
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Ubuntu:regular,bold&subset=Latin" />
|
||||
<?lua
|
||||
end
|
||||
?>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<div class="header_container">
|
||||
<?lua if data.photo and data.photo ~= "" and data.user ~= "mrsang" then ?>
|
||||
<img src="/<?=data.user?>/user/photo"></img>
|
||||
<img src="<?=HTTP_ROOT?>/<?=data.user?>/user/photo"></img>
|
||||
<?lua end ?>
|
||||
<h1>
|
||||
<span class="name"><?=data.fullname?></span>
|
||||
|
Reference in New Issue
Block a user