mirror of
https://github.com/antos-rde/antos-backend.git
synced 2024-11-20 04:18:23 +01:00
remove VDB support, use new DB filtering syntax
All checks were successful
gitea-sync/antos-backend/pipeline/head This commit looks good
All checks were successful
gitea-sync/antos-backend/pipeline/head This commit looks good
This commit is contained in:
parent
f4c7342fc3
commit
54a0a130b2
@ -23,7 +23,6 @@ function IndexController:doc(...)
|
|||||||
version = "2.0.0-a",
|
version = "2.0.0-a",
|
||||||
documents = {
|
documents = {
|
||||||
vfs = HTTP_ROOT.."/VFS",
|
vfs = HTTP_ROOT.."/VFS",
|
||||||
vdb = HTTP_ROOT.."/VDB",
|
|
||||||
user = HTTP_ROOT.."/user",
|
user = HTTP_ROOT.."/user",
|
||||||
system = HTTP_ROOT.."/system"
|
system = HTTP_ROOT.."/system"
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ function UserController:login(...)
|
|||||||
local cookie = {sessionid=enc.sha1(request.username..request.password..salt)} -- iotos_user = request.username
|
local cookie = {sessionid=enc.sha1(request.username..request.password..salt)} -- iotos_user = request.username
|
||||||
local db = sysdb();
|
local db = sysdb();
|
||||||
if db == nil then return fail("Cannot setup session") end
|
if db == nil then return fail("Cannot setup session") end
|
||||||
local cond = {exp= {["="] = { sessionid = cookie.sessionid }}}
|
local cond = {where = { sessionid = cookie.sessionid }}
|
||||||
local data = db:find(cond)
|
local data = db:find(cond)
|
||||||
--print(data)
|
--print(data)
|
||||||
if data == nil or data[1] == nil then
|
if data == nil or data[1] == nil then
|
||||||
@ -89,7 +89,7 @@ function UserController:logout(...)
|
|||||||
local cookie = {sessionid='0'}
|
local cookie = {sessionid='0'}
|
||||||
local db = sysdb()
|
local db = sysdb()
|
||||||
if db ~= nil then
|
if db ~= nil then
|
||||||
local cond = {["="] = { sessionid = SESSION.sessionid }}
|
local cond = {where = { sessionid = SESSION.sessionid }}
|
||||||
db:delete(cond)
|
db:delete(cond)
|
||||||
db:close()
|
db:close()
|
||||||
end
|
end
|
||||||
|
@ -1,130 +0,0 @@
|
|||||||
BaseController:subclass(
|
|
||||||
"VDBController",
|
|
||||||
{
|
|
||||||
registry = {},
|
|
||||||
models = {}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
function VDBController:actionnotfound(...)
|
|
||||||
return self:index(table.unpack({...}))
|
|
||||||
end
|
|
||||||
|
|
||||||
function VDBController:index(...)
|
|
||||||
local api = {
|
|
||||||
description = "This api handle database operation",
|
|
||||||
actions = {
|
|
||||||
["/save"] = "Save a record to a table",
|
|
||||||
["/get"] = "Get all records or Get a record by id",
|
|
||||||
["/select"] = "Select records by a condition",
|
|
||||||
["/delete"] = "Delete record(s) by condition or by id"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result(api)
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
function VDBController:save(...)
|
|
||||||
auth_or_die("User unauthorized. Please login")
|
|
||||||
local rq = (JSON.decodeString(REQUEST.json))
|
|
||||||
if (rq ~= nil and rq.table ~= nil) then
|
|
||||||
local model = require("dbmodel").get(SESSION.user, rq.table, rq.data)
|
|
||||||
local ret
|
|
||||||
if model == nil then
|
|
||||||
fail("Cannot get table metadata:" .. rq.table)
|
|
||||||
else
|
|
||||||
if (rq.data.id ~= nil) then
|
|
||||||
rq.data.id = tonumber(rq.data.id)
|
|
||||||
ret = model:update(rq.data)
|
|
||||||
else
|
|
||||||
ret = model:insert(rq.data)
|
|
||||||
end
|
|
||||||
model:close()
|
|
||||||
if ret == true then
|
|
||||||
result(ret)
|
|
||||||
else
|
|
||||||
fail("Cannot modify/update table " .. rq.table)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
fail("Unknown database request")
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
function VDBController:get(...)
|
|
||||||
auth_or_die("User unauthorized. Please login")
|
|
||||||
local rq = (JSON.decodeString(REQUEST.json))
|
|
||||||
if (rq ~= nil and rq.table ~= nil) then
|
|
||||||
local model = require("dbmodel").get(SESSION.user, rq.table, nil)
|
|
||||||
local ret
|
|
||||||
if model == nil then
|
|
||||||
fail("Cannot get table metadata:" .. rq.table)
|
|
||||||
else
|
|
||||||
if (rq.id == nil) then
|
|
||||||
ret = model:getAll()
|
|
||||||
else
|
|
||||||
ret = model:get(rq.id)
|
|
||||||
end
|
|
||||||
model:close()
|
|
||||||
result(ret)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
fail("Unknown database request")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function VDBController:select(...)
|
|
||||||
auth_or_die("User unauthorized. Please login")
|
|
||||||
local rq = (JSON.decodeString(REQUEST.json))
|
|
||||||
if (rq ~= nil and rq.table ~= nil) then
|
|
||||||
local model = require("dbmodel").get(SESSION.user, rq.table, nil)
|
|
||||||
local ret
|
|
||||||
if model == nil then
|
|
||||||
fail("Cannot get table metadata:" .. rq.table)
|
|
||||||
else
|
|
||||||
if (rq.cond == nil) then
|
|
||||||
model:close()
|
|
||||||
return fail("Unknow condition")
|
|
||||||
else
|
|
||||||
ret = model:find(rq.cond)
|
|
||||||
end
|
|
||||||
model:close()
|
|
||||||
result(ret)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
fail("Unknown database request")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function VDBController:delete(...)
|
|
||||||
auth_or_die("User unauthorized. Please login")
|
|
||||||
local rq = (JSON.decodeString(REQUEST.json))
|
|
||||||
if (rq ~= nil and rq.table ~= nil) then
|
|
||||||
local model = require("dbmodel").get(SESSION.user, rq.table, nil)
|
|
||||||
local ret
|
|
||||||
if model == nil then
|
|
||||||
fail("Cannot get table metadata:" .. rq.table)
|
|
||||||
else
|
|
||||||
if (rq.id == nil) then
|
|
||||||
if (rq.cond) then
|
|
||||||
ret = model:delete(rq.cond)
|
|
||||||
model:close()
|
|
||||||
else
|
|
||||||
model:close()
|
|
||||||
return fail("Unknow element to delete")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
ret = model:deleteByID(rq.id)
|
|
||||||
model:close()
|
|
||||||
end
|
|
||||||
if ret then
|
|
||||||
result(ret)
|
|
||||||
else
|
|
||||||
fail("Querry error or database is locked")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
fail("Unknown database request")
|
|
||||||
end
|
|
||||||
end
|
|
@ -151,14 +151,14 @@ function VFSController:publish(...)
|
|||||||
end
|
end
|
||||||
local cond = nil
|
local cond = nil
|
||||||
if rq.publish then
|
if rq.publish then
|
||||||
cond = {exp = {["="] = {path = p}}}
|
cond = {where = {path = p}}
|
||||||
local data = db:find(cond)
|
local data = db:find(cond)
|
||||||
if data == nil or data[0] == nil then
|
if data == nil or data[0] == nil then
|
||||||
-- insert entry
|
-- insert entry
|
||||||
db:insert(entry)
|
db:insert(entry)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
cond = {["="] = {sid = rq.path}}
|
cond = { where = {sid = rq.path}}
|
||||||
db:delete(cond)
|
db:delete(cond)
|
||||||
end
|
end
|
||||||
db:close()
|
db:close()
|
||||||
|
@ -52,10 +52,8 @@ function is_auth()
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
local cond = {
|
local cond = {
|
||||||
exp = {
|
where = {
|
||||||
["="] = {
|
sessionid = sessionid
|
||||||
sessionid = sessionid
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
local data = db:find(cond)
|
local data = db:find(cond)
|
||||||
|
@ -19,7 +19,7 @@ shared.get = function(sharedid)
|
|||||||
i = i+1
|
i = i+1
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local cond = { ["="] = { sid = v.sid } }
|
local cond = { where = { sid = v.sid } }
|
||||||
db:delete(cond)
|
db:delete(cond)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -36,7 +36,7 @@ end
|
|||||||
shared.ospath = function(sharedid)
|
shared.ospath = function(sharedid)
|
||||||
local db = require("dbmodel").get("sysdb", "shared", nil)
|
local db = require("dbmodel").get("sysdb", "shared", nil)
|
||||||
if db == nil then die("Cannot get shared database") end
|
if db == nil then die("Cannot get shared database") end
|
||||||
local cond = { exp = { ["="] = { sid = sharedid } } }
|
local cond = { where = { sid = sharedid } }
|
||||||
local data = db:find(cond)
|
local data = db:find(cond)
|
||||||
db:close()
|
db:close()
|
||||||
if data == nil or data[1] == nil then die("Cannot get shared file with: "..sharedid) end
|
if data == nil or data[1] == nil then die("Cannot get shared file with: "..sharedid) end
|
||||||
|
@ -182,7 +182,7 @@ vfs.checkperm = function(path, right)
|
|||||||
if right == "write" then
|
if right == "write" then
|
||||||
return false, "Shared file is readonly"
|
return false, "Shared file is readonly"
|
||||||
else
|
else
|
||||||
return true
|
return true, vfs.ospath(path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local osfile = vfs.ospath(path)
|
local osfile = vfs.ospath(path)
|
||||||
|
Loading…
Reference in New Issue
Block a user