adapt the system with the new api

This commit is contained in:
lxsang
2020-05-10 21:39:42 +02:00
parent ae54c9a10c
commit f5e5d8501b
24 changed files with 1120 additions and 952 deletions

View File

@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
#along with this program. If not, see https://www.gnu.org/licenses/.
Ant.OS.API.HOST = Ant.location.hostname+ (if Ant.location.port then":#{Ant.location.port}" else "")
Ant.OS.API.HOST = Ant.location.hostname + (if Ant.location.port then":#{Ant.location.port}" else "")
Ant.OS.API.REST = "#{Ant.location.protocol}//#{Ant.OS.API.HOST}"
Ant.OS.API.handle =
@ -23,101 +23,80 @@ Ant.OS.API.handle =
get: "#{Ant.OS.API.REST}/VFS/get"
# get shared file with publish
shared: "#{Ant.OS.API.REST}/VFS/shared"
scandir: (p, c ) ->
scandir: (p) ->
path = "#{Ant.OS.API.REST}/VFS/scandir"
Ant.OS.API.post path, { path: p }, c, (e, s) ->
Ant.OS.announcer.osfail __("Fail to scan directory: {0}", p), e, s
mkdir: (p, c ) ->
Ant.OS.API.post path, { path: p }
mkdir: (p) ->
path = "#{Ant.OS.API.REST}/VFS/mkdir"
Ant.OS.API.post path, { path: p }, c, (e, s) ->
Ant.OS.announcer.osfail __("Fail to create directory: {0}", p), e, s
sharefile: (p, pub , c) ->
Ant.OS.API.post path, { path: p }
sharefile: (p, pub) ->
path = "#{Ant.OS.API.REST}/VFS/publish"
Ant.OS.API.post path, { path: p , publish: pub }, c, (e, s) ->
Ant.OS.announcer.osfail __("Fail to publish file: {0}", p), e, s
Ant.OS.API.post path, { path: p , publish: pub }
fileinfo: (p, c) ->
fileinfo: (p) ->
path = "#{Ant.OS.API.REST}/VFS/fileinfo"
Ant.OS.API.post path, { path: p }, c, (e, s) ->
Ant.OS.announcer.osfail __("Fail to get file meta data: {0}", p), e, s
Ant.OS.API.post path, { path: p }
readfile: (p, c, t) ->
readfile: (p, t) ->
path = "#{Ant.OS.API.REST}/VFS/get/"
Ant.OS.API.get path + p, c, (e, s) ->
Ant.OS.announcer.osfail __("Fail to read file: {0}", p), e, s
, t
Ant.OS.API.get path + p, t
move: (s, d, c) ->
move: (s, d) ->
path = "#{Ant.OS.API.REST}/VFS/move"
Ant.OS.API.post path, { src: s, dest: d }, c, (e, s) ->
Ant.OS.announcer.osfail __("Fail to move file: {0} -> {1}", s, d), e, s
Ant.OS.API.post path, { src: s, dest: d }
delete: (p , c) ->
delete: (p) ->
path = "#{Ant.OS.API.REST}/VFS/delete"
Ant.OS.API.post path, { path: p }, c, (e, s) ->
Ant.OS.announcer.osfail __("Fail to delete: {0}", p), e, s
Ant.OS.API.post path, { path: p }
fileblob: (p, c) ->
fileblob: (p) ->
path = "#{Ant.OS.API.REST}/VFS/get/"
Ant.OS.API.blob path + p, c, (e, s) ->
Ant.OS.announcer.osfail "Fail to read file: #{p}", e, s
Ant.OS.API.blob path + p
packages: (d, c) ->
packages: (d) ->
path = "#{Ant.OS.API.REST}/system/packages"
Ant.OS.API.post path, d, c, (e, s) ->
Ant.OS.announcer.osfail __("Fail to {0} package", d.command), e, s
Ant.OS.API.post path, d
upload: (d, c) ->
upload: (d) ->
path = "#{Ant.OS.API.REST}/VFS/upload"
Ant.OS.API.upload path, d, c, (e, s) ->
Ant.OS.announcer.osfail __("Fail to upload file to: {0}", d), e, s
Ant.OS.API.upload path, d
write: (p, d , c) ->
write: (p, d) ->
path = "#{Ant.OS.API.REST}/VFS/write"
Ant.OS.API.post path, { path: p, data: d }, c, (e, s) ->
Ant.OS.announcer.osfail __("Fail to write to file: {0}", p), e, s
Ant.OS.API.post path, { path: p, data: d }
scanapp: (p, c ) ->
path = "#{Ant.OS.API.REST}/system/application"
apigateway: (d, ws, c) ->
apigateway: (d, ws) ->
if ws
path = "#{Ant.OS.API.HOST}/system/apigateway?ws=1"
proto = if window.location.protocol is "https:" then "wss://" else "ws://"
socket = new WebSocket proto + path
if c then c(socket)
return socket
new Promise (resolve, reject) ->
path = "#{Ant.OS.API.HOST}/system/apigateway?ws=1"
proto = if window.location.protocol is "https:" then "wss://" else "ws://"
socket = new WebSocket proto + path
resolve(socket)
else
path = "#{Ant.OS.API.REST}/system/apigateway?ws=0"
Ant.OS.API.post path, d, c, (e, s) ->
Ant.OS.announcer.osfail __("Fail to invoke gateway api"), e, s
Ant.OS.API.post path, d
auth: (c) ->
auth: () ->
p = "#{Ant.OS.API.REST}/user/auth"
Ant.OS.API.post p, {}, c, (e, s) ->
console.log e, s
alert __("Resource not found: {0}", p)
login: (d, c) ->
Ant.OS.API.post p, {}
login: (d) ->
p = "#{Ant.OS.API.REST}/user/login"
Ant.OS.API.post p, d, c, () ->
alert __("Resource not found: {0}", p)
Ant.OS.API.post p, d
logout: () ->
p = "#{Ant.OS.API.REST}/user/logout"
Ant.OS.API.post p, {}, (d) ->
Ant.OS.boot()
, () ->
alert __("Resource not found: {0}", p)
setting: (f) ->
Ant.OS.API.post p, {}
setting: () ->
p = "#{Ant.OS.API.REST}/system/settings"
Ant.OS.API.post p, Ant.OS.setting, (d) ->
Ant.OS.announcer.oserror __("Cannot save system setting"), d.error if d.error
f(d) if f
, (e, s) ->
m = __("Fail to make request: {0}", p)
Ant.OS.announcer.osfail m , e, s
f({ error: m }) if f
Ant.OS.API.post p, Ant.OS.setting
dbquery: (cmd, d, c) ->
dbquery: (cmd, d) ->
path = "#{Ant.OS.API.REST}/VDB/#{cmd}"
Ant.OS.API.post path, d, c, (e, s) ->
Ant.OS.announcer.osfail __("Fail to query data from database: {0}", path), e, s
Ant.OS.API.post path, d