diff --git a/Makefile b/Makefile index c6b3d9a..9068c24 100644 --- a/Makefile +++ b/Makefile @@ -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 \ No newline at end of file diff --git a/controllers/IndexController.lua b/controllers/IndexController.lua index 74df671..22b1f60 100644 --- a/controllers/IndexController.lua +++ b/controllers/IndexController.lua @@ -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", diff --git a/controllers/SystemController.lua b/controllers/SystemController.lua index 0703411..b3ca666 100644 --- a/controllers/SystemController.lua +++ b/controllers/SystemController.lua @@ -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 diff --git a/router.lua b/router.lua index 2c99027..19ce9b6 100644 --- a/router.lua +++ b/router.lua @@ -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>&