A tool for parsing traffic on the jetstream and applying a moderation workstream based on regexp based rules

Fix: Resolve shortened URLs in posts

The URL regex was updated to be case-insensitive to ensure that
shortened URLs are correctly resolved. Also added more logging for
debugging purposes.

Skywatch 4e4ec535 dade9598

+23 -8
+23 -8
src/rules/posts/checkPosts.ts
··· 21 21 return; 22 22 } 23 23 24 - const urlRegex = /https?:\/\/[^\s]+/g; 24 + const urlRegex = /https?:\/\/[^\s]+/gi; 25 25 26 26 // Check for link shorteners 27 27 if (LINK_SHORTENER.test(post[0].text)) { 28 28 try { 29 29 const url = post[0].text.match(urlRegex); 30 30 if (url && LINK_SHORTENER.test(url[0])) { 31 - // logger.info(`[CHECKPOSTS]: Checking shortened URL: ${url[0]}`); 31 + logger.debug( 32 + { process: "CHECKPOSTS", url: url[0], did: post[0].did }, 33 + "Resolving shortened URL", 34 + ); 35 + 32 36 const finalUrl = await getFinalUrl(url[0]); 33 - if (finalUrl) { 34 - const originalUrl = post[0].text; 37 + if (finalUrl && finalUrl !== url[0]) { 35 38 post[0].text = post[0].text.replace(url[0], finalUrl); 36 - /* logger.info( 37 - `[CHECKPOSTS]: Shortened URL resolved: ${originalUrl} -> ${finalUrl}`, 38 - ); */ 39 + logger.debug( 40 + { 41 + process: "CHECKPOSTS", 42 + originalUrl: url[0], 43 + resolvedUrl: finalUrl, 44 + did: post[0].did, 45 + }, 46 + "Shortened URL resolved", 47 + ); 39 48 } 40 49 } 41 50 } catch (error) { ··· 48 57 : { error: String(error) }; 49 58 50 59 logger.error( 51 - { process: "CHECKPOSTS", text: post[0].text, ...errorInfo }, 60 + { 61 + process: "CHECKPOSTS", 62 + text: post[0].text, 63 + did: post[0].did, 64 + atURI: post[0].atURI, 65 + ...errorInfo, 66 + }, 52 67 "Failed to resolve shortened URL", 53 68 ); 54 69 // Keep the original URL if resolution fails