linkfollower
Advanced tools
Comparing version 1.1.5 to 1.2.0
@@ -43,10 +43,15 @@ const userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246' | ||
} | ||
return { url: url, redirect: true, status: response.status, redirectUrl: addPathTo(locationHeader, url.origin) } | ||
return { url: url, redirect: true, status: response.status, redirectUrl: addBaseTo(locationHeader, url.origin) } | ||
} | ||
if (response.status == 200) { | ||
const metaRefreshUrl = extractMetaRefreshUrl(await response.text()) | ||
return metaRefreshUrl ? | ||
{ url: url, redirect: true, status: '200 + META REFRESH', redirectUrl: addPathTo(metaRefreshUrl, url.origin) } : | ||
{ url: url, redirect: false, status: response.status } | ||
if (response.status === 200) { | ||
const html = await response.text() | ||
for (const urlExtractor of extractors) { | ||
const extracted = urlExtractor(html) | ||
if (extracted) { | ||
return { url: url, redirect: true, status: '200 + extracted', redirectUrl: addBaseTo(extracted, url.origin) } | ||
} | ||
} | ||
return { url: url, redirect: false, status: response.status } | ||
} | ||
@@ -71,2 +76,8 @@ } catch (error) { | ||
const extractFromLinkedIn = (html) => { | ||
const regex = /<a.*name="external_url_click".*>\s+(http[s]?:\/\/.*\s+)<\/a>/g | ||
const matches = [...html.matchAll(regex)] | ||
return matches.length != 0 ? matches.map(m => m[1])[0].trim() : null | ||
} | ||
const stripUnwantedCharsFrom = (url) => url | ||
@@ -78,8 +89,10 @@ .replaceAll("'", "") | ||
const addPathTo = (locationResponse, base) => { | ||
if (locationResponse.startsWith('http')) { | ||
new URL(locationResponse) | ||
const addBaseTo = (maybeCompleteUrl, base) => { | ||
if (maybeCompleteUrl.startsWith('http')) { | ||
new URL(maybeCompleteUrl) | ||
} | ||
return new URL(locationResponse, base) | ||
} | ||
return new URL(maybeCompleteUrl, base) | ||
} | ||
const extractors = [extractMetaRefreshUrl, extractFromLinkedIn] |
{ | ||
"name": "linkfollower", | ||
"version": "1.1.5", | ||
"version": "1.2.0", | ||
"type": "module", | ||
@@ -8,5 +8,5 @@ "description": "Command line utility that lets you follow redirects to see where http URLs end up. Useful for shortened URLs.", | ||
"devDependencies": { | ||
"chai": "5.1.0", | ||
"express": "4.18.2", | ||
"mocha": "10.3.0" | ||
"chai": "5.1.1", | ||
"express": "4.19.2", | ||
"mocha": "10.6.0" | ||
}, | ||
@@ -13,0 +13,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6550
107