[WIP] Add majority of logic for HLS reading support

This commit is contained in:
Vanilagy
2026-01-27 14:45:44 +01:00
parent f620a328e5
commit d1fbea3e19
48 changed files with 5511 additions and 9 deletions
+46
View File
@@ -0,0 +1,46 @@
import { expect, test } from 'vitest';
import { joinPaths } from '../../src/misc.js';
test('joinPaths handles all path combinations correctly', () => {
// Simple relative paths
expect(joinPaths('path/to/entry.m3u8', 'other.m3u8')).toBe('path/to/other.m3u8');
expect(joinPaths('entry.m3u8', 'other.m3u8')).toBe('other.m3u8');
expect(joinPaths('/path/to/entry.m3u8', 'other.m3u8')).toBe('/path/to/other.m3u8');
// Absolute relative paths (starting with /)
expect(joinPaths('path/to/entry.m3u8', '/other.m3u8')).toBe('/other.m3u8');
expect(joinPaths('/path/to/entry.m3u8', '/other.m3u8')).toBe('/other.m3u8');
// With protocols
expect(joinPaths('https://example.com/path/to/entry.m3u8', 'other.m3u8'))
.toBe('https://example.com/path/to/other.m3u8');
expect(joinPaths('https://example.com/path/to/entry.m3u8', '/other.m3u8'))
.toBe('https://example.com/other.m3u8');
expect(joinPaths('file:///path/to/entry.m3u8', 'other.m3u8')).toBe('file:///path/to/other.m3u8');
expect(joinPaths('file:///path/to/entry.m3u8', '/other.m3u8')).toBe('file:///other.m3u8');
// With ./
expect(joinPaths('path/to/entry.m3u8', './other.m3u8')).toBe('path/to/other.m3u8');
expect(joinPaths('https://example.com/path/to/entry.m3u8', './other.m3u8'))
.toBe('https://example.com/path/to/other.m3u8');
// With ../
expect(joinPaths('path/to/entry.m3u8', '../other.m3u8')).toBe('path/other.m3u8');
expect(joinPaths('path/to/deep/entry.m3u8', '../../other.m3u8')).toBe('path/other.m3u8');
expect(joinPaths('https://example.com/path/to/entry.m3u8', '../other.m3u8'))
.toBe('https://example.com/path/other.m3u8');
expect(joinPaths('https://example.com/a/b/c/entry.m3u8', '../../other.m3u8'))
.toBe('https://example.com/a/other.m3u8');
// Mixed ./ and ../
expect(joinPaths('path/to/entry.m3u8', './../other.m3u8')).toBe('path/other.m3u8');
expect(joinPaths('path/to/entry.m3u8', '../foo/../other.m3u8')).toBe('path/other.m3u8');
// Second argument is a full URL with protocol
expect(joinPaths('path/to/entry.m3u8', 'https://example.com/other.m3u8'))
.toBe('https://example.com/other.m3u8');
expect(joinPaths('https://example.com/path/to/entry.m3u8', 'https://other.com/other.m3u8'))
.toBe('https://other.com/other.m3u8');
expect(joinPaths('file:///path/to/entry.m3u8', 'https://example.com/other.m3u8'))
.toBe('https://example.com/other.m3u8');
});