From 0da98332c5553e4201d39d380bd419806317f07c Mon Sep 17 00:00:00 2001 From: lxsang Date: Wed, 24 Jun 2020 19:49:19 +0200 Subject: [PATCH] add api doc --- doc/controllers/AntosController.lua | 5 +++-- doc/controllers/doccontroller.lua | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/doc/controllers/AntosController.lua b/doc/controllers/AntosController.lua index 2cbfefd..20a001a 100644 --- a/doc/controllers/AntosController.lua +++ b/doc/controllers/AntosController.lua @@ -2,10 +2,11 @@ require(CONTROLLER_ROOT..".doccontroller") DocController:subclass("AntosController", { path_map = { vfs_path = "home://doc/antos", - local_path = "/home/mrsang/doc/antos" + local_path = "/home/mrsang/doc/antos", + api_path = "/opt/www/htdocs/doc/antos" }, name = "antos", elinks = { - { name = "API", url = "https://doc.iohub.dev/antos/api/" } + { name = "API", url = "https://doc.iohub.dev/antos/api/index.html" } } }) diff --git a/doc/controllers/doccontroller.lua b/doc/controllers/doccontroller.lua index d6a6613..a97cd78 100644 --- a/doc/controllers/doccontroller.lua +++ b/doc/controllers/doccontroller.lua @@ -165,6 +165,30 @@ function DocController:search(...) return true end +function DocController:api(...) + local args = {...} + if not self.path_map.api_path then + return self:actionnotfound(table.unpack(args)) + end + local rpath = "index.html" + if #args ~= 0 then + rpath = implode(args,"/") + end + local path = self.path_map.api_path.."/"..rpath + + if ulib.exists(path) then + local mime = std.mimeOf(path) + if POLICY.mimes[mime] then + std.sendFile(path) + else + self:error("Access forbidden: "..path) + end + else + self:error("File not found or access forbidden: "..path) + end + return false +end + function DocController:actionnotfound(...) local args = {...} return self:index(table.unpack(args))