more WIP for orbis

This commit is contained in:
willyb321
2018-07-28 11:36:44 +10:00
parent 3d9d6397f6
commit de1cb901fc
9 changed files with 190 additions and 104 deletions

View File

@@ -1,5 +1,6 @@
import request from 'superagent';
const agent = request.agent();
/**
* Shorten a URL
@@ -95,29 +96,46 @@ function orbisShorten(url, success, error) {
}
const API_ORBIS = 'http://localhost:3000/builds/add';
const API_ORBIS_LOGIN = 'http://localhost:3000/login';
/**
* Upload to Orbis
* @param {object} ship The URL to shorten
* @param {function} success Success callback
* @param {function} error Failure/Error callback
* @param {object} creds Orbis credentials
* @return {Promise<any>} Either a URL or error message.
*/
export function orbisUpload(ship, success, error) {
if (window.navigator.onLine) {
try {
request.post(API_ORBIS)
.send(ship)
.end(function(err, response) {
if (err) {
error('Bad Request');
} else {
success(response.body.link);
}
});
} catch (e) {
console.log(e);
error(e.message ? e.message : e);
export function orbisUpload(ship, creds) {
return new Promise(async (resolve, reject) => {
if (window.navigator.onLine) {
try {
agent
.post(API_ORBIS_LOGIN)
.send(creds)
.withCredentials()
.end(function(err) {
if (err) {
reject('Bad Request');
} else {
agent
.post(API_ORBIS)
.withCredentials()
.set('Content-Type', 'application/json')
.send(ship)
.end(function(err, response) {
if (err) {
reject('Bad Request');
} else {
resolve(response.body.link);
}
});
}
});
} catch (e) {
console.log(e);
reject(e.message ? e.message : e);
}
} else {
reject('Not Online');
}
} else {
error('Not Online');
}
});
}