mirror of
https://github.com/KuekHaoYang/KVideo.git
synced 2026-08-22 12:13:43 +08:00
feat: Implement HLS download and enhance copy link functionality to support original and proxied URLs.
This commit is contained in:
@@ -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');
|
||||
}
|
||||
Reference in New Issue
Block a user