diff --git a/ChangeLog.md b/ChangeLog.md index 2429a876..d25c19f2 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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 diff --git a/src/app/utils/ShortenUrl.js b/src/app/utils/ShortenUrl.js index e1db8eb3..f11efaa8 100644 --- a/src/app/utils/ShortenUrl.js +++ b/src/app/utils/ShortenUrl.js @@ -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'); + } +}