VFS(cont)

This commit is contained in:
Xuan Sang LE 2018-01-24 01:03:14 +01:00
parent a70f52f965
commit dfbeb16601
6 changed files with 34 additions and 19 deletions

View File

@ -70,6 +70,8 @@ class BaseModel
fail: (m) ->
@publish "fail", m
throwe: () ->
@_api.throwe @name
find: (id) -> ($ "[data-id='#{id}']", @scheme)[0] if @scheme

View File

@ -55,3 +55,12 @@ self.OS.API =
path = "resources/#{r}"
_API.get path, c, f
throwe: (n) ->
err = undefined
try
throw new Error(n)
catch e
err = e
return "" if not err
return err.stack

View File

@ -2,12 +2,17 @@ self.OS.API.handler =
scandir: (p, c ) ->
path = "lua-api/fs/scandir"
_API.post path, { path: p }, c, (e, s) ->
_courrier.osfail "Fail to scan directory: #{path}", e, s
_courrier.osfail "Fail to scan directory: #{p}", e, s
fileinfo: (p, c) ->
path = "lua-api/fs/fileinfo"
_API.post path, { path: p }, c, (e, s) ->
_courrier.osfail "Fail to get file metadata: #{path}", e, s
_courrier.osfail "Fail to get file metadata: #{p}", e, s
readfile: (p, c) ->
path = "lua-api/fs/get/"
_API.get path + p, c, (e, s) ->
_courrier.osfail "Fail to read file: #{p}",e , s
scanapp: (p, c ) ->
path = "lua-api/system/application"

View File

@ -39,21 +39,21 @@ class BasicFileHandler
return @ if @isRoot()
(@protocol + ":///" + (@genealogy.slice 0 , @genealogy.length - 1).join "/").asFileHandler()
onready: (f, e) ->
onready: (f) ->
# read meta data
return f() if @ready
me = @
me.meta (d) ->
return e d.error if d.error
return _courrier.osfail d.error, (_API.throwe "OS.VFS"), d.error if d.error
me.meta = d.result
me.ready = true
f()
#public interface for all action on file
do: (a, f, e) ->
return e "Action #{a} not found" if not @[a]
do: (a, f) ->
return _courrier.osfail "VFS unknown action: #{a}", (_API.throwe "OS.VFS"), a if not @[a]
me = @
@onready (() -> me[a] f), e
@onready (() -> me[a] f)
# methods implemented by subclasses used as private methods
@ -67,8 +67,6 @@ class BasicFileHandler
execute: (f) ->
ls: (f) ->
mk: (f) ->
# now export the class
@ -82,9 +80,10 @@ class RemoteFileHandler extends self.OS.API.VFS.BasicFileHandler
meta: (f) ->
_API.handler.fileinfo @path, f
ls: (f) ->
return f(@) if @meta.type is "file"
_API.handler.scandir @path, f
read: (f) ->
return _API.handler.scandir @path, f if @meta.type is "dir"
#read the file
_API.handler.readfile @path, f
self.OS.API.VFS.RemoteFileHandler = RemoteFileHandler

View File

@ -55,7 +55,7 @@ class PushNotification extends this.OS.GUI.BaseService
pushout: (s, o, mfeed) ->
d = {
text: "[#{s}] #{o.name} (#{o.id}): #{o.data.m}",
text: "[#{s}] #{o.name} (#{o.id}): #{o.data.m} : #{o.data.e}",
icon: o.data.icon,
iconclass: o.data.iconclass,
closable: true }