movie-web/src/utils/cdn.ts

17 lines
433 B
TypeScript
Raw Normal View History

2023-12-27 23:39:32 +01:00
import { conf } from "@/setup/config";
export function processCdnLink(url: string): string {
const parsedUrl = new URL(url);
const replacements = conf().CDN_REPLACEMENTS;
for (const [before, after] of replacements) {
if (parsedUrl.hostname.endsWith(before)) {
2023-12-27 23:52:18 +01:00
parsedUrl.hostname = after;
parsedUrl.port = "";
parsedUrl.protocol = "https://";
2023-12-27 23:39:32 +01:00
return parsedUrl.toString();
}
}
return url;
}