1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2025-04-19 01:56:44 +02:00

Compare commits

...

2 Commits

Author SHA1 Message Date
DanyLE
fd31477739 Support URLsafe base 64 encoding in API gateway 2022-08-19 20:01:05 +02:00
DanyLE
6d3ee13d87 update base64 handling 2022-08-19 16:40:25 +02:00

View File

@ -132,10 +132,12 @@ function SystemController:apigateway(...)
r, e = loadfile(ospath)
if r then
local status, result = pcall(r, data.parameters)
if (status) then
echo(JSON.encode(result))
else
echo(result)
if result then
if (status) then
echo(JSON.encode(result))
else
echo(result)
end
end
else
echo(e)
@ -192,7 +194,14 @@ function SystemController:apigateway(...)
data = JSON.decodeString(REQUEST.json)
exec_with_user_priv(data)
elseif args and #args > 0 then
local decoded = std.b64decode(args[1])
-- data is encoded in url safe base64
local encoded = args[1]:gsub('_', '/'):gsub('-', '+')
if #encoded % 4 == 2 then
encoded = encoded.."=="
elseif #encoded %4 == 3 then
encoded = encoded.."="
end
local decoded = std.b64decode(encoded)
data = JSON.decodeString(bytes.__tostring(decoded))
if data and data.path then
exec_with_user_priv(data)