fallback username with getUsernameFromProfileUrl#176
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughAdds a new exported utility that extracts a username from a profile URL and integrates it into the profile scraper; when the incoming username is falsy, the scraper derives a finalUsername from the profile URL and uses that for scraping. Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant scrapeProfileUrl
participant getUsernameFromProfileUrl
participant Scraper
Caller->>scrapeProfileUrl: invoke(profileUrl, username?)
alt username provided (truthy)
scrapeProfileUrl->>Scraper: call(scrape with finalUsername = username)
else username missing/falsy
scrapeProfileUrl->>getUsernameFromProfileUrl: call(profileUrl)
getUsernameFromProfileUrl-->>scrapeProfileUrl: return extractedUsername or ""
scrapeProfileUrl->>Scraper: call(scrape with finalUsername = extractedUsername)
end
Scraper-->>Caller: return result
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
lib/socials/getUsernameFromProfileUrl.ts (1)
15-15: Consider supporting additional TLDs for extensibility.The regex is limited to
.comand.netdomains. While this covers all currently supported platforms, consider making it more flexible for future extensibility:-const match = normalizedUrl.match(/(?:\.com|\.net)\/([^/?]+)/); +const match = normalizedUrl.match(/\/\/[^/]+\/([^/?]+)/);This pattern would match any domain by capturing the first path segment after the hostname.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
lib/apify/scrapeProfileUrl.ts(2 hunks)lib/socials/getUsernameFromProfileUrl.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
lib/apify/scrapeProfileUrl.ts (1)
lib/socials/getUsernameFromProfileUrl.ts (1)
getUsernameFromProfileUrl(6-21)
🔇 Additional comments (2)
lib/socials/getUsernameFromProfileUrl.ts (1)
1-11: LGTM: Clean function signature and early return.The documentation clearly describes the extraction logic, and the function signature appropriately handles nullable input with an early return for falsy values.
lib/apify/scrapeProfileUrl.ts (1)
7-7: LGTM: Import statement is correct.The import path and function name are appropriate.
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
lib/socials/getUsernameFromProfileUrl.ts (1)
15-15: Critical: Regex still fails for multi-segment YouTube URLs.As flagged in the previous review, the regex pattern
/(?:\.com|\.net)\/([^/?]+)/only captures the first path segment and will produce incorrect results for YouTube URLs with multi-segment paths likeyoutube.com/c/channelname(extracts"c"),youtube.com/user/username(extracts"user"), andyoutube.com/channel/channelid(extracts"channel").This issue remains unresolved and must be fixed before merging.
Apply the previously suggested fix:
- const match = normalizedUrl.match(/(?:\.com|\.net)\/([^/?]+)/); + const match = normalizedUrl.match(/(?:\.com|\.net)\/(?:@|c\/|user\/|channel\/)?([^/?]+)/);
🧹 Nitpick comments (1)
lib/socials/getUsernameFromProfileUrl.ts (1)
13-16: Consider broader TLD support.The regex currently only matches
.comand.netdomains. If you anticipate supporting profile URLs from platforms with other TLDs (e.g.,.org,.io,.co, or country-specific TLDs), consider expanding the pattern.For example:
// Support common TLDs const match = normalizedUrl.match(/\.(?:com|net|org|io|co)\/(?:@|c\/|user\/|channel\/)?([^/?]+)/);Or use a more generic pattern that matches any TLD:
// Match any TLD const match = normalizedUrl.match(/\.[a-z]{2,}\/(?:@|c\/|user\/|channel\/)?([^/?]+)/);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
lib/apify/scrapeProfileUrl.ts(2 hunks)lib/socials/getUsernameFromProfileUrl.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- lib/apify/scrapeProfileUrl.ts
Summary by CodeRabbit