Skip to content

Commit

Permalink
fix lamba function URI encoding issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaphasilor committed Aug 2, 2021
1 parent 7a345ce commit 4ddf004
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions public/netlify-functions/checkLinkAlive.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,20 @@ const fetchTimeout = (url, ms, options = {}) => {
return promise.finally(() => clearTimeout(timeout));
};

function encodeUriOnce(url, useURIComponent = false) {

let decoder = useURIComponent ? decodeURIComponent : decodeURI
while(url !== decoder(url)) {
url = decoder(url);
}

return encodeURI(url);

}

function resolveLink(url) {

let resolvedUrl = url;
let resolvedUrl = encodeUriOnce(url);
let resolvedHeaders = {};

if (url.includes(`driveindex.ga/`)) {
Expand All @@ -48,7 +59,7 @@ function checkLink(urlData) {
return new Promise((resolve) => {

const startTime = performance.now()
urlData.url = encodeURI(urlData.url);
urlData.url = encodeUriOnce(urlData.url);

fetchTimeout(urlData.url, REQUEST_TIMEOUT, {
method: `HEAD`,
Expand Down

0 comments on commit 4ddf004

Please sign in to comment.