shared file enable

This commit is contained in:
Xuan Sang LE 2018-02-19 16:45:18 +01:00
parent 564df6c815
commit e50cdc3620
6 changed files with 82 additions and 10 deletions

View File

@ -332,6 +332,7 @@ self.OS.GUI =
{ text: "Home", path: 'home:///', iconclass: "fa fa-home", type: "fs" },
{ text: "OS", path: 'os:///', iconclass: "fa fa-inbox", type: "fs" },
{ text: "Desktop", path: _OS.setting.desktop.path , iconclass: "fa fa-desktop", type: "fs" },
{ text: "Shared", path: 'shared:///' , iconclass: "fa fa-share-square", type: "fs" }
] if not _OS.setting.VFS.mountpoints
_OS.setting.system = conf.system if conf.system

View File

@ -3,7 +3,10 @@ self.OS.API.REST = "#{self.location.protocol}//#{self.OS.API.HOST}/lua-api"
_REST = self.OS.API.REST
self.OS.API.handler =
get: "#{_REST}/fs/get/"
# get file, require authentification
get: "#{_REST}/fs/get"
# get shared file with publish
shared: "#{_REST}/fs/shared"
scandir: (p, c ) ->
path = "#{_REST}/fs/scandir"
_API.post path, { path: p }, c, (e, s) ->
@ -12,7 +15,10 @@ self.OS.API.handler =
path = "#{_REST}/fs/mkdir"
_API.post path, { path: p }, c, (e, s) ->
_courrier.osfail "Fail to create directory: #{p}", e, s
sharefile: (p, c) ->
path = "#{_REST}/fs/publish"
_API.post path, { path: p }, c, (e, s) ->
_courrier.osfail "Fail to publish file: #{p}", e, s
fileinfo: (p, c) ->
path = "#{_REST}/fs/fileinfo"
_API.post path, { path: p }, c, (e, s) ->

View File

@ -90,7 +90,11 @@ class BaseFileHandler
@onready (() -> me.action "upload", null, (r) ->
_courrier.ostrigger "VFS", { m: "upload", file: me } if r.result
f r)
publish: (f) ->
me = @
@onready (() -> me.action "publish", null, (r) ->
_courrier.ostrigger "VFS", { m: "publish", file: me } if r.result
f r)
download: (f) ->
me = @
@onready (() -> me.action "download", null, f)
@ -142,6 +146,8 @@ class RemoteFileHandler extends self.OS.API.VFS.BaseFileHandler
_API.handler.upload @path, f
when "remove"
_API.handler.delete @path, f
when "publish"
_API.handler.sharefile @path, f
when "download"
return if @info.type is "dir"
_API.handler.fileblob @path, (d) ->
@ -152,7 +158,7 @@ class RemoteFileHandler extends self.OS.API.VFS.BaseFileHandler
else
return _courrier.osfail "VFS unknown action: #{n}", (_API.throwe "OS.VFS"), n
self.OS.API.VFS.register "^(home|shared|desktop|os|Untitled)$", RemoteFileHandler
self.OS.API.VFS.register "^(home|desktop|os|Untitled)$", RemoteFileHandler
# Application Handler
class ApplicationHandler extends self.OS.API.VFS.BaseFileHandler
@ -185,7 +191,8 @@ class ApplicationHandler extends self.OS.API.VFS.BaseFileHandler
when "remove"
#uninstall
return
when "publish"
return
when "download"
return
@ -233,7 +240,8 @@ class BlobFileHandler extends self.OS.API.VFS.BaseFileHandler
when "remove"
#uninstall
return
when "publish"
return
when "download"
blob = new Blob [@cache], { type: "octet/stream" }
_API.saveblob me.basename, blob
@ -244,3 +252,44 @@ class BlobFileHandler extends self.OS.API.VFS.BaseFileHandler
return _courrier.osfail "VFS unknown action: #{n}", (_API.throwe "OS.VFS"), n
self.OS.API.VFS.register "^blob$", BlobFileHandler
class SharedFileHandler extends self.OS.API.VFS.BaseFileHandler
constructor: (path) ->
super path
@ready = true if @isRoot()
meta: (f) ->
_API.handler.fileinfo @path, f
action: (n, p, f) ->
me = @
switch n
when "read"
return _API.get "#{_API.handler.shared}/all", f, ((e, s)->) if @isRoot()
#read the file
_API.handler.readfile @path, f, if p then p else "text"
when "mk"
return
when "write"
_API.handler.write @path, p, f
when "remove"
_API.handler.delete @path, f
when "upload"
return
when "publish"
return f { result: @basename }
when "download"
return if @info.type is "dir"
_API.handler.fileblob @path, (d) ->
blob = new Blob [d], { type: "octet/stream" }
_API.saveblob me.basename, blob
when "move"
return
else
return _courrier.osfail "VFS unknown action: #{n}", (_API.throwe "OS.VFS"), n
self.OS.API.VFS.register "^shared$", SharedFileHandler

View File

@ -131,8 +131,10 @@ class Blogger extends this.OS.GUI.BaseApplication
className: "fa fa-file-image-o",
action: (e) ->
me.openDialog "FileDiaLog", (d, n) ->
"#{d}/#{n}".asFileHandler().publish (r) ->
return me.error "Cannot export file for embeding to text" if r.error
doc = me.editor.codemirror.getDoc()
doc.replaceSelection "![](#{me._api.handler.get}/#{d}/#{n})"
doc.replaceSelection "![](#{me._api.handler.shared}/#{r.result})"
, "Select image file", { mimes: ["image/.*"] }
},
"|",

View File

@ -21,6 +21,9 @@ afx-list-view[data-id = "notifylist"] li{
border:1px solid #a6a6a6;
border-radius: 6px;
margin-bottom: 2px;
-ms-word-break: break-all;
word-break: break-all;
word-break: break-word;
}
afx-overlay[data-id = "feedzone"]{
@ -42,4 +45,7 @@ afx-list-view[data-id = "notifeed"] li{
border-radius: 6px;
margin-bottom: 2px;
z-index: 99999;
-ms-word-break: break-all;
word-break: break-all;
word-break: break-word;
}

View File

@ -80,7 +80,7 @@ class Files extends this.OS.GUI.BaseApplication
dir.read (d) ->
if(d.error)
return me.error "Resource not found #{p}"
console.log "error"
me.currdir = dir
if not dir.isRoot()
p = dir.parent().asFileHandler()
@ -103,6 +103,7 @@ class Files extends this.OS.GUI.BaseApplication
{ text: "Open with", dataid: "#{@name}-open", child:@apps },
{ text: "Upload", dataid: "#{@name}-upload" },
{ text: "Download", dataid: "#{@name}-download" },
{ text: "Share file", dataid: "#{@name}-share" },
{ text: "Properties", dataid: "#{@name}-info" }
], onmenuselect: (e) -> me.actionFile e
}
@ -251,6 +252,13 @@ class Files extends this.OS.GUI.BaseApplication
@currdir.upload (r) ->
me.error "Faile to upload to: #{d}: #{r.error}" if r.error
when "#{@name}-share"
me = @
return unless file and file.type is "file"
file.path.asFileHandler().publish (r) ->
return me.error "Cannot share file: #{r.error}" if r.error
return me.notify "Shared url: #{r.result}"
when "#{@name}-download"
return unless file
file.path.asFileHandler().download ()->