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,6 +7,7 @@ NC=\033[0m
coffees= src/core/core.coffee\ coffees= src/core/core.coffee\
src/core/api.coffee\ src/core/api.coffee\
src/core/handlers/RemoteHandler.coffee\ src/core/handlers/RemoteHandler.coffee\
src/core/vfs.coffee\
src/core/gui.coffee\ src/core/gui.coffee\
src/core/BaseModel.coffee\ src/core/BaseModel.coffee\
src/core/BaseApplication.coffee\ src/core/BaseApplication.coffee\

View File

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

View File

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

View File

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

View File

@ -1,15 +1,104 @@
self.OS.API.VFS = String.prototype.hash = () ->
readdir: (p, c, er) -> hash = 5381
h = _API.VFS.pathHandler p i = this.length
h p, hash = (hash * 33) ^ this.charCodeAt(--i) while i
(d ) -> c d hash >>> 0
, (e, s) -> er e, s
pathHandler: (p) -> String.prototype.asFileHandler = () ->
list = p.split "///" list = this.split ":///"
switch list[0] switch list[0]
when "app:" when "app"
return _API.handler.scanapp return new ApplicationHandler(this)
else else
return _API.handler.scandir 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