Use own URL shortener

This commit is contained in:
Cmdr McDonald
2016-12-24 21:57:11 +00:00
parent 091789c819
commit 5f036c586c
2 changed files with 36 additions and 3 deletions

View File

@@ -20,6 +20,8 @@
* Add module copy functionality - drag module whilst holding 'alt' to copy
* Add base resistances to defence summary tooltip
* Update shield recovery/regeneration calculations
* Pin menu to top of page
* Switch to custom shortlink method to avoid google length limitations
#2.2.5
* Calculate rate of fire for multi-burst weapons

View File

@@ -1,17 +1,21 @@
import request from 'superagent';
const SHORTEN_API = 'https://www.googleapis.com/urlshortener/v1/url?key=';
export default function shorternUrl(url, success, error) {
shortenUrlEddp(url, success, error);
}
const SHORTEN_API_GOOGLE = 'https://www.googleapis.com/urlshortener/v1/url?key=';
/**
* Shorten a URL using Google's URL shortener API
* @param {string} url The URL to shorten
* @param {function} success Success callback
* @param {function} error Failure/Error callback
*/
export default function shortenUrl(url, success, error) {
function shortenUrlGoogle(url, success, error) {
if (window.navigator.onLine) {
try {
request.post(SHORTEN_API + window.CORIOLIS_GAPI_KEY)
request.post(SHORTEN_API_GOOGLE + window.CORIOLIS_GAPI_KEY)
.send({ longUrl: url })
.end(function(err, response) {
if (err) {
@@ -27,3 +31,30 @@ export default function shortenUrl(url, success, error) {
error('Not Online');
}
}
const SHORTEN_API_EDDP = 'http://eddp.co/u';
/**
* Shorten a URL using EDDP's URL shortener API
* @param {string} url The URL to shorten
* @param {function} success Success callback
* @param {function} error Failure/Error callback
*/
function shortenUrlEddp(url, success, error) {
if (window.navigator.onLine) {
try {
request.post(SHORTEN_API_EDDP)
.send(url)
.end(function(err, response) {
if (err) {
error('Bad Request');
} else {
success(response.header['location']);
}
});
} catch (e) {
error(e.message ? e.message : e);
}
} else {
error('Not Online');
}
}