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 > <afx-hbox >
<div data-id="editor-area"></div> <div data-id="editor-area" id='placeholder'></div>
</afx-hbox> </afx-hbox>
</afx-app-window> </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,22 +4,112 @@
OnlyOffice = class OnlyOffice extends this.OS.application.BaseApplication { OnlyOffice = class OnlyOffice extends this.OS.application.BaseApplication {
constructor(args) { constructor(args) {
super("OnlyOffice", args); super("OnlyOffice", args);
this.eid = `id${Math.random().toString(36).replace(".", "")}`;
} }
main() { main() {
var placeholder; 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"); placeholder = this.find("editor-area");
return this.editor = new DocsAPI.DocEditor(placeholder, { placeholder.id = this.eid;
"document": { if (this.currfile) {
"fileType": "docx", return this.open();
"key": "Khirz6zTPdfd7", }
"title": "Example Document Title.docx", }
"url": "https://file-examples-com.github.io/uploads/2017/02/file-sample_100kB.doc"
}, open() {
"documentType": "word" 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();
},
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() { cleanup() {
if (this.editor) { if (this.editor) {
this.editor.destroyEditor(); this.editor.destroyEditor();
@ -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.OS.register("OnlyOffice", OnlyOffice);
this.extensionParams = {
url: "https://office.iohub.dev/web-apps/"
};
}).call(this); }).call(this);

View File

@ -1,8 +1,8 @@
{ {
"pkgname": "OnlyOffice", "pkgname": "OnlyOffice",
"app":"OnlyOffice", "app":"OnlyOffice",
"name":"OnlyOffice", "name":"Office Suite",
"description":"OnlyOffice", "description":"Online Office suite based on OnlyOffice",
"info":{ "info":{
"author": "", "author": "",
"email": "" "email": ""
@ -10,7 +10,18 @@
"version":"0.0.1-a", "version":"0.0.1-a",
"category":"Other", "category":"Other",
"iconclass":"fa fa-adn", "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":[], "dependencies":[],
"locale": {} "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 > <afx-hbox >
<div data-id="editor-area"></div> <div data-id="editor-area" id='placeholder'></div>
</afx-hbox> </afx-hbox>
</afx-app-window> </afx-app-window>

View File

@ -1,25 +1,87 @@
class OnlyOffice extends this.OS.application.BaseApplication class OnlyOffice extends this.OS.application.BaseApplication
constructor: ( args ) -> constructor: ( args ) ->
super "OnlyOffice", args super "OnlyOffice", args
@eid = "id#{Math.random().toString(36).replace(".","")}"
main: () -> main: () ->
@currfile = undefined
if @args and @args.length > 0
@currfile = @args[0].path.asFileHandle()
placeholder = @find "editor-area" placeholder = @find "editor-area"
@editor = new DocsAPI.DocEditor(placeholder, { placeholder.id = @eid
"document": { @open() if @currfile
"fileType": "docx",
"key": "Khirz6zTPdfd7", open: () ->
"title": "Example Document Title.docx", return unless @currfile
"url": "https://file-examples-com.github.io/uploads/2017/02/file-sample_100kB.doc" console.log @currfile
}, @exec("token", {file: @currfile.path})
"documentType": "word" .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: () -> cleanup: () ->
@editor.destroyEditor() if @editor @editor.destroyEditor() if @editor
@editor = undefined @editor = undefined
OnlyOffice.dependencies = [ 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.OS.register "OnlyOffice", OnlyOffice
this.extensionParams = {
url: "https://office.iohub.dev/web-apps/"
}

View File

@ -1,8 +1,8 @@
{ {
"pkgname": "OnlyOffice", "pkgname": "OnlyOffice",
"app":"OnlyOffice", "app":"OnlyOffice",
"name":"OnlyOffice", "name":"Office Suite",
"description":"OnlyOffice", "description":"Online Office suite based on OnlyOffice",
"info":{ "info":{
"author": "", "author": "",
"email": "" "email": ""
@ -10,7 +10,18 @@
"version":"0.0.1-a", "version":"0.0.1-a",
"category":"Other", "category":"Other",
"iconclass":"fa fa-adn", "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":[], "dependencies":[],
"locale": {} "locale": {}
} }

View File

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