mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2024-11-08 06:28:29 +01:00
Update LibreOffice and OnlyOffice to latests backend API
This commit is contained in:
parent
a2a602f5b2
commit
9afa2f5d1c
@ -9,6 +9,9 @@ It support a wide range of documents.
|
||||
![https://github.com/lxsang/antosdk-apps/blob/master/LibreOffice/libreoffice.png?raw=true](https://github.com/lxsang/antosdk-apps/blob/master/LibreOffice/libreoffice.png?raw=true)
|
||||
|
||||
## Change log
|
||||
- v 0.1.4-a:
|
||||
* Update backend script to latest API changes
|
||||
* use luasocket + luasec to fetch LibreOffice service discovery
|
||||
- v 0.1.3-a:
|
||||
* Minor fix to support AntOS v2.0.x
|
||||
- v 0.1.2-a:
|
||||
|
@ -6,7 +6,6 @@ if not args then
|
||||
args = REQUEST
|
||||
end
|
||||
local vfs = require("vfs")
|
||||
local DLCMD="wget --no-check-certificate -O"
|
||||
local handle = {}
|
||||
--local logger = Logger:new{ levels = {INFO = true, ERROR = true, DEBUG = false}}
|
||||
local result = function(data)
|
||||
@ -17,12 +16,22 @@ local error = function(msg)
|
||||
return {error = msg, result = false}
|
||||
end
|
||||
|
||||
local fetch = function(url)
|
||||
local https = require('ssl.https')
|
||||
local body, code, headers = https.request(url)
|
||||
if code~=200 then
|
||||
LOG_ERROR("Error: ".. (code or '') )
|
||||
return nil
|
||||
end
|
||||
return body
|
||||
end
|
||||
|
||||
handle.token = function(data)
|
||||
local file = vfs.ospath(data.file)
|
||||
local stat = ulib.file_stat(file)
|
||||
local ret = {
|
||||
sid = "access_token="..SESSION.sessionid,
|
||||
key = std.sha1(file..":"..stat.mtime)
|
||||
key = enc.sha1(file..":"..stat.mtime)
|
||||
}
|
||||
return result(ret)
|
||||
end
|
||||
@ -43,14 +52,9 @@ handle.duplicate = function(data)
|
||||
end
|
||||
|
||||
handle.discover = function(data)
|
||||
local tmpfile = "/tmp/libreoffice_discover.xml"
|
||||
local cmd = DLCMD.." "..tmpfile..' '..data.uri
|
||||
os.execute(cmd)
|
||||
content = fetch(url)
|
||||
-- move file to correct position
|
||||
if ulib.exists(tmpfile) then
|
||||
local f = assert(io.open(tmpfile, "rb"))
|
||||
local content = f:read("*all")
|
||||
f:close()
|
||||
if content then
|
||||
return result(content)
|
||||
else
|
||||
return error("Unable to discover data")
|
||||
@ -74,7 +78,7 @@ handle.file = function(data)
|
||||
elseif REQUEST.method == "POST" then
|
||||
--local clen = tonumber(HEADER['Content-Length'])
|
||||
local barr = REQUEST["application/octet-stream"]
|
||||
bytes.write(barr, path)
|
||||
barr:fileout(path)
|
||||
return result(true)
|
||||
else
|
||||
return error("Unknown request method")
|
||||
|
@ -9,6 +9,9 @@ It support a wide range of documents.
|
||||
![https://github.com/lxsang/antosdk-apps/blob/master/LibreOffice/libreoffice.png?raw=true](https://github.com/lxsang/antosdk-apps/blob/master/LibreOffice/libreoffice.png?raw=true)
|
||||
|
||||
## Change log
|
||||
- v 0.1.4-a:
|
||||
* Update backend script to latest API changes
|
||||
* use luasocket + luasec to fetch LibreOffice service discovery
|
||||
- v 0.1.3-a:
|
||||
* Minor fix to support AntOS v2.0.x
|
||||
- v 0.1.2-a:
|
||||
|
@ -6,7 +6,6 @@ if not args then
|
||||
args = REQUEST
|
||||
end
|
||||
local vfs = require("vfs")
|
||||
local DLCMD="wget --no-check-certificate -O"
|
||||
local handle = {}
|
||||
--local logger = Logger:new{ levels = {INFO = true, ERROR = true, DEBUG = false}}
|
||||
local result = function(data)
|
||||
@ -17,12 +16,22 @@ local error = function(msg)
|
||||
return {error = msg, result = false}
|
||||
end
|
||||
|
||||
local fetch = function(url)
|
||||
local https = require('ssl.https')
|
||||
local body, code, headers = https.request(url)
|
||||
if code~=200 then
|
||||
LOG_ERROR("Error: ".. (code or '') )
|
||||
return nil
|
||||
end
|
||||
return body
|
||||
end
|
||||
|
||||
handle.token = function(data)
|
||||
local file = vfs.ospath(data.file)
|
||||
local stat = ulib.file_stat(file)
|
||||
local ret = {
|
||||
sid = "access_token="..SESSION.sessionid,
|
||||
key = std.sha1(file..":"..stat.mtime)
|
||||
key = enc.sha1(file..":"..stat.mtime)
|
||||
}
|
||||
return result(ret)
|
||||
end
|
||||
@ -43,14 +52,9 @@ handle.duplicate = function(data)
|
||||
end
|
||||
|
||||
handle.discover = function(data)
|
||||
local tmpfile = "/tmp/libreoffice_discover.xml"
|
||||
local cmd = DLCMD.." "..tmpfile..' '..data.uri
|
||||
os.execute(cmd)
|
||||
content = fetch(url)
|
||||
-- move file to correct position
|
||||
if ulib.exists(tmpfile) then
|
||||
local f = assert(io.open(tmpfile, "rb"))
|
||||
local content = f:read("*all")
|
||||
f:close()
|
||||
if content then
|
||||
return result(content)
|
||||
else
|
||||
return error("Unable to discover data")
|
||||
@ -74,7 +78,7 @@ handle.file = function(data)
|
||||
elseif REQUEST.method == "POST" then
|
||||
--local clen = tonumber(HEADER['Content-Length'])
|
||||
local barr = REQUEST["application/octet-stream"]
|
||||
bytes.write(barr, path)
|
||||
barr:fileout(path)
|
||||
return result(true)
|
||||
else
|
||||
return error("Unknown request method")
|
||||
|
@ -7,7 +7,7 @@
|
||||
"author": "Dany LE",
|
||||
"email": "contact@iohub.dev"
|
||||
},
|
||||
"version":"0.1.3-a",
|
||||
"version":"0.1.4-a",
|
||||
"category":"Office",
|
||||
"icon":"icon.png",
|
||||
"mimes":[
|
||||
|
Binary file not shown.
@ -7,7 +7,7 @@
|
||||
"author": "Dany LE",
|
||||
"email": "contact@iohub.dev"
|
||||
},
|
||||
"version":"0.1.3-a",
|
||||
"version":"0.1.4-a",
|
||||
"category":"Office",
|
||||
"icon":"icon.png",
|
||||
"mimes":[
|
||||
|
@ -10,6 +10,7 @@ way to work with multiple documents at the same time.
|
||||
![https://github.com/lxsang/antosdk-apps/blob/master/OnlyOffice/screenshot.png?raw=true](https://github.com/lxsang/antosdk-apps/blob/master/OnlyOffice/screenshot.png?raw=true)
|
||||
|
||||
## Change log
|
||||
- v 0.1.8a: Use new backend API + luasec + luasocket to manipulate remote file
|
||||
- v 0.1.7a: Allow setting blur overlay on window
|
||||
- v 0.1.6a: Update backend api
|
||||
- v 0.1.5a: Add document versionning support
|
||||
|
@ -1,7 +1,6 @@
|
||||
local args=...
|
||||
local vfs = require("vfs")
|
||||
|
||||
local DLCMD="wget --no-check-certificate -O"
|
||||
if not args then
|
||||
args = REQUEST
|
||||
end
|
||||
@ -20,6 +19,25 @@ local error = function(data)
|
||||
}
|
||||
end
|
||||
|
||||
local download_file = function(src, dest)
|
||||
local https = require('ssl.https')
|
||||
local ltn12 = require("ltn12")
|
||||
local file = io.open(dest, "w")
|
||||
if not file then
|
||||
LOG_ERROR("Unable to open file %s to write", dest)
|
||||
return false
|
||||
end
|
||||
local body, code, headers = https.request{
|
||||
url = src,
|
||||
sink = ltn12.sink.file(file)
|
||||
}
|
||||
if code~=200 then
|
||||
LOG_ERROR("Error: ".. (code or '') )
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local handle = {}
|
||||
|
||||
handle.token = function(data)
|
||||
@ -27,17 +45,17 @@ handle.token = function(data)
|
||||
local stat = ulib.file_stat(file)
|
||||
local ret = {
|
||||
sid = "sessionid="..SESSION.sessionid,
|
||||
key = std.sha1(file..":"..stat.mtime)
|
||||
key = enc.sha1(file..":"..stat.mtime)
|
||||
}
|
||||
return result(ret)
|
||||
end
|
||||
|
||||
handle.history = function(data)
|
||||
local file = vfs.ospath(data.file)
|
||||
local history_file = vfs.ospath("home://.office/"..std.sha1(file).."/history.json")
|
||||
local history_file = vfs.ospath("home://.office/"..enc.sha1(file).."/history.json")
|
||||
if(ulib.exists(history_file)) then
|
||||
local obj = JSON.decodeFile(history_file)
|
||||
obj.hash = std.sha1(file)
|
||||
obj.hash = enc.sha1(file)
|
||||
return result(obj)
|
||||
else
|
||||
return error("No history found")
|
||||
@ -64,7 +82,7 @@ end
|
||||
handle.restore = function(data)
|
||||
local version = data.version
|
||||
local file = vfs.ospath(data.file)
|
||||
local basepath = vfs.ospath("home://.office/"..std.sha1(file))
|
||||
local basepath = vfs.ospath("home://.office/"..enc.sha1(file))
|
||||
if ulib.exists(basepath.."/history.json") then
|
||||
local history = JSON.decodeFile(basepath.."/history.json")
|
||||
local obj = handle.clean_up_version(basepath, history,version)
|
||||
@ -95,22 +113,14 @@ handle.restore = function(data)
|
||||
end
|
||||
handle.duplicate = function(data)
|
||||
local file = vfs.ospath(data.as)
|
||||
local tmpfile = "/tmp/"..std.sha1(file)
|
||||
local cmd = DLCMD.." "..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
|
||||
download_file(data.remote, file)
|
||||
if not ulib.exists(file) then
|
||||
return error("Unable to duplicate file")
|
||||
end
|
||||
return result("File duplicated")
|
||||
end
|
||||
|
||||
handle.save = function()
|
||||
--print(JSON.encode(REQUEST))
|
||||
if not REQUEST.json then
|
||||
return error("Invalid request")
|
||||
end
|
||||
@ -123,31 +133,31 @@ handle.save = function()
|
||||
end
|
||||
local file = vfs.ospath(REQUEST.file)
|
||||
if data.status == 2 then
|
||||
local tmpfile = "/tmp/"..std.sha1(file)
|
||||
local cmd = DLCMD.." "..tmpfile..' "'..data.url..'"'
|
||||
os.execute(cmd)
|
||||
local tmpfile = "/tmp/"..enc.sha1(file)
|
||||
download_file(data.url, tmpfile)
|
||||
-- move file to correct position
|
||||
if ulib.exists(tmpfile) then
|
||||
LOG_INFO("Remote file saved to %s", tmpfile)
|
||||
-- back up the file version
|
||||
local history_dir = "home://.office"
|
||||
vfs.mkdir(history_dir)
|
||||
history_dir = history_dir.."/"..std.sha1(file)
|
||||
history_dir = history_dir.."/"..enc.sha1(file)
|
||||
vfs.mkdir(history_dir)
|
||||
history_dir = vfs.ospath(history_dir)
|
||||
-- backup old version
|
||||
cmd = 'cp "'..file..'" "'..history_dir.."/"..data.key..'"'
|
||||
os.execute(cmd)
|
||||
ulib.send_file(file,history_dir.."/"..data.key)
|
||||
LOG_INFO("Backup file saved to %s", history_dir.."/"..data.key)
|
||||
-- create new version
|
||||
local old_stat = ulib.file_stat(file)
|
||||
cmd = 'mv "'..tmpfile..'" "'..file..'"'
|
||||
os.execute(cmd)
|
||||
if not ulib.move(tmpfile, file) then
|
||||
ulib.send_file(tmpfile, file)
|
||||
end
|
||||
-- get the new key
|
||||
local stat = ulib.file_stat(file)
|
||||
local new_key = std.sha1(file..":"..stat.mtime)
|
||||
local new_key = enc.sha1(file..":"..stat.mtime)
|
||||
-- save changes
|
||||
if(data.changesurl) then
|
||||
cmd = DLCMD.." "..history_dir.."/"..new_key..'.zip "'..data.changesurl..'"'
|
||||
os.execute(cmd)
|
||||
download_file(data.changesurl, history_dir.."/"..new_key..'.zip')
|
||||
end
|
||||
-- now save version object
|
||||
local history_file = history_dir.."/history.json"
|
||||
@ -177,7 +187,7 @@ handle.save = function()
|
||||
else
|
||||
return error("Cannot save history")
|
||||
end
|
||||
print("File "..file.." sync with remote")
|
||||
LOG_INFO("File "..file.." sync with remote")
|
||||
else
|
||||
return error("Unable to download")
|
||||
end
|
||||
|
Binary file not shown.
@ -7,7 +7,7 @@
|
||||
"author": "Xuan Sang LE",
|
||||
"email": "mrsang@iohub.dev"
|
||||
},
|
||||
"version":"0.1.7-a",
|
||||
"version":"0.1.8-a",
|
||||
"category":"Office",
|
||||
"icon":"icon.png",
|
||||
"mimes":[
|
||||
|
@ -275,7 +275,7 @@
|
||||
"description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/2.0.x/LibreOffice/README.md",
|
||||
"category": "Office",
|
||||
"author": "Dany LE",
|
||||
"version": "0.1.3-a",
|
||||
"version": "0.1.4-a",
|
||||
"dependencies": [],
|
||||
"download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/2.0.x/LibreOffice/build/release/LibreOffice.zip"
|
||||
},
|
||||
@ -335,7 +335,7 @@
|
||||
"description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/2.0.x/OnlyOffice/README.md",
|
||||
"category": "Office",
|
||||
"author": "Xuan Sang LE",
|
||||
"version": "0.1.7-a",
|
||||
"version": "0.1.8-a",
|
||||
"dependencies": [],
|
||||
"download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/2.0.x/OnlyOffice/build/release/OnlyOffice.zip"
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user