feat: add versions info to API
gitea-sync/antos-backend/pipeline/head This commit looks good Details

This commit is contained in:
DanyLE 2024-03-17 21:11:37 +01:00
parent 37f68f0e04
commit ac36ba6ff0
4 changed files with 22 additions and 4 deletions

View File

@ -1,10 +1,11 @@
DESTDIR?=/opt/www/htdocs/os
BUILDID:=$(shell git rev-parse --short HEAD)
all:
- mkdir -p $(DESTDIR)
cp router.lua mimes.json $(DESTDIR)
cp -rf controllers $(DESTDIR)
cp -rf libs $(DESTDIR)
sed -i '1s/^/API_REF="$(BUILDID)"\n/' $(DESTDIR)/router.lua
clean:
rm -rf $(DESTDIR)/router.lua $(DESTDIR)/mimes.json \
$(DESTDIR)/controllers $(DESTDIR)/libs

View File

@ -20,7 +20,7 @@ function IndexController:doc(...)
author = "Xuan Sang LE",
email = "xsang.le@gmail.com",
api_name = "AntOS API",
version = "2.0.0-a",
version = API_VERSION,
documents = {
vfs = HTTP_ROOT.."/VFS",
user = HTTP_ROOT.."/user",

View File

@ -17,7 +17,8 @@ function SystemController:index(...)
["/packages"] = "Handle all operation relate to package: list, install, cache, uninstall",
["/settings"] = "Save user setting",
["/application"] = "Call a specific server side application api",
["/apigateway"] = "Gateway for executing custom server side code"
["/apigateway"] = "Gateway for executing custom server side code",
["/version"] = "All component versions"
}
}
result(api)
@ -248,3 +249,18 @@ function SystemController:apigateway(...)
cout('{"error":"User unauthorized. Please login"}')
end
end
function SystemController:version(...)
auth_or_die("User unauthorized. Please login")
local versions = {}
local version_file = string.format('%s/libs/versions.json', WWW_ROOT)
if ulib.exists(version_file) then
versions = JSON.decodeFile(version_file)
end
versions["REST"] = { version = API_VERSION, ref = "unknown" }
if API_REF then
versions["REST"]["ref"] = API_REF
end
result(versions)
return false
end

View File

@ -1,4 +1,5 @@
-- API version
API_VERSION = "2.1.0"
-- the rewrite rule for the framework
-- should be something like this
-- ^\/apps\/+(.*)$ = /apps/router.lua?r=<1>&<query>