This commit is contained in:
Xuan Sang LE 2018-01-23 18:16:41 +01:00
parent c3e5b2749e
commit a70f52f965
6 changed files with 111 additions and 21 deletions

View File

@ -7,7 +7,8 @@ NC=\033[0m
coffees= src/core/core.coffee\
src/core/api.coffee\
src/core/handlers/RemoteHandler.coffee\
src/core/gui.coffee\
src/core/vfs.coffee\
src/core/gui.coffee\
src/core/BaseModel.coffee\
src/core/BaseApplication.coffee\
src/core/BaseService.coffee\

View File

@ -1,4 +1,3 @@
self = this
class BaseApplication extends this.OS.GUI.BaseModel
constructor: (name, args) ->
super name, args

View File

@ -2,7 +2,7 @@ self.OS.API =
# the handler object could be a any remote or local handle to
# fetch user data, used by the API to make requests
# handlers are defined in /src/handlers
handler: {}
handler: { }
#request a user data
post: (p, d, c, f) ->
q = _courrier.getMID()

View File

@ -1,10 +1,5 @@
self.OS.GUI =
dialog: new Object()
init: () ->
query =
path: 'VFS/get'
data: "#{_GUI.tagPath}/tags.json"
self.OS.API.request query, ()->
htmlToScheme: (html, app, parent) ->
scheme = $.parseHTML html
($ parent).append scheme

View File

@ -3,6 +3,12 @@ self.OS.API.handler =
path = "lua-api/fs/scandir"
_API.post path, { path: p }, c, (e, s) ->
_courrier.osfail "Fail to scan directory: #{path}", 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
scanapp: (p, c ) ->
path = "lua-api/system/application"
auth: (c) ->

View File

@ -1,15 +1,104 @@
self.OS.API.VFS =
readdir: (p, c, er) ->
h = _API.VFS.pathHandler p
h p,
(d ) -> c d
, (e, s) -> er e, s
String.prototype.hash = () ->
hash = 5381
i = this.length
hash = (hash * 33) ^ this.charCodeAt(--i) while i
hash >>> 0
pathHandler: (p) ->
list = p.split "///"
switch list[0]
when "app:"
return _API.handler.scanapp
else
return _API.handler.scandir
String.prototype.asFileHandler = () ->
list = this.split ":///"
switch list[0]
when "app"
return new ApplicationHandler(this)
else
return new RemoteFileHandler(this)
this.OS.API.VFS = {}
class BasicFileHandler
constructor: (@path) ->
list = @path.split ":///"
@protocol = list[0]
return unless list.length > 1
re = list[1].replace(/^\/+|\/+$/g, '')
return if re is ""
@genealogy = re.split("/")
@basename = @genealogy[@genealogy.length - 1] unless @isRoot()
@ext = @basename.split( "." ).pop() unless @basename.lastIndexOf(".") is 0 or @basename.indexOf( "." ) is -1
@ready = false
isRoot: () -> (not @genealogy) or (@genealogy.size is 0)
isHidden: () ->
return false if not @basename
@basename[0] is "."
hash: () -> @path.hash()
parent: () ->
return @ if @isRoot()
(@protocol + ":///" + (@genealogy.slice 0 , @genealogy.length - 1).join "/").asFileHandler()
onready: (f, e) ->
# read meta data
return f() if @ready
me = @
me.meta (d) ->
return e 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]
me = @
@onready (() -> me[a] f), e
# methods implemented by subclasses used as private methods
meta: (f) ->
read: (f) ->
write: (f) ->
remove: (f) ->
execute: (f) ->
ls: (f) ->
mk: (f) ->
# now export the class
self.OS.API.VFS.BasicFileHandler = BasicFileHandler
# Remote file handle
class RemoteFileHandler extends self.OS.API.VFS.BasicFileHandler
constructor: (path) ->
super path
meta: (f) ->
_API.handler.fileinfo @path, f
ls: (f) ->
return f(@) if @meta.type is "file"
_API.handler.scandir @path, f
self.OS.API.VFS.RemoteFileHandler = RemoteFileHandler
# Application Handler
class ApplicationHandler extends self.OS.API.VFS.BasicFileHandler
constructor: (path) ->
super path
self.OS.API.VFS.ApplicationHandler = ApplicationHandler
# GoogleDrive File Handler
class GoogleDriveHandler extends self.OS.API.VFS.BasicFileHandler
constructor: (path) ->
super path
self.OS.API.VFS.GoogleDriveHandler = GoogleDriveHandler