make it online

This commit is contained in:
lxsang 2021-02-09 19:41:47 +01:00
parent 5f90daf079
commit 46d271ad90
9 changed files with 327 additions and 31 deletions

59
OnlyOffice/api/api.lua Normal file
View File

@ -0,0 +1,59 @@
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
handle.save = function()
print(JSON.encode(REQUEST))
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
print("download to"..file)
if not web.download(data.url, file) then
print("Unable to download")
return error("Unable to save file")
end
end
return result("OK")
end
print(JSON.encode(args))
if args.action and handle[args.action] then
return handle[args.action](args.args)
else
return error("Invalid action parameter")
end

View File

@ -1,5 +1,5 @@
<afx-app-window apptitle="OnlyOffice" width="500" height="400" data-id="OnlyOffice">
<afx-app-window apptitle="Office Suite" width="700" height="500" data-id="OnlyOffice">
<afx-hbox >
<div data-id="editor-area"></div>
<div data-id="editor-area" id='placeholder'></div>
</afx-hbox>
</afx-app-window>

View File

@ -0,0 +1,59 @@
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
handle.save = function()
print(JSON.encode(REQUEST))
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
print("download to"..file)
if not web.download(data.url, file) then
print("Unable to download")
return error("Unable to save file")
end
end
return result("OK")
end
print(JSON.encode(args))
if args.action and handle[args.action] then
return handle[args.action](args.args)
else
return error("Invalid action parameter")
end

View File

