douyinWEB/frontend/src/lib/ytChannelMeta.ts
eric c9c71948cb Unify YouTube OAuth/YPP card meta and fix YPP monetize payloads.
Seed brand hints on startup, merge Shorts OAuth into yt-long board, and retry Studio monetize with corrected self-cert formats.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-22 01:59:36 -05:00

38 lines
1.2 KiB
TypeScript

import type { YtChannelMeta } from "@/components/YtChannelMetaBadges";
import { brandHintForChannel } from "@/lib/ytBrandHints";
import type { YtProfileSnippet } from "@/components/YtChannelProfileSnippet";
export type ChannelMetaInput = {
id?: string;
enabled?: boolean;
authorized?: boolean;
oauth_ok?: number | boolean | null;
oauth_error?: string;
oauth_profile_id?: string;
youtube_channel_id?: string;
note?: string;
brand_hint?: string;
ypp_ok?: number | null;
yt_profile?: YtProfileSnippet | null;
};
export function buildChannelMeta(
ch: ChannelMetaInput,
oauthIssue?: { oauth_error?: string } | null,
): YtChannelMeta {
const staleReauth = Boolean(ch.authorized && (ch.oauth_error || "").includes("重授权中"));
const oauthBad = Boolean(oauthIssue) && !staleReauth;
const brandHint =
String(ch.brand_hint || "").trim() ||
brandHintForChannel(ch.yt_profile, ch.youtube_channel_id, ch.note);
return {
enabled: ch.enabled,
authorized: ch.authorized,
oauthOk: staleReauth ? 1 : oauthBad ? 0 : ch.oauth_ok,
oauthError: oauthIssue?.oauth_error || ch.oauth_error,
brandHint,
yppOk: ch.ypp_ok,
oauthProfileId: ch.oauth_profile_id,
};
}