mirror of
https://github.com/imputnet/cobalt.git
synced 2025-06-28 01:18:27 +00:00
api: disable youtube HLS by default & add env to enable it
This commit is contained in:
parent
1e7406de9d
commit
af99e7218c
@ -156,6 +156,7 @@ export const runAPI = async (express, app, __dirname, isPrimary = true) => {
|
||||
return fail(res, `error.api.auth.key.${error}`);
|
||||
}
|
||||
|
||||
req.isApiKey = true;
|
||||
return next();
|
||||
});
|
||||
|
||||
@ -264,6 +265,7 @@ export const runAPI = async (express, app, __dirname, isPrimary = true) => {
|
||||
patternMatch: parsed.patternMatch,
|
||||
params: normalizedRequest,
|
||||
isSession: req.isSession ?? false,
|
||||
isApiKey: req.isApiKey ?? false,
|
||||
});
|
||||
|
||||
res.status(result.status).json(result.body);
|
||||
|
@ -8,6 +8,7 @@ import * as cluster from "../misc/cluster.js";
|
||||
import { Green, Yellow } from "../misc/console-text.js";
|
||||
|
||||
const forceLocalProcessingOptions = ["never", "session", "always"];
|
||||
const youtubeHlsOptions = ["never", "key", "always"];
|
||||
|
||||
export const loadEnvs = (env = process.env) => {
|
||||
const disabledServices = env.DISABLED_SERVICES?.split(',') || [];
|
||||
@ -74,6 +75,9 @@ export const loadEnvs = (env = process.env) => {
|
||||
// "never" | "session" | "always"
|
||||
forceLocalProcessing: env.FORCE_LOCAL_PROCESSING ?? "never",
|
||||
|
||||
// "never" | "key" | "always"
|
||||
enableDeprecatedYoutubeHls: env.ENABLE_DEPRECATED_YOUTUBE_HLS ?? "never",
|
||||
|
||||
envFile: env.API_ENV_FILE,
|
||||
envRemoteReloadInterval: 300,
|
||||
};
|
||||
@ -106,6 +110,12 @@ export const validateEnvs = async (env) => {
|
||||
throw new Error("Invalid FORCE_LOCAL_PROCESSING");
|
||||
}
|
||||
|
||||
if (env.enableDeprecatedYoutubeHls && !youtubeHlsOptions.includes(env.enableDeprecatedYoutubeHls)) {
|
||||
console.error("ENABLE_DEPRECATED_YOUTUBE_HLS is invalid.");
|
||||
console.error(`Supported options are are: ${youtubeHlsOptions.join(', ')}\n`);
|
||||
throw new Error("Invalid ENABLE_DEPRECATED_YOUTUBE_HLS");
|
||||
}
|
||||
|
||||
if (env.externalProxy && env.freebindCIDR) {
|
||||
throw new Error('freebind is not available when external proxy is enabled')
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import xiaohongshu from "./services/xiaohongshu.js";
|
||||
|
||||
let freebind;
|
||||
|
||||
export default async function({ host, patternMatch, params, isSession }) {
|
||||
export default async function({ host, patternMatch, params, isSession, isApiKey }) {
|
||||
const { url } = params;
|
||||
assert(url instanceof URL);
|
||||
let dispatcher, requestIP;
|
||||
@ -65,6 +65,14 @@ export default async function({ host, patternMatch, params, isSession }) {
|
||||
});
|
||||
}
|
||||
|
||||
// youtubeHLS will be fully removed in the future
|
||||
let youtubeHLS = params.youtubeHLS;
|
||||
const hlsEnv = env.enableDeprecatedYoutubeHls;
|
||||
|
||||
if (hlsEnv === "never" || (hlsEnv === "key" && !isApiKey)) {
|
||||
youtubeHLS = false;
|
||||
}
|
||||
|
||||
switch (host) {
|
||||
case "twitter":
|
||||
r = await twitter({
|
||||
@ -105,7 +113,7 @@ export default async function({ host, patternMatch, params, isSession }) {
|
||||
isAudioOnly,
|
||||
isAudioMuted,
|
||||
dubLang: params.youtubeDubLang,
|
||||
youtubeHLS: params.youtubeHLS,
|
||||
youtubeHLS,
|
||||
}
|
||||
|
||||
if (url.hostname === "music.youtube.com" || isAudioOnly) {
|
||||
|
Loading…
Reference in New Issue
Block a user