From 5bc87d11c884a8be5849d60ae17dd5e3621246ca Mon Sep 17 00:00:00 2001 From: zane-programs Date: Fri, 21 Jan 2022 12:07:51 -0800 Subject: [PATCH 1/2] add URL shortener --- public/js/compose.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/public/js/compose.js b/public/js/compose.js index 8d5c9b6..ae5ac63 100644 --- a/public/js/compose.js +++ b/public/js/compose.js @@ -39,7 +39,7 @@ return urlBase.concat('?message=',message,'&from=',from,'&graph=',graphName); }; - //this is called once we have a short url from the google url-shortener + //this is called once we have a short url from the TinyURL var shareCallback = function(shareLink){ $shareLink.val(shareLink); var tweetUrl = "https://twitter.com/intent/tweet?text=" @@ -52,11 +52,12 @@ showShare(); }; - //TODO: hook up a new link shortener! var share = function(){ $body.addClass('is-loading'); var longUrl = getLongUrl(); - shareCallback(longUrl); + + // shorten longUrl using TinyURL API + $.get("https://tinyurl.com/api-create.php?url=" + encodeURIComponent(longUrl)).done(shareCallback); }; //this is the code that interacts with the graphpaper From ac60220436b81645382cd763ecd0d03ccbe664a9 Mon Sep 17 00:00:00 2001 From: zane-programs Date: Fri, 21 Jan 2022 12:39:28 -0800 Subject: [PATCH 2/2] error handling for tinyurl api --- public/js/compose.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/public/js/compose.js b/public/js/compose.js index ae5ac63..a02b04b 100644 --- a/public/js/compose.js +++ b/public/js/compose.js @@ -57,7 +57,12 @@ var longUrl = getLongUrl(); // shorten longUrl using TinyURL API - $.get("https://tinyurl.com/api-create.php?url=" + encodeURIComponent(longUrl)).done(shareCallback); + $.get("https://tinyurl.com/api-create.php?url=" + encodeURIComponent(longUrl)) + .done(shareCallback) + .fail(function () { + // share longUrl if TinyURL API call fails + shareCallback(longUrl); + }); }; //this is the code that interacts with the graphpaper