1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2024-12-25 17:08:22 +01:00

add only office to doc

This commit is contained in:
Xuan Sang LE 2021-03-05 17:40:20 +01:00
parent 4f80957ece
commit dcb3803120
5 changed files with 165 additions and 1 deletions

View File

@ -1,5 +1,5 @@
BUILDDIR?=./build
PROJS?=grs info blog os doc ci talk get
PROJS?=grs info blog os doc ci talk get oob
copyfiles = index.ls mimes.json
main: copy
for f in $(PROJS); do BUILDDIR=$(BUILDDIR)/"$${f}" make -C "$${f}" ; done

4
doc/assets/office.css Normal file
View File

@ -0,0 +1,4 @@
html, body {
margin: 0;
height: 100%;
}

View File

@ -0,0 +1,91 @@
BaseController:subclass(
"OfficeController",
{
registry = {},
models = {}
}
)
local docType = function(ext)
if ext == "doc" or ext=="docx" or ext =="odt" then
return "word"
elseif ext == "csv" or ext =="ods" or ext== "xls" or ext == "xlsx" then
return "cell"
elseif ext == "odp" or ext == "ppt" or ext == "pptx" then
return "slide"
else
return "none"
end
end
function OfficeController:index(sid)
-- doing nothing here
require("sqlite")
local ospath = require("shared").ospath(sid)
local ext = ospath:match("^.+%.(.+)$")
local name = ospath:match("^.+/(.+)$")
if(ulib.exists(ospath)) then
local stat = ulib.file_stat(ospath)
if stat.error == nil then
local key = std.sha1(ospath..":"..stat.mtime)
self.template:set("shareid", sid)
self.template:set("ext", ext )
self.template:set("doctype", docType(ext) )
self.template:set("name", name)
self.template:set("key", key)
end
end
self:switchLayout("office")
return true
end
function OfficeController:shared(id)
require("sqlite")
require(BASE_FRW.."shared").get(id)
return false
end
function OfficeController:save(sid)
require("sqlite")
local ospath = require("shared").ospath(sid)
std.json()
local obj = {
error = false,
result = false
}
if not REQUEST.json then
obj.error = "Invalid request"
echo(JSON.encode(obj))
return false
end
local data = JSON.decodeString(REQUEST.json)
if not data then
obj.error = "Invalid request"
echo(JSON.encode(obj))
return false
end
if data.status == 2 then
local tmpfile = "/tmp/"..std.sha1(ospath)
local cmd = "curl -o "..tmpfile..' "'..data.url..'"'
os.execute(cmd)
-- move file to correct position
if ulib.exists(tmpfile) then
cmd = "mv "..tmpfile.." "..ospath
os.execute(cmd)
print("File "..ospath.." sync with remote")
else
obj.error = "Unable to sync file"
echo(JSON.encode(obj))
return false
end
end
obj.result = "OK"
echo(JSON.encode(obj))
return false
end
function OfficeController:actionnotfound(...)
self.template:setView("index")
return self:index(table.unpack({...}))
end

View File

@ -22,6 +22,8 @@ POST_LIMIT = 10
-- require needed library
require(BASE_FRW.."silk.api")
package.path = package.path..";"..__ROOT__.."/os/libs/?.lua"
POLICY.mimes["model/gltf-binary"] = true
if REQUEST.r then

View File

@ -0,0 +1,67 @@
<?lua
local shareid = __main__:get("shareid")
local ext = __main__:get("ext")
local doctype = __main__:get("doctype")
local name = __main__:get("name")
local key = __main__:get("key")
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link
rel="stylesheet"
type="text/css"
href="<?=HTTP_ROOT?>/assets/office.css" />
<!--meta name="viewport" content="width=device-width, initial-scale=1"-->
<script src="https://office.iohub.dev/web-apps/apps/api/documents/api.js"> </script>
<title>
<?lua
echo(name)
?>
</title>
<script type="text/javascript">
<?lua
if shareid and ext and doctype ~= "none" then
?>
window.onload = () => {
const editor = new DocsAPI.DocEditor("container", {
events: {
onAppReady: (e) => () => {},
//onRequestCreateNew: () => @newDocument(),
//onRequestSaveAs: (e) => @saveAs(e)
},
document: {
fileType: '<?=ext?>',
key: '<?=key?>',
title: '<?=name?>',
url: "https://doc.iohub.dev/office/shared/<?=shareid?>"
},
documentType: '<?=doctype?>',
editorConfig: {
//user: {
// id: @systemsetting.user.id.toString(),
// name: @systemsetting.user.username
//},
customization: {
compactHeader: false,
},
callbackUrl:"https://doc.iohub.dev/office/save/<?=shareid?>"
}
});
};
<?lua
end
?>
</script>
</head>
<body>
<div id = "container">
<?lua
if not shareid or not ext or doctype == "none" then
echo("<h1> Invalid document </h1>")
end
?>
</div>
</body>
</html>