From 93e103b73a90aa8a4fa6f1e44ba4afe50e47fc9a Mon Sep 17 00:00:00 2001 From: Nelson/Roberto Date: Tue, 25 Jan 2022 10:47:39 -0500 Subject: [PATCH 1/2] Added BASE_DOMAIN as .env variable Allows user to more easily use workflow with custom domain. --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index a9b4205..0e9113b 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ const p = require('phin'); const target = process.argv[process.argv.length - 1]; const key = process.env.API_KEY; +const baseDomain = process.env.BASE_DOMAIN || "https://kutt.it"; if (!key) { return console.log('Please set an API key first.'); @@ -17,7 +18,7 @@ function getErrorMessage(message) { (async function() { try { const { body = {} } = await p({ - url: 'https://kutt.it/api/url/submit', + url: `${baseDomain}/api/url/submit`, method: 'POST', data: { target }, core: { From cfee5d03dddc550fb3fe0f456db46a05dfdf006f Mon Sep 17 00:00:00 2001 From: Nelson/Roberto Date: Thu, 7 Apr 2022 09:39:05 -0400 Subject: [PATCH 2/2] Updated workflow to use APIv2 - Also added support for multiple domains by passing a `env.domain` variable. --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 0e9113b..2a22a8c 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,8 @@ const p = require('phin'); const target = process.argv[process.argv.length - 1]; +const domain = process.env.domain; + const key = process.env.API_KEY; const baseDomain = process.env.BASE_DOMAIN || "https://kutt.it"; @@ -18,7 +20,7 @@ function getErrorMessage(message) { (async function() { try { const { body = {} } = await p({ - url: `${baseDomain}/api/url/submit`, + url: `${baseDomain}/api/v2/links`, method: 'POST', data: { target }, core: { @@ -29,7 +31,7 @@ function getErrorMessage(message) { }, parse: 'json' }); - const message = body.shortUrl || getErrorMessage(body.error) + const message = body.link || getErrorMessage(body.error) console.log(message) } catch (error) { console.log(error.message);