diff --git a/Makefile b/Makefile index 295c834..b53794f 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/doc/assets/office.css b/doc/assets/office.css new file mode 100644 index 0000000..897a861 --- /dev/null +++ b/doc/assets/office.css @@ -0,0 +1,4 @@ +html, body { + margin: 0; + height: 100%; +} \ No newline at end of file diff --git a/doc/controllers/OfficeController.lua b/doc/controllers/OfficeController.lua new file mode 100644 index 0000000..a030cdd --- /dev/null +++ b/doc/controllers/OfficeController.lua @@ -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 \ No newline at end of file diff --git a/doc/router.lua b/doc/router.lua index ab256b8..c572106 100644 --- a/doc/router.lua +++ b/doc/router.lua @@ -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 diff --git a/doc/views/office/layout.ls b/doc/views/office/layout.ls new file mode 100644 index 0000000..c2ca388 --- /dev/null +++ b/doc/views/office/layout.ls @@ -0,0 +1,67 @@ + + + + + + + + + + <?lua + echo(name) + ?> + + + + +
+ Invalid document ") + end + ?> +
+ + \ No newline at end of file