@ -4,20 +4,110 @@
OnlyOffice = class OnlyOffice extends this.OS.application.BaseApplication {
constructor(args) {
super("OnlyOffice", args);
this.eid = `id${Math.random().toString(36).replace(".", "")}`;
}
main() {
var placeholder;
this.currfile = void 0;
if (this.args && this.args.length > 0) {
this.currfile = this.args[0].path.asFileHandle();
}
placeholder = this.find("editor-area");
return this.editor = new DocsAPI.DocEditor(placeholder, {
"document": {
"fileType": "docx",
"key": "Khirz6zTPdfd7",
"title": "Example Document Title.docx",
"url": "https://file-examples-com.github.io/uploads/2017/02/file-sample_100kB.doc"
placeholder.id = this.eid;
if (this.currfile) {
return this.open();
}
}
open() {
if (!this.currfile) {
return;
}
console.log(this.currfile);
return this.exec("token", {
file: this.currfile.path
}).then((d) => {
if (d.error) {
return this.error(d.error);
}
this.access_token = d.result;
return this.currfile.onready().then((meta) => {
if (this.editor) {
//@scheme.apptitle = @currfile.path
this.editor.destroyEditor();
}
return this.editor = new DocsAPI.DocEditor(this.eid, {
events: {
onRequestCreateNew: () => {
return this.newDocument();
},
"documentType": "word"
onRequestSaveAs: (e) => {
return console.log(e);
}
},
document: {
fileType: this.currfile.ext,
key: meta.mtime.hash().toString(),
title: this.currfile.path,
url: this.currfile.getlink() + "?" + this.access_token
},
documentType: this.getDocType(this.currfile.ext),
editorConfig: {
user: {
id: this.systemsetting.user.id.toString(),
name: this.systemsetting.user.username
},
customization: {
compactHeader: false
},
//autosave: false,
//forcesave: true
callbackUrl: this.uapi("save")
}
});
});
}).catch((e) => {
return this.error(e.toString(), e);
});
}
getDocType(ext) {
if ("doc,docx,epub,odt".split(",").includes(ext)) {
return "word";
}
if ("csv,ods,xls,xlsx".split(",").includes(ext)) {
return "cell";
}
if ("odp,ppt,pptx".split(",").includes(ext)) {
return "slide";
}
return "none";
}
saveAs(e) {
return console.log(e);
}
newDocument() {
console.log("create document");
return this.error(__("Unable to create document"));
}
uapi(action) {
return `${this._api.REST}/system/apigateway?ws=0&path=${this.path()}/api.lua&action=${action}&file=${this.currfile.path}&${this.access_token}`;
}
exec(action, args) {
var cmd;
cmd = {
path: `${this.path()}/api.lua`,
parameters: {
action: action,
args: args
}
};
return this.call(cmd);
}
cleanup() {
@ -29,8 +119,12 @@
};
OnlyOffice.dependencies = ["http://192.168.1.91/web-apps/apps/api/documents/api.js"];
OnlyOffice.dependencies = ["https://office.iohub.dev/web-apps/apps/api/documents/api.js"];
this.OS.register("OnlyOffice", OnlyOffice);
this.extensionParams = {
url: "https://office.iohub.dev/web-apps/"
};
}).call(this);

View File

@ -1,8 +1,8 @@
{
"pkgname": "OnlyOffice",
"app":"OnlyOffice",
"name":"OnlyOffice",
"description":"OnlyOffice",
"name":"Office Suite",
"description":"Online Office suite based on OnlyOffice",
"info":{
"author": "",
"email": ""
@ -10,7 +10,18 @@
"version":"0.0.1-a",
"category":"Other",
"iconclass":"fa fa-adn",
"mimes":["none"],
"mimes":[
"application/vnd.oasis.opendocument.text",
"application/vnd.oasis.opendocument.spreadsheet",
"application/vnd.oasis.opendocument.presentation",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/msword",
"application/vnd.ms-excel",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"application/vnd.ms-powerpoint",
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
"application/epub+zip"
],
"dependencies":[],
"locale": {}
}

View File

@ -1,5 +1,5 @@
<afx-app-window apptitle="OnlyOffice" width="500" height="400" data-id="OnlyOffice">
<afx-app-window apptitle="Office Suite" width="700" height="500" data-id="OnlyOffice">
<afx-hbox >
<div data-id="editor-area"></div>
<div data-id="editor-area" id='placeholder'></div>
</afx-hbox>
</afx-app-window>

View File

@ -1,25 +1,87 @@
class OnlyOffice extends this.OS.application.BaseApplication
constructor: ( args ) ->
super "OnlyOffice", args
@eid = "id#{Math.random().toString(36).replace(".","")}"
main: () ->
@currfile = undefined
if @args and @args.length > 0
@currfile = @args[0].path.asFileHandle()
placeholder = @find "editor-area"
@editor = new DocsAPI.DocEditor(placeholder, {
"document": {
"fileType": "docx",
"key": "Khirz6zTPdfd7",
"title": "Example Document Title.docx",
"url": "https://file-examples-com.github.io/uploads/2017/02/file-sample_100kB.doc"
},
"documentType": "word"
});
placeholder.id = @eid
@open() if @currfile
open: () ->
return unless @currfile
console.log @currfile
@exec("token", {file: @currfile.path})
.then (d) =>
return @error d.error if d.error
@access_token = d.result
@currfile.onready()
.then (meta) =>
#@scheme.apptitle = @currfile.path
@editor.destroyEditor() if @editor
@editor = new DocsAPI.DocEditor(@eid, {
events: {
onRequestCreateNew: () => @newDocument(),
onRequestSaveAs: (e) => console.log e
},
document: {
fileType: @currfile.ext,
key: meta.mtime.hash().toString(),
title: @currfile.path,
url: @currfile.getlink() + "?" + @access_token
},
documentType: @getDocType(@currfile.ext),
editorConfig: {
user: {
id: @systemsetting.user.id.toString(),
name: @systemsetting.user.username
},
customization: {
compactHeader: false,
#autosave: false,
#forcesave: true
},
callbackUrl: @uapi("save")
}
});
.catch (e) =>
@error e.toString(), e
getDocType: (ext) ->
return "word" if "doc,docx,epub,odt".split(",").includes(ext)
return "cell" if "csv,ods,xls,xlsx".split(",").includes(ext)
return "slide" if "odp,ppt,pptx".split(",").includes(ext)
return "none"
saveAs: (e) ->
console.log e
newDocument: () ->
console.log("create document")
@error __("Unable to create document")
uapi: (action) ->
return "#{@_api.REST}/system/apigateway?ws=0&path=#{@path()}/api.lua&action=#{action}&file=#{@currfile.path}&#{@access_token}"
exec: (action, args) ->
cmd =
path: "#{@path()}/api.lua",
parameters:
action: action,
args: args
return @call(cmd)
cleanup: () ->
@editor.destroyEditor() if @editor
@editor = undefined
OnlyOffice.dependencies = [
"http://192.168.1.91/web-apps/apps/api/documents/api.js"
"https://office.iohub.dev/web-apps/apps/api/documents/api.js"
]
this.OS.register "OnlyOffice", OnlyOffice
this.extensionParams = {
url: "https://office.iohub.dev/web-apps/"
}

View File

@ -1,8 +1,8 @@
{
"pkgname": "OnlyOffice",
"app":"OnlyOffice",
"name":"OnlyOffice",
"description":"OnlyOffice",
"name":"Office Suite",
"description":"Online Office suite based on OnlyOffice",
"info":{
"author": "",
"email": ""
@ -10,7 +10,18 @@
"version":"0.0.1-a",
"category":"Other",
"iconclass":"fa fa-adn",
"mimes":["none"],
"mimes":[
"application/vnd.oasis.opendocument.text",
"application/vnd.oasis.opendocument.spreadsheet",
"application/vnd.oasis.opendocument.presentation",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/msword",
"application/vnd.ms-excel",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"application/vnd.ms-powerpoint",
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
"application/epub+zip"
],
"dependencies":[],
"locale": {}
}

View File

@ -3,5 +3,5 @@
"css": [],
"javascripts": [],
"coffees": ["coffees/main.coffee"],
"copies": ["assets/scheme.html", "package.json", "README.md"]
"copies": ["api/api.lua", "assets/scheme.html", "package.json", "README.md"]
}