mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2025-07-13 14:14:27 +02:00
make it online
This commit is contained in:
59
OnlyOffice/build/debug/api.lua
Normal file
59
OnlyOffice/build/debug/api.lua
Normal 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
|
@ -4,22 +4,112 @@
|
||||
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"
|
||||
},
|
||||
"documentType": "word"
|
||||
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();
|
||||
},
|
||||
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() {
|
||||
if (this.editor) {
|
||||
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.extensionParams = {
|
||||
url: "https://office.iohub.dev/web-apps/"
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
@ -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": {}
|
||||
}
|
@ -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>
|
Reference in New Issue
Block a user