This commit is contained in:
eric
2026-03-29 02:33:37 -05:00
parent 16dc9abbbb
commit ef87c43b33
17 changed files with 1197 additions and 407 deletions

View File

@@ -14,6 +14,13 @@ export type YoutubeProChannel = {
const STORAGE_KEY = "live-hub-youtube-pro-v2";
export function parseYoutubeProChannelList(raw: unknown): YoutubeProChannel[] {
if (!Array.isArray(raw)) return [];
return raw
.map((x) => migrateRow(x as Record<string, unknown>))
.filter((c): c is YoutubeProChannel => c !== null);
}
function migrateRow(x: Record<string, unknown>): YoutubeProChannel | null {
if (!x || typeof x !== "object") return null;
const id = String(x.id || "").trim();
@@ -62,6 +69,17 @@ export function saveYoutubeProChannels(channels: YoutubeProChannel[]): void {
window.localStorage.setItem(STORAGE_KEY, JSON.stringify(channels));
}
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 }),
});
}
export function newChannelId(): string {
return `ch_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 7)}`;
}