mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-09 22:55:35 +00:00
more WIP for orbis
This commit is contained in:
@@ -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');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user