diff --git a/src/app/components/ModalPermalink.jsx b/src/app/components/ModalPermalink.jsx index ebc7f518..96d611e6 100644 --- a/src/app/components/ModalPermalink.jsx +++ b/src/app/components/ModalPermalink.jsx @@ -50,6 +50,7 @@ export default class ModalPermalink extends TranslatedComponent {
s.orbis.zone is the new URL shortener domain, old eddp.co urls are considered end of life and could go down at any moment. Sorry for any inconvenience.
; } diff --git a/src/app/utils/ShortenUrl.js b/src/app/utils/ShortenUrl.js index e2f59614..1dc5ff78 100644 --- a/src/app/utils/ShortenUrl.js +++ b/src/app/utils/ShortenUrl.js @@ -8,7 +8,7 @@ import request from 'superagent'; * @param {function} error Failure/Error callback */ export default function shorternUrl(url, success, error) { - shortenUrlEddp(url, success, error); + shortenUrlOrbis(url, success, error); } const SHORTEN_API_GOOGLE = 'https://www.googleapis.com/urlshortener/v1/url?key='; @@ -64,3 +64,32 @@ function shortenUrlEddp(url, success, error) { error('Not Online'); } } + +const SHORTEN_API_ORBIS = 'https://s.orbis.zone/a'; +/** + * Shorten a URL using Orbis's URL shortener API + * @param {string} url The URL to shorten + * @param {function} success Success callback + * @param {function} error Failure/Error callback + */ +function shortenUrlOrbis(url, success, error) { + if (window.navigator.onLine) { + try { + request.post(SHORTEN_API_ORBIS) + .field('lsturl', url) + .field('format', 'json') + .end(function(err, response) { + if (err) { + error('Bad Request'); + } else { + success(response.body.short); + } + }); + } catch (e) { + console.log(e) + error(e.message ? e.message : e); + } + } else { + error('Not Online'); + } +}