This commit is contained in:
eric
2026-03-29 03:35:05 -05:00
parent 895dafc0e0
commit 22061fb3c8
14 changed files with 669 additions and 94 deletions

View File

@@ -116,15 +116,13 @@ export function parseYoutubeIniFields(content: string): YoutubeIniFields {
return { key, rtmps, bitrate, fastAudio };
}
/** 与 web.py `managed_url_config_relpath` 一致(app-config 相对路径 */
/** 与 web.py `managed_url_config_relpath` 一致(每进程独立,避免 YouTube / TikTok 共写同一文件 */
export function managedUrlConfigRelPathForPm2(pm2: string): string {
if (!pm2.includes("__")) return "URL_config.ini";
return `URL_config.${pm2.replace(/[^a-zA-Z0-9_.-]/g, "_")}.ini`;
}
/** 与 web.py `managed_youtube_ini_relpath` 一致 */
export function managedYoutubeIniRelPathForPm2(pm2: string): string {
if (!pm2.includes("__")) return "youtube.ini";
return `youtube.${pm2.replace(/[^a-zA-Z0-9_.-]/g, "_")}.ini`;
}

View File

@@ -69,15 +69,42 @@ export function saveYoutubeProChannels(channels: YoutubeProChannel[]): void {
window.localStorage.setItem(STORAGE_KEY, JSON.stringify(channels));
}
const YOUTUBE_PRO_SYNC_PATHS = ["/hub/youtube_pro_channels", "/youtube_pro_channels"] as const;
/** 从服务器拉多频道列表(依次尝试 /hub 与根路径,兼容反代未转发 /hub 的情况) */
export async function fetchYoutubeProChannelsRemote(
fetchJson: <T,>(path: string, init?: RequestInit) => Promise<T>,
): Promise<YoutubeProChannel[]> {
for (const path of YOUTUBE_PRO_SYNC_PATHS) {
try {
const data = await fetchJson<{ channels?: unknown }>(path);
const fromServer = parseYoutubeProChannelList(data.channels);
if (fromServer.length) return fromServer;
} catch {
/* try next */
}
}
return [];
}
export async function pushYoutubeProChannelsRemote(
fetchJson: <T,>(path: string, init?: RequestInit) => Promise<T>,
channels: YoutubeProChannel[],
): Promise<void> {
await fetchJson("/hub/youtube_pro_channels", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ channels }),
});
let last: Error | null = null;
for (const path of YOUTUBE_PRO_SYNC_PATHS) {
try {
await fetchJson(path, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ channels }),
});
return;
} catch (e) {
last = e instanceof Error ? e : new Error(String(e));
}
}
throw last ?? new Error("youtube_pro_channels sync failed");
}
export function newChannelId(): string {