From 3f5a9c58c7ad5f0f6376f85b71b0c86b90593db5 Mon Sep 17 00:00:00 2001 From: devStorm <59678453+developStorm@users.noreply.github.com> Date: Sun, 17 Nov 2024 22:36:48 -0800 Subject: [PATCH] fix: short link expansion --- utils/sanitizer.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/utils/sanitizer.ts b/utils/sanitizer.ts index 34993d7..9c51ad5 100644 --- a/utils/sanitizer.ts +++ b/utils/sanitizer.ts @@ -96,7 +96,11 @@ export async function sanitizeURL(originalURL: string) { continue; } } - } catch {} + } catch (e) { + if (process.env.NODE_ENV === "development") { + console.error("Exception during URL expansion:", e); + } + } // Sanitize path let [rule, matches] = getRuleForURL(allRules, url, "sanitize"); @@ -129,6 +133,11 @@ function getRuleForURL(ALL_RULES: any, url: URL, type: string) { } const rules = ALL_RULES[url.host]; + + if (!rules.hasOwnProperty(type)) { + throw new Error(`No rules found for type ${type}`); + } + for (const rule of rules[type]) { // Check if rule pattern matches the URL.pathname, extract the matched parts const matches = new RegExp(rule.pattern).exec(url.pathname); @@ -140,7 +149,7 @@ function getRuleForURL(ALL_RULES: any, url: URL, type: string) { async function expandShortURL(shortURL: URL): Promise { const response = await got(shortURL, { - method: "HEAD", + method: "GET", maxRedirects: 5, followRedirect: true, });