fix: address latest CodeRabbit review items

This commit is contained in:
2026-03-23 01:01:53 -07:00
parent c6e6aeebbe
commit 207151dba3
5 changed files with 159 additions and 13 deletions

View File

@@ -12,6 +12,7 @@ test('isYoutubeMediaPath detects youtube watch and short urls', () => {
test('isYoutubeMediaPath ignores local files and non-youtube urls', () => {
assert.equal(isYoutubeMediaPath('/tmp/video.mkv'), false);
assert.equal(isYoutubeMediaPath('https://example.com/watch?v=abc123'), false);
assert.equal(isYoutubeMediaPath('https://notyoutube.com/watch?v=abc123'), false);
assert.equal(isYoutubeMediaPath(' '), false);
assert.equal(isYoutubeMediaPath(null), false);
});

View File

@@ -6,6 +6,10 @@ function trimToNull(value: string | null | undefined): string | null {
return trimmed.length > 0 ? trimmed : null;
}
function matchesYoutubeHost(hostname: string, expectedHost: string): boolean {
return hostname === expectedHost || hostname.endsWith(`.${expectedHost}`);
}
export function isYoutubeMediaPath(mediaPath: string | null | undefined): boolean {
const normalized = trimToNull(mediaPath);
if (!normalized) {
@@ -21,10 +25,9 @@ export function isYoutubeMediaPath(mediaPath: string | null | undefined): boolea
const host = parsed.hostname.toLowerCase();
return (
host === 'youtu.be' ||
host.endsWith('.youtu.be') ||
host.endsWith('youtube.com') ||
host.endsWith('youtube-nocookie.com')
matchesYoutubeHost(host, 'youtu.be') ||
matchesYoutubeHost(host, 'youtube.com') ||
matchesYoutubeHost(host, 'youtube-nocookie.com')
);
}