s
This commit is contained in:
@@ -71,20 +71,24 @@ export function saveYoutubeProChannels(channels: YoutubeProChannel[]): void {
|
||||
|
||||
const YOUTUBE_PRO_SYNC_PATHS = ["/hub/youtube_pro_channels", "/youtube_pro_channels"] as const;
|
||||
|
||||
export type YoutubeProChannelsRemoteResult = {
|
||||
fetched: boolean;
|
||||
channels: YoutubeProChannel[];
|
||||
};
|
||||
|
||||
/** 从服务器拉多频道列表(依次尝试 /hub 与根路径,兼容反代未转发 /hub 的情况) */
|
||||
export async function fetchYoutubeProChannelsRemote(
|
||||
fetchJson: <T,>(path: string, init?: RequestInit) => Promise<T>,
|
||||
): Promise<YoutubeProChannel[]> {
|
||||
): Promise<YoutubeProChannelsRemoteResult> {
|
||||
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;
|
||||
return { fetched: true, channels: parseYoutubeProChannelList(data.channels) };
|
||||
} catch {
|
||||
/* try next */
|
||||
}
|
||||
}
|
||||
return [];
|
||||
return { fetched: false, channels: [] };
|
||||
}
|
||||
|
||||
export async function pushYoutubeProChannelsRemote(
|
||||
|
||||
Reference in New Issue
Block a user