6 changed files with 68 additions and 4 deletions
@ -0,0 +1,5 @@
@@ -0,0 +1,5 @@
|
||||
const allowedExtensionVersion = ["0.0.1"]; |
||||
|
||||
export function isAllowedExtensionVersion(version: string): boolean { |
||||
return allowedExtensionVersion.includes(version); |
||||
} |
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
import { Stream } from "@movie-web/providers"; |
||||
|
||||
import { setDomainRule } from "@/backend/extension/messaging"; |
||||
|
||||
function extractDomain(url: string): string { |
||||
try { |
||||
const u = new URL(url); |
||||
return u.hostname; |
||||
} catch { |
||||
return url; |
||||
} |
||||
} |
||||
|
||||
function extractDomainsFromStream(stream: Stream): string[] { |
||||
if (stream.type === "hls") { |
||||
return [extractDomain(stream.playlist)]; |
||||
} |
||||
if (stream.type === "file") { |
||||
return Object.values(stream.qualities).map((v) => extractDomain(v.url)); |
||||
} |
||||
return []; |
||||
} |
||||
|
||||
function buildHeadersFromStream(stream: Stream): Record<string, string> { |
||||
const headers: Record<string, string> = {}; |
||||
Object.entries(stream.headers ?? {}).forEach((entry) => { |
||||
headers[entry[0]] = entry[1]; |
||||
}); |
||||
Object.entries(stream.preferredHeaders ?? {}).forEach((entry) => { |
||||
headers[entry[0]] = entry[1]; |
||||
}); |
||||
return headers; |
||||
} |
||||
|
||||
export async function prepareStream(stream: Stream) { |
||||
await setDomainRule( |
||||
extractDomainsFromStream(stream), |
||||
buildHeadersFromStream(stream), |
||||
); |
||||
} |
Loading…
Reference in new issue