mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2024-12-25 11:48:21 +01:00
Let backend generate dockey in Onlyoffice
This commit is contained in:
parent
f04340e174
commit
d39d10d78a
@ -10,5 +10,6 @@ way to work with multiple documents at the same time.
|
|||||||
![https://github.com/lxsang/antosdk-apps/blob/master/OnlyOffice/screenshot.png?raw=true](https://github.com/lxsang/antosdk-apps/blob/master/OnlyOffice/screenshot.png?raw=true)
|
![https://github.com/lxsang/antosdk-apps/blob/master/OnlyOffice/screenshot.png?raw=true](https://github.com/lxsang/antosdk-apps/blob/master/OnlyOffice/screenshot.png?raw=true)
|
||||||
|
|
||||||
## Change log
|
## Change log
|
||||||
- v 0.1.1a: generate document key based on username, file path and modified time
|
- v 0.1.3a: Let backend generates document key, compatible with doc.iohub.dev/office
|
||||||
|
- v 0.1.2a: generate document key based on username, file path and modified time
|
||||||
- v 0.1.1a: generate document key based on username and file path
|
- v 0.1.1a: generate document key based on username and file path
|
||||||
|
@ -22,8 +22,14 @@ end
|
|||||||
|
|
||||||
local handle = {}
|
local handle = {}
|
||||||
|
|
||||||
handle.token = function()
|
handle.token = function(data)
|
||||||
return result("sessionid="..SESSION.sessionid)
|
local file = vfs.ospath(data.file)
|
||||||
|
local stat = ulib.file_stat(file)
|
||||||
|
local ret = {
|
||||||
|
sid = "sessionid="..SESSION.sessionid,
|
||||||
|
key = std.sha1(file..":"..stat.mtime)
|
||||||
|
}
|
||||||
|
return result(ret)
|
||||||
end
|
end
|
||||||
|
|
||||||
handle.duplicate = function(data)
|
handle.duplicate = function(data)
|
||||||
|
@ -10,5 +10,6 @@ way to work with multiple documents at the same time.
|
|||||||
![https://github.com/lxsang/antosdk-apps/blob/master/OnlyOffice/screenshot.png?raw=true](https://github.com/lxsang/antosdk-apps/blob/master/OnlyOffice/screenshot.png?raw=true)
|
![https://github.com/lxsang/antosdk-apps/blob/master/OnlyOffice/screenshot.png?raw=true](https://github.com/lxsang/antosdk-apps/blob/master/OnlyOffice/screenshot.png?raw=true)
|
||||||
|
|
||||||
## Change log
|
## Change log
|
||||||
- v 0.1.1a: generate document key based on username, file path and modified time
|
- v 0.1.3a: Let backend generates document key, compatible with doc.iohub.dev/office
|
||||||
|
- v 0.1.2a: generate document key based on username, file path and modified time
|
||||||
- v 0.1.1a: generate document key based on username and file path
|
- v 0.1.1a: generate document key based on username and file path
|
||||||
|
@ -22,8 +22,14 @@ end
|
|||||||
|
|
||||||
local handle = {}
|
local handle = {}
|
||||||
|
|
||||||
handle.token = function()
|
handle.token = function(data)
|
||||||
return result("sessionid="..SESSION.sessionid)
|
local file = vfs.ospath(data.file)
|
||||||
|
local stat = ulib.file_stat(file)
|
||||||
|
local ret = {
|
||||||
|
sid = "sessionid="..SESSION.sessionid,
|
||||||
|
key = std.sha1(file..":"..stat.mtime)
|
||||||
|
}
|
||||||
|
return result(ret)
|
||||||
end
|
end
|
||||||
|
|
||||||
handle.duplicate = function(data)
|
handle.duplicate = function(data)
|
||||||
|
@ -1 +1 @@
|
|||||||
(function(){var e;(e=class extends this.OS.application.BaseApplication{constructor(e){super("OnlyOffice",e),this.eid="id"+Math.random().toString(36).replace(".","")}main(){if(this.currfile=void 0,this.args&&this.args.length>0&&(this.currfile=this.args[0].path.asFileHandle()),this.placeholder=this.find("editor-area"),this.placeholder.id=this.eid,this.find("btn-open-file").onbtclick=e=>this.openFile(),this.find("btn-new-doc").onbtclick=e=>this.create("word"),this.find("btn-new-cell").onbtclick=e=>this.create("sheet"),this.find("btn-new-slide").onbtclick=e=>this.create("slide"),this.currfile)return this.open()}create(e){var t;return t=void 0,"word"===e&&(t="docx"),"sheet"===e&&(t="xlsx"),"slide"===e&&(t="pptx"),t?this.openDialog("FileDialog",{title:__("Save file as"),type:"dir",file:("home://Untitled."+t).asFileHandle()}).then(e=>{var i,s;return i=`${e.file.path}/${e.name}`.asFileHandle(),(s=`${this.path()}/templates/model.${t}`.asFileHandle()).read("binary").then(e=>{var t;return t=new Blob([e],{type:s.info.mime}),i.cache=t,i.write(s.info.mime).then(e=>(i.cache=void 0,this.currfile=i,this.open())).catch(e=>this.error(e.toString(),e))}).catch(e=>this.error(e.toString(),e))}):this.error(__("Unkown file type"))}openFile(){return this.openDialog("FileDialog",{title:__("Open file"),type:"file",mimes:this.meta().mimes}).then((e,t)=>(this.currfile=e.file.path.asFileHandle(),this.open()))}editorReady(){return console.log($('iframe[name="frameEditor"]',this.scheme).contents())}open(){if(this.currfile)return this.exec("token",{file:this.currfile.path}).then(e=>e.error?this.error(e.error):(this.access_token=e.result,this.currfile.onready().then(e=>{var t;return t=(t=`${this.systemsetting.user.username}:${this.currfile.path}:${e.mtime}`).hash().toString(),this.scheme.apptitle=this.currfile.path,$(this.placeholder).empty(),this.editor&&this.editor.destroyEditor(),this.editor=new DocsAPI.DocEditor(this.eid,{events:{onAppReady:e=>this.editorReady(e),onRequestCreateNew:()=>this.newDocument(),onRequestSaveAs:e=>this.saveAs(e)},document:{fileType:this.currfile.ext,key:t,title:this.currfile.filename,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:!1},callbackUrl:this.uapi("save")}})}))).catch(e=>this.error(e.toString(),e))}getDocType(e){return"doc,docx,epub,odt".split(",").includes(e)?"word":"csv,ods,xls,xlsx".split(",").includes(e)?"cell":"odp,ppt,pptx".split(",").includes(e)?"slide":"none"}saveAs(e){if(e.data.url)return e.data.url.asFileHandle(),this.openDialog("FileDialog",{title:__("Save file as"),type:"dir",file:("home://"+e.data.title).asFileHandle()}).then(t=>{var i;return i=`${t.file.path}/${t.name}`,this.exec("duplicate",{remote:e.data.url,as:i}).then(e=>e.error?this.error(e.error):"none"!==this.getDocType(i.asFileHandle().ext)?(this.currfile=i.asFileHandle(),this.open()):void 0).catch(e=>this.error(e.toString(),e))})}newDocument(){return this.openDialog("SelectionDialog",{title:__("Create new"),data:[{text:__("Open a file"),iconclass:"fa fa-folder-open",type:"open"},{text:__("Document"),iconclass:"fa fa-file-word-o",type:"word"},{text:__("Spreadsheet"),iconclass:"fa fa-file-excel-o",type:"sheet"},{text:__("Presentation"),iconclass:"fa fa-file-powerpoint-o",type:"slide"}]}).then(e=>{switch(e.type){case"open":return this.openFile();default:return this.create(e.type)}})}uapi(e){return`${this._api.REST}/system/apigateway?ws=0&path=${this.path()}/api.lua&action=${e}&file=${this.currfile.path}&${this.access_token}`}exec(e,t){var i;return i={path:this.path()+"/api.lua",parameters:{action:e,args:t}},this.call(i)}cleanup(){return this.editor&&this.editor.destroyEditor(),this.editor=void 0}}).dependencies=["https://office.iohub.dev/web-apps/apps/api/documents/api.js"],this.OS.register("OnlyOffice",e),this.extensionParams={url:"https://office.iohub.dev/web-apps/"}}).call(this);
|
(function(){var e;(e=class extends this.OS.application.BaseApplication{constructor(e){super("OnlyOffice",e),this.eid="id"+Math.random().toString(36).replace(".","")}main(){if(this.currfile=void 0,this.args&&this.args.length>0&&(this.currfile=this.args[0].path.asFileHandle()),this.placeholder=this.find("editor-area"),this.placeholder.id=this.eid,this.find("btn-open-file").onbtclick=e=>this.openFile(),this.find("btn-new-doc").onbtclick=e=>this.create("word"),this.find("btn-new-cell").onbtclick=e=>this.create("sheet"),this.find("btn-new-slide").onbtclick=e=>this.create("slide"),this.currfile)return this.open()}create(e){var t;return t=void 0,"word"===e&&(t="docx"),"sheet"===e&&(t="xlsx"),"slide"===e&&(t="pptx"),t?this.openDialog("FileDialog",{title:__("Save file as"),type:"dir",file:("home://Untitled."+t).asFileHandle()}).then(e=>{var i,s;return i=`${e.file.path}/${e.name}`.asFileHandle(),(s=`${this.path()}/templates/model.${t}`.asFileHandle()).read("binary").then(e=>{var t;return t=new Blob([e],{type:s.info.mime}),i.cache=t,i.write(s.info.mime).then(e=>(i.cache=void 0,this.currfile=i,this.open())).catch(e=>this.error(e.toString(),e))}).catch(e=>this.error(e.toString(),e))}):this.error(__("Unkown file type"))}openFile(){return this.openDialog("FileDialog",{title:__("Open file"),type:"file",mimes:this.meta().mimes}).then((e,t)=>(this.currfile=e.file.path.asFileHandle(),this.open()))}editorReady(){return console.log($('iframe[name="frameEditor"]',this.scheme).contents())}open(){if(this.currfile)return this.exec("token",{file:this.currfile.path}).then(e=>(console.log(e),e.error?this.error(e.error):(this.access_token=e.result.sid,this.currfile.onready().then(t=>(this.scheme.apptitle=this.currfile.path,$(this.placeholder).empty(),this.editor&&this.editor.destroyEditor(),this.editor=new DocsAPI.DocEditor(this.eid,{events:{onAppReady:e=>this.editorReady(e),onRequestCreateNew:()=>this.newDocument(),onRequestSaveAs:e=>this.saveAs(e)},document:{fileType:this.currfile.ext,key:e.result.key,title:this.currfile.filename,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:!1},callbackUrl:this.uapi("save")}})))))).catch(e=>this.error(e.toString(),e))}getDocType(e){return"doc,docx,epub,odt".split(",").includes(e)?"word":"csv,ods,xls,xlsx".split(",").includes(e)?"cell":"odp,ppt,pptx".split(",").includes(e)?"slide":"none"}saveAs(e){if(e.data.url)return e.data.url.asFileHandle(),this.openDialog("FileDialog",{title:__("Save file as"),type:"dir",file:("home://"+e.data.title).asFileHandle()}).then(t=>{var i;return i=`${t.file.path}/${t.name}`,this.exec("duplicate",{remote:e.data.url,as:i}).then(e=>e.error?this.error(e.error):"none"!==this.getDocType(i.asFileHandle().ext)?(this.currfile=i.asFileHandle(),this.open()):void 0).catch(e=>this.error(e.toString(),e))})}newDocument(){return this.openDialog("SelectionDialog",{title:__("Create new"),data:[{text:__("Open a file"),iconclass:"fa fa-folder-open",type:"open"},{text:__("Document"),iconclass:"fa fa-file-word-o",type:"word"},{text:__("Spreadsheet"),iconclass:"fa fa-file-excel-o",type:"sheet"},{text:__("Presentation"),iconclass:"fa fa-file-powerpoint-o",type:"slide"}]}).then(e=>{switch(e.type){case"open":return this.openFile();default:return this.create(e.type)}})}uapi(e){return`${this._api.REST}/system/apigateway?ws=0&path=${this.path()}/api.lua&action=${e}&file=${this.currfile.path}&${this.access_token}`}exec(e,t){var i;return i={path:this.path()+"/api.lua",parameters:{action:e,args:t}},this.call(i)}cleanup(){return this.editor&&this.editor.destroyEditor(),this.editor=void 0}}).dependencies=["https://office.iohub.dev/web-apps/apps/api/documents/api.js"],this.OS.register("OnlyOffice",e),this.extensionParams={url:"https://office.iohub.dev/web-apps/"}}).call(this);
|
@ -7,7 +7,7 @@
|
|||||||
"author": "Xuan Sang LE",
|
"author": "Xuan Sang LE",
|
||||||
"email": "mrsang@iohub.dev"
|
"email": "mrsang@iohub.dev"
|
||||||
},
|
},
|
||||||
"version":"0.1.2-a",
|
"version":"0.1.3-a",
|
||||||
"category":"Other",
|
"category":"Other",
|
||||||
"icon":"icon.png",
|
"icon":"icon.png",
|
||||||
"mimes":[
|
"mimes":[
|
||||||
|
Binary file not shown.
@ -75,12 +75,13 @@ class OnlyOffice extends this.OS.application.BaseApplication
|
|||||||
return unless @currfile
|
return unless @currfile
|
||||||
@exec("token", {file: @currfile.path})
|
@exec("token", {file: @currfile.path})
|
||||||
.then (d) =>
|
.then (d) =>
|
||||||
|
console.log(d)
|
||||||
return @error d.error if d.error
|
return @error d.error if d.error
|
||||||
@access_token = d.result
|
@access_token = d.result.sid
|
||||||
@currfile.onready()
|
@currfile.onready()
|
||||||
.then (meta) =>
|
.then (meta) =>
|
||||||
key = "#{@systemsetting.user.username}:#{@currfile.path}:#{meta.mtime}"
|
#key = "#{@systemsetting.user.username}:#{@currfile.path}:#{meta.mtime}"
|
||||||
key = key.hash().toString()
|
#key = key.hash().toString()
|
||||||
@scheme.apptitle = @currfile.path
|
@scheme.apptitle = @currfile.path
|
||||||
$(@placeholder).empty()
|
$(@placeholder).empty()
|
||||||
@editor.destroyEditor() if @editor
|
@editor.destroyEditor() if @editor
|
||||||
@ -92,7 +93,7 @@ class OnlyOffice extends this.OS.application.BaseApplication
|
|||||||
},
|
},
|
||||||
document: {
|
document: {
|
||||||
fileType: @currfile.ext,
|
fileType: @currfile.ext,
|
||||||
key: key,
|
key: d.result.key,
|
||||||
title: @currfile.filename,
|
title: @currfile.filename,
|
||||||
url: @currfile.getlink() + "?" + @access_token
|
url: @currfile.getlink() + "?" + @access_token
|
||||||
},
|
},
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
"author": "Xuan Sang LE",
|
"author": "Xuan Sang LE",
|
||||||
"email": "mrsang@iohub.dev"
|
"email": "mrsang@iohub.dev"
|
||||||
},
|
},
|
||||||
"version":"0.1.2-a",
|
"version":"0.1.3-a",
|
||||||
"category":"Other",
|
"category":"Other",
|
||||||
"icon":"icon.png",
|
"icon":"icon.png",
|
||||||
"mimes":[
|
"mimes":[
|
||||||
|
@ -155,7 +155,7 @@
|
|||||||
"description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/OnlyOffice/README.md",
|
"description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/OnlyOffice/README.md",
|
||||||
"category": "Other",
|
"category": "Other",
|
||||||
"author": "Xuan Sang LE",
|
"author": "Xuan Sang LE",
|
||||||
"version": "0.1.2-a",
|
"version": "0.1.3-a",
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/OnlyOffice/build/release/OnlyOffice.zip"
|
"download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/OnlyOffice/build/release/OnlyOffice.zip"
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user