feat: Implement HLS download and enhance copy link functionality to support original and proxied URLs.

This commit is contained in:
kuekhaoyang
2025-11-29 11:05:04 +08:00
parent 4e7024f2bf
commit 220d1b0faf
22 changed files with 401 additions and 226 deletions
+28
View File
@@ -0,0 +1,28 @@
import { NextRequest } from 'next/server';
export async function processM3u8Content(
content: string,
baseUrl: string,
origin: string
): Promise<string> {
const lines = content.split('\n');
const base = new URL(baseUrl);
const processedLines = lines.map(line => {
// Skip comments and empty lines
if (line.trim().startsWith('#') || !line.trim()) {
return line;
}
// Resolve relative URLs
try {
const absoluteUrl = new URL(line.trim(), base).toString();
// Wrap in proxy
return `${origin}/api/proxy?url=${encodeURIComponent(absoluteUrl)}`;
} catch (e) {
return line;
}
});
return processedLines.join('\n');
}