mirror of
https://github.com/KuekHaoYang/KVideo.git
synced 2026-08-14 16:23:43 +08:00
feat: proxy HLS manifest encryption key URIs and refine segment URL proxying
This commit is contained in:
@@ -8,15 +8,32 @@ export async function processM3u8Content(
|
||||
const base = new URL(baseUrl);
|
||||
|
||||
const processedLines = lines.map(line => {
|
||||
// Skip comments and empty lines
|
||||
if (line.trim().startsWith('#') || !line.trim()) {
|
||||
const trimmed = line.trim();
|
||||
|
||||
// Handle EXT-X-KEY encryption keys
|
||||
if (trimmed.startsWith('#EXT-X-KEY:')) {
|
||||
// Extract URI from the key tag
|
||||
const uriMatch = trimmed.match(/URI="([^"]+)"/);
|
||||
if (uriMatch && uriMatch[1]) {
|
||||
const keyUri = uriMatch[1];
|
||||
try {
|
||||
const absoluteUrl = new URL(keyUri, base).toString();
|
||||
const proxiedUrl = `${origin}/api/proxy?url=${encodeURIComponent(absoluteUrl)}`;
|
||||
return trimmed.replace(/URI="[^"]+"/, `URI="${proxiedUrl}"`);
|
||||
} catch {
|
||||
return line;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Skip other comments and empty lines
|
||||
if (trimmed.startsWith('#') || !trimmed) {
|
||||
return line;
|
||||
}
|
||||
|
||||
// Resolve relative URLs
|
||||
// Resolve relative URLs for segments
|
||||
try {
|
||||
const absoluteUrl = new URL(line.trim(), base).toString();
|
||||
// Wrap in proxy
|
||||
const absoluteUrl = new URL(trimmed, base).toString();
|
||||
return `${origin}/api/proxy?url=${encodeURIComponent(absoluteUrl)}`;
|
||||
} catch {
|
||||
return line;
|
||||
|
||||
Reference in New Issue
Block a user