summaryrefslogtreecommitdiff
path: root/src/web/app/common/scripts/api.ls
diff options
context:
space:
mode:
Diffstat (limited to 'src/web/app/common/scripts/api.ls')
-rw-r--r--src/web/app/common/scripts/api.ls51
1 files changed, 0 insertions, 51 deletions
diff --git a/src/web/app/common/scripts/api.ls b/src/web/app/common/scripts/api.ls
deleted file mode 100644
index 47182b6a5a..0000000000
--- a/src/web/app/common/scripts/api.ls
+++ /dev/null
@@ -1,51 +0,0 @@
-riot = require \riot
-
-spinner = null
-pending = 0
-
-net = riot.observable!
-
-riot.mixin \net do
- net: net
-
-module.exports = (i, endpoint, data = {}) ->
- if ++pending == 1
- spinner := document.create-element \div
- ..set-attribute \id \wait
- document.body.append-child spinner
-
- if i? and typeof i == \object then i = i.token
-
- # append user token when signed in
- if i? then data.i = i
-
- opts =
- method: \POST
- body: JSON.stringify data
-
- if endpoint == \signin
- opts.credentials = \include
-
- ep = if (endpoint.index-of '://') > -1
- then endpoint
- else "#{CONFIG.api.url}/#{endpoint}"
-
- new Promise (resolve, reject) ->
- timer = set-timeout ->
- net.trigger \detected-slow-network
- , 5000ms
-
- fetch ep, opts
- .then (res) ->
- clear-timeout timer
- if --pending == 0
- spinner.parent-node.remove-child spinner
-
- if res.status == 200
- res.json!.then resolve
- else if res.status == 204
- resolve!
- else
- res.json!.then (err) ->
- reject err.error
- .catch reject