2021-02-09 19:41:47 +01:00
|
|
|
local args=...
|
|
|
|
local web = require("web")
|
|
|
|
local vfs = require("vfs")
|
|
|
|
|
|
|
|
if not args then
|
|
|
|
args = REQUEST
|
|
|
|
end
|
|
|
|
|
|
|
|
local result = function(data)
|
|
|
|
return {
|
|
|
|
error = false,
|
|
|
|
result = data
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
local error = function(data)
|
|
|
|
return {
|
|
|
|
error = data,
|
|
|
|
result = false
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
local handle = {}
|
|
|
|
|
|
|
|
handle.token = function()
|
|
|
|
return result("sessionid="..SESSION.sessionid)
|
|
|
|
end
|
|
|
|
|
2021-02-09 23:55:48 +01:00
|
|
|
handle.duplicate = function(data)
|
|
|
|
local file = vfs.ospath(data.as)
|
|
|
|
local tmpfile = "/tmp/"..std.sha1(file)
|
|
|
|
local cmd = "curl -o "..tmpfile..' "'..data.remote..'"'
|
|
|
|
os.execute(cmd)
|
|
|
|
-- move file to correct position
|
|
|
|
if ulib.exists(tmpfile) then
|
|
|
|
cmd = "mv "..tmpfile.." "..file
|
|
|
|
os.execute(cmd)
|
|
|
|
print("File "..file.." is duplicated with remote")
|
|
|
|
else
|
|
|
|
return error("Unable to duplicate file")
|
|
|
|
end
|
|
|
|
return result("File duplicated")
|
|
|
|
end
|
|
|
|
|
2021-02-09 19:41:47 +01:00
|
|
|
handle.save = function()
|
2021-02-09 23:55:48 +01:00
|
|
|
--print(JSON.encode(REQUEST))
|
2021-02-09 19:41:47 +01:00
|
|
|
if not REQUEST.json then
|
|
|
|
return error("Invalid request")
|
|
|
|
end
|
|
|
|
local data = JSON.decodeString(REQUEST.json)
|
|
|
|
if not data then
|
|
|
|
return error("Invalid request")
|
|
|
|
end
|
|
|
|
if not REQUEST.file then
|
|
|
|
return error("No file found")
|
|
|
|
end
|
|
|
|
local file = vfs.ospath(REQUEST.file)
|
|
|
|
if data.status == 2 then
|
2021-02-09 23:55:48 +01:00
|
|
|
local tmpfile = "/tmp/"..std.sha1(file)
|
|
|
|
local cmd = "curl -o "..tmpfile..' "'..data.url..'"'
|
|
|
|
os.execute(cmd)
|
|
|
|
-- move file to correct position
|
|
|
|
if ulib.exists(tmpfile) then
|
|
|
|
cmd = "mv "..tmpfile.." "..file
|
|
|
|
os.execute(cmd)
|
|
|
|
print("File "..file.." sync with remote")
|
|
|
|
else
|
|
|
|
return error("Unable to download")
|
2021-02-09 19:41:47 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return result("OK")
|
|
|
|
end
|
|
|
|
|
2021-02-09 23:55:48 +01:00
|
|
|
--print(JSON.encode(args))
|
2021-02-09 19:41:47 +01:00
|
|
|
|
|
|
|
if args.action and handle[args.action] then
|
|
|
|
return handle[args.action](args.args)
|
|
|
|
else
|
|
|
|
return error("Invalid action parameter")
|
|
|
|
end
|