mirror of
https://github.com/lxsang/antos-frontend.git
synced 2024-12-26 17:38:20 +01:00
VFS
This commit is contained in:
parent
c3e5b2749e
commit
a70f52f965
1
Makefile
1
Makefile
@ -7,6 +7,7 @@ NC=\033[0m
|
||||
coffees= src/core/core.coffee\
|
||||
src/core/api.coffee\
|
||||
src/core/handlers/RemoteHandler.coffee\
|
||||
src/core/vfs.coffee\
|
||||
src/core/gui.coffee\
|
||||
src/core/BaseModel.coffee\
|
||||
src/core/BaseApplication.coffee\
|
||||
|
@ -1,4 +1,3 @@
|
||||
self = this
|
||||
class BaseApplication extends this.OS.GUI.BaseModel
|
||||
constructor: (name, args) ->
|
||||
super name, args
|
||||
|
@ -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
|
||||
|
@ -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) ->
|
||||
|
@ -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 "///"
|
||||
String.prototype.asFileHandler = () ->
|
||||
list = this.split ":///"
|
||||
switch list[0]
|
||||
when "app:"
|
||||
return _API.handler.scanapp
|
||||
when "app"
|
||||
return new ApplicationHandler(this)
|
||||
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
|
Loading…
Reference in New Issue
Block a user