* Whether `host` is one of `domains` or a subdomain of one (e.g. `m.youtube.com` * matches `youtube.com`). A null host (unparseable URL) never matches. This is the * security boundary for provider detection: a link is only treated as a given * platform when its parsed host actually belongs to tha
(host: string | null, ...domains: string[])
| 35 | * like `youtube.com.evil.com` or `evil.com/youtube.com/...` are rejected. |
| 36 | */ |
| 37 | function hostMatches(host: string | null, ...domains: string[]): boolean { |
| 38 | if (host === null) return false |
| 39 | return domains.some((domain) => host === domain || host.endsWith(`.${domain}`)) |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Rewrite a Dropbox share URL's host to `dl.dropboxusercontent.com` so the file |