Skip to content

Commit

Permalink
fix: short link expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
developStorm committed Nov 18, 2024
1 parent f80b3bc commit 3f5a9c5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions utils/sanitizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand All @@ -140,7 +149,7 @@ function getRuleForURL(ALL_RULES: any, url: URL, type: string) {

async function expandShortURL(shortURL: URL): Promise<URL[]> {
const response = await got(shortURL, {
method: "HEAD",
method: "GET",
maxRedirects: 5,
followRedirect: true,
});
Expand Down

0 comments on commit 3f5a9c5

Please sign in to comment.