's'
This commit is contained in:
@@ -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)}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user