antos-frontend/src/core/handlers/RemoteHandler.coffee

93 lines
3.4 KiB
CoffeeScript
Raw Normal View History

2018-02-04 23:58:26 +01:00
self.OS.API.HOST = self.location.hostname+ (if self.location.port then":#{self.location.port}" else "")
2018-02-20 16:31:50 +01:00
self.OS.API.REST = "#{self.location.protocol}//#{self.OS.API.HOST}/lua-api/os"
2018-02-02 22:18:33 +01:00
_REST = self.OS.API.REST
2017-08-27 23:40:02 +02:00
self.OS.API.handler =
2018-02-19 16:45:18 +01:00
# get file, require authentification
get: "#{_REST}/fs/get"
# get shared file with publish
shared: "#{_REST}/fs/shared"
2017-08-27 23:40:02 +02:00
scandir: (p, c ) ->
2018-02-02 22:18:33 +01:00
path = "#{_REST}/fs/scandir"
2017-08-27 23:40:02 +02:00
_API.post path, { path: p }, c, (e, s) ->
_courrier.osfail __("Fail to scan directory: {0}", p), e, s
2018-01-24 15:03:33 +01:00
mkdir: (p, c ) ->
2018-02-02 22:18:33 +01:00
path = "#{_REST}/fs/mkdir"
2018-01-24 15:03:33 +01:00
_API.post path, { path: p }, c, (e, s) ->
_courrier.osfail __("Fail to create directory: {0}", p), e, s
2018-02-19 22:11:04 +01:00
sharefile: (p, pub , c) ->
2018-02-19 16:45:18 +01:00
path = "#{_REST}/fs/publish"
2018-02-19 22:11:04 +01:00
_API.post path, { path: p , publish: pub }, c, (e, s) ->
_courrier.osfail __("Fail to publish file: {0}", p), e, s
2018-02-19 22:11:04 +01:00
2018-01-23 18:16:41 +01:00
fileinfo: (p, c) ->
2018-02-02 22:18:33 +01:00
path = "#{_REST}/fs/fileinfo"
2018-01-23 18:16:41 +01:00
_API.post path, { path: p }, c, (e, s) ->
_courrier.osfail __("Fail to get file meta data: {0}", p), e, s
2018-01-24 01:03:14 +01:00
2018-01-31 19:20:42 +01:00
readfile: (p, c, t) ->
2018-02-02 22:18:33 +01:00
path = "#{_REST}/fs/get/"
2018-01-24 01:03:14 +01:00
_API.get path + p, c, (e, s) ->
_courrier.osfail __("Fail to read file: {0}", p), e, s
2018-01-31 19:20:42 +01:00
, t
2018-01-25 19:15:41 +01:00
move: (s, d, c) ->
2018-02-02 22:18:33 +01:00
path = "#{_REST}/fs/move"
2018-01-25 19:15:41 +01:00
_API.post path, { src: s, dest: d }, c, (e, s) ->
_courrier.osfail __("Fail to move file: {0} -> {1}", s, d), e, s
2018-01-25 19:15:41 +01:00
delete: (p , c) ->
2018-02-02 22:18:33 +01:00
path = "#{_REST}/fs/delete"
2018-01-25 19:15:41 +01:00
_API.post path, { path: p }, c, (e, s) ->
_courrier.osfail __("Fail to delete: {0}", p), e, s
2018-01-25 19:15:41 +01:00
fileblob: (p, c) ->
2018-02-02 22:18:33 +01:00
path = "#{_REST}/fs/get/"
2018-01-25 19:15:41 +01:00
_API.blob path + p, c, (e, s) ->
_courrier.osfail "Fail to read file: #{p}", e, s
2018-01-29 19:16:29 +01:00
packages: (d, c) ->
2018-02-02 22:18:33 +01:00
path = "#{_REST}/system/packages"
2018-01-29 19:16:29 +01:00
_API.post path, d, c, (e, s) ->
_courrier.osfail __("Fail to {0} package", d.command), e, s
2018-01-29 19:16:29 +01:00
2018-01-25 19:15:41 +01:00
upload: (d, c) ->
2018-02-02 22:18:33 +01:00
path = "#{_REST}/fs/upload"
2018-01-25 19:15:41 +01:00
_API.upload path, d, c, (e, s) ->
_courrier.osfail __("Fail to upload file to: {0}", d), e, s
2018-01-24 01:03:14 +01:00
2018-01-25 00:49:02 +01:00
write: (p, d , c) ->
2018-02-02 22:18:33 +01:00
path = "#{_REST}/fs/write"
2018-01-25 00:49:02 +01:00
_API.post path, { path: p, data: d }, c, (e, s) ->
_courrier.osfail __("Fail to write to file: {0}", p), e, s
2018-01-25 00:49:02 +01:00
2018-01-23 10:10:40 +01:00
scanapp: (p, c ) ->
2018-02-02 22:18:33 +01:00
path = "#{_REST}/system/application"
2017-08-27 23:40:02 +02:00
auth: (c) ->
2018-02-02 22:18:33 +01:00
p = "#{_REST}/system/auth"
_API.post p, {}, c, (e, s) ->
console.log e, s
alert __("Resource not found: {0}", p)
2017-08-27 23:40:02 +02:00
login: (d, c) ->
2018-02-02 22:18:33 +01:00
p = "#{_REST}/system/login"
2017-08-27 23:40:02 +02:00
_API.post p, d, c, () ->
alert __("Resource not found: {0}", p)
2017-08-27 23:40:02 +02:00
logout: () ->
p = "#{_REST}/system/logout"
_API.post p, {}, (d) ->
_OS.boot()
, () ->
alert __("Resource not found: {0}", p)
2018-02-28 15:40:34 +01:00
setting: (f) ->
2018-02-02 22:18:33 +01:00
p = "#{_REST}/system/settings"
2017-08-27 23:40:02 +02:00
_API.post p, _OS.setting, (d) ->
_courrier.oserror __("Cannot save system setting"), d.error if d.error
2018-02-28 15:40:34 +01:00
f() if f
2017-08-27 23:40:02 +02:00
, (e, s) ->
_courrier.osfail __("Fail to make request: {0}", p), e, s
2018-02-28 15:40:34 +01:00
f() if f
2018-02-05 19:05:41 +01:00
2018-02-27 16:40:36 +01:00
dbquery: (cmd, d, c) ->
2018-02-05 19:05:41 +01:00
path = "#{_REST}/db/#{cmd}"
_API.post path, d, c, (e, s) ->
_courrier.osfail __("Fail to query data from database: {0}", path), e, s