| "use strict"; |
| var __importDefault = (this && this.__importDefault) || function (mod) { |
| return (mod && mod.__esModule) ? mod : { "default": mod }; |
| }; |
| Object.defineProperty(exports, "__esModule", { value: true }); |
| exports.resolveUrl = resolveUrl; |
| const axios_1 = __importDefault(require("axios")); |
| |
| |
| |
| |
| async function resolveUrl(url) { |
| let currentUrl = url; |
| try { |
| const parsedUrl = new URL(url); |
| |
| |
| if (/google\.[a-z.]*$/.test(parsedUrl.hostname) && |
| parsedUrl.pathname === '/url' && |
| parsedUrl.searchParams.has('q')) { |
| currentUrl = parsedUrl.searchParams.get('q') || currentUrl; |
| } |
| |
| if (parsedUrl.hostname.includes('safelinks.protection.outlook.com') && |
| parsedUrl.searchParams.has('url')) { |
| currentUrl = parsedUrl.searchParams.get('url') || currentUrl; |
| } |
| |
| if (parsedUrl.hostname === 'lnkd.in' || (parsedUrl.hostname === 'www.linkedin.com' && parsedUrl.pathname.startsWith('/Check/'))) { |
| |
| } |
| |
| |
| const shorteners = ['bit.ly', 't.co', 'goo.gl', 'tinyurl.com', 'is.gd', 'buff.ly', 'adf.ly', 'lnkd.in']; |
| const isShortener = shorteners.some(s => parsedUrl.hostname.includes(s)); |
| if (isShortener) { |
| const response = await axios_1.default.head(currentUrl, { |
| maxRedirects: 5, |
| validateStatus: (status) => status >= 200 && status < 400 |
| }); |
| if (response.request.res.responseUrl) { |
| currentUrl = response.request.res.responseUrl; |
| } |
| } |
| return currentUrl; |
| } |
| catch (error) { |
| console.error('Error resolving URL:', error); |
| return url; |
| } |
| } |
|
|