From e4a0e4408850080e3fad159462352a673fe42469 Mon Sep 17 00:00:00 2001 From: Justin Dhillon Date: Tue, 5 Mar 2024 15:15:37 -0800 Subject: [PATCH] https://example.com/anything doesn't retrun false positive anymore --- checkLink.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/checkLink.ts b/checkLink.ts index 2769a52..b53cc73 100644 --- a/checkLink.ts +++ b/checkLink.ts @@ -2,6 +2,13 @@ const axios = require("axios"); // Return true if link is broken export async function checkLink(link: string): Promise { + const ignoredCodes: Set = new Set([999, 429, 403, 401]); + const ignoredURLs: Set = new Set(['example.com']); + + const url = new URL(link); + if (ignoredURLs.has(url.host)) + return false; + const params: object = { headers: { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8", @@ -17,13 +24,11 @@ export async function checkLink(link: string): Promise { } }; - const falsePositives: Set = new Set([999, 429, 403, 401]); - try { await axios.head(link, params); } catch (err: any) { // If false positive, return false - if (falsePositives.has(err.response.status)) + if (ignoredCodes.has(err.response.status)) return false; // If HEAD is not allowed try GET @@ -32,7 +37,7 @@ export async function checkLink(link: string): Promise { await axios.get(link, params); } catch (error: any) { // If false positive, return false - if (falsePositives.has(err.response.status)) + if (ignoredCodes.has(err.response.status)) return false; return true;