fix: clear oauth_ok after re-auth, show Google brand hints, reduce false OAuth errors
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
0309bbe0f6
commit
d99153175a
@ -413,7 +413,13 @@ async def exchange_code(*, code: str, state: str, request_base: str = "") -> dic
|
|||||||
name = str(channel.get("name") or "").strip()
|
name = str(channel.get("name") or "").strip()
|
||||||
if yt_title and (not name or name.startswith("Shorts") or name == "未命名频道"):
|
if yt_title and (not name or name.startswith("Shorts") or name == "未命名频道"):
|
||||||
patch["name"] = yt_title
|
patch["name"] = yt_title
|
||||||
updated = db.update_shorts_channel(channel_pk, **patch)
|
updated = db.update_shorts_channel(
|
||||||
|
channel_pk,
|
||||||
|
**patch,
|
||||||
|
oauth_ok=1,
|
||||||
|
oauth_checked_at=time.time(),
|
||||||
|
oauth_error="",
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
from . import yt_long_db
|
from . import yt_long_db
|
||||||
|
|
||||||
|
|||||||
@ -503,13 +503,17 @@ class ShortsPipeline:
|
|||||||
try:
|
try:
|
||||||
for ch in db.list_shorts_channels(enabled=True):
|
for ch in db.list_shorts_channels(enabled=True):
|
||||||
ok_flag = int(ch.get("oauth_ok") if ch.get("oauth_ok") is not None else -1)
|
ok_flag = int(ch.get("oauth_ok") if ch.get("oauth_ok") is not None else -1)
|
||||||
if ok_flag == 0 or not str(ch.get("refresh_token") or "").strip():
|
err = str(ch.get("oauth_error") or "")
|
||||||
|
has_rt = bool(str(ch.get("refresh_token") or "").strip())
|
||||||
|
if ok_flag == 0 or not has_rt:
|
||||||
|
if has_rt and "重授权中" in err:
|
||||||
|
continue
|
||||||
oauth_issues.append(
|
oauth_issues.append(
|
||||||
{
|
{
|
||||||
"id": ch.get("id"),
|
"id": ch.get("id"),
|
||||||
"name": ch.get("name"),
|
"name": ch.get("name"),
|
||||||
"oauth_ok": ok_flag,
|
"oauth_ok": ok_flag,
|
||||||
"oauth_error": ch.get("oauth_error") or ("未授权" if not str(ch.get("refresh_token") or "").strip() else ""),
|
"oauth_error": err or ("未授权" if not has_rt else ""),
|
||||||
"oauth_checked_at": ch.get("oauth_checked_at") or 0,
|
"oauth_checked_at": ch.get("oauth_checked_at") or 0,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@ -256,6 +256,7 @@ def schedule_board(limit: int = 24) -> dict[str, Any]:
|
|||||||
"last_live_url": str(c.get("last_live_url") or ""),
|
"last_live_url": str(c.get("last_live_url") or ""),
|
||||||
"oauth_ok": c.get("oauth_ok"),
|
"oauth_ok": c.get("oauth_ok"),
|
||||||
"oauth_error": str(c.get("oauth_error") or ""),
|
"oauth_error": str(c.get("oauth_error") or ""),
|
||||||
|
"note": str(c.get("note") or ""),
|
||||||
"ypp_ok": ypp_by_shorts.get(cid, -1),
|
"ypp_ok": ypp_by_shorts.get(cid, -1),
|
||||||
**stats,
|
**stats,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,7 @@ import {
|
|||||||
import { UploadTimeline } from "@/components/UploadTimeline";
|
import { UploadTimeline } from "@/components/UploadTimeline";
|
||||||
import { YouTubeLiveBadge } from "@/components/YouTubeLiveBadge";
|
import { YouTubeLiveBadge } from "@/components/YouTubeLiveBadge";
|
||||||
import { YtChannelProfileSnippet, type YtProfileSnippet } from "@/components/YtChannelProfileSnippet";
|
import { YtChannelProfileSnippet, type YtProfileSnippet } from "@/components/YtChannelProfileSnippet";
|
||||||
import type { YtChannelMeta } from "@/components/YtChannelMetaBadges";
|
import { brandHintForChannel } from "@/lib/ytBrandHints";
|
||||||
import { SessionCharts, type RelayStats } from "@/components/SessionCharts";
|
import { SessionCharts, type RelayStats } from "@/components/SessionCharts";
|
||||||
import { PageLoader, TableSkeleton } from "@/components/ui";
|
import { PageLoader, TableSkeleton } from "@/components/ui";
|
||||||
import { fetchJson, fmtDuration, fmtTs, todayBeijingISO, shiftBeijingISO } from "@/lib/api";
|
import { fetchJson, fmtDuration, fmtTs, todayBeijingISO, shiftBeijingISO } from "@/lib/api";
|
||||||
@ -88,6 +88,7 @@ type BoardChannel = {
|
|||||||
ypp_ok?: number;
|
ypp_ok?: number;
|
||||||
oauth_ok?: number;
|
oauth_ok?: number;
|
||||||
oauth_error?: string;
|
oauth_error?: string;
|
||||||
|
note?: string;
|
||||||
last_status?: string;
|
last_status?: string;
|
||||||
last_title?: string;
|
last_title?: string;
|
||||||
last_live_url?: string;
|
last_live_url?: string;
|
||||||
@ -402,12 +403,17 @@ export default function ShortsPage() {
|
|||||||
}>;
|
}>;
|
||||||
|
|
||||||
function channelMeta(ch: BoardChannel): YtChannelMeta {
|
function channelMeta(ch: BoardChannel): YtChannelMeta {
|
||||||
const oauthBad = oauthIssues.some((x) => x.id === ch.id);
|
const issue = oauthIssues.find((x) => x.id === ch.id);
|
||||||
|
const oauthBad = Boolean(issue);
|
||||||
|
const staleReauth = Boolean(
|
||||||
|
ch.authorized && issue?.oauth_error?.includes("重授权中"),
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
enabled: ch.enabled,
|
enabled: ch.enabled,
|
||||||
authorized: ch.authorized,
|
authorized: ch.authorized,
|
||||||
oauthOk: oauthBad ? 0 : ch.oauth_ok,
|
oauthOk: staleReauth ? 1 : oauthBad ? 0 : ch.oauth_ok,
|
||||||
oauthError: oauthBad ? oauthIssues.find((x) => x.id === ch.id)?.oauth_error : ch.oauth_error,
|
oauthError: issue?.oauth_error || ch.oauth_error,
|
||||||
|
brandHint: brandHintForChannel(ch.yt_profile, ch.youtube_channel_id, ch.note),
|
||||||
yppOk: ch.ypp_ok,
|
yppOk: ch.ypp_ok,
|
||||||
oauthProfileId: ch.oauth_profile_id,
|
oauthProfileId: ch.oauth_profile_id,
|
||||||
};
|
};
|
||||||
@ -459,7 +465,7 @@ export default function ShortsPage() {
|
|||||||
if (hasBound && needTitle) {
|
if (hasBound && needTitle) {
|
||||||
const ok = window.confirm(
|
const ok = window.confirm(
|
||||||
`本卡需要的 YouTube 频道:\n${needTitle}${needHandle ? ` ${needHandle}` : ""}\n\n` +
|
`本卡需要的 YouTube 频道:\n${needTitle}${needHandle ? ` ${needHandle}` : ""}\n\n` +
|
||||||
`系统将自动撤销旧 OAuth token,再打开 Google 重新授权(含 YPP 获利所需 force-ssl 权限)。\n` +
|
`Google 授权页请选品牌账号:${brandHintForChannel(board?.yt_profile, full?.youtube_channel_id || board?.youtube_channel_id, full?.note || board?.note) || "(见卡片 Google·… 提示)"}\n\n` +
|
||||||
`Google 品牌账号名可能和上面不一样;点错了页面会提示,不会写入。\n\n继续?`
|
`Google 品牌账号名可能和上面不一样;点错了页面会提示,不会写入。\n\n继续?`
|
||||||
);
|
);
|
||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
|
|||||||
@ -7,6 +7,8 @@ export type YtChannelMeta = {
|
|||||||
authorized?: boolean;
|
authorized?: boolean;
|
||||||
oauthOk?: number | boolean | null;
|
oauthOk?: number | boolean | null;
|
||||||
oauthError?: string;
|
oauthError?: string;
|
||||||
|
/** Google brand-account name shown in OAuth picker (often ≠ YouTube title). */
|
||||||
|
brandHint?: string;
|
||||||
/** -1 unknown, 0 not YPP, 1 YPP */
|
/** -1 unknown, 0 not YPP, 1 YPP */
|
||||||
yppOk?: number | null;
|
yppOk?: number | null;
|
||||||
oauthProfileId?: string;
|
oauthProfileId?: string;
|
||||||
@ -18,8 +20,12 @@ function oauthTone(oauthOk?: number | boolean | null, authorized?: boolean) {
|
|||||||
return "text-amber-300";
|
return "text-amber-300";
|
||||||
}
|
}
|
||||||
|
|
||||||
function oauthLabel(oauthOk?: number | boolean | null, authorized?: boolean) {
|
function oauthLabel(oauthOk?: number | boolean | null, authorized?: boolean, oauthError?: string) {
|
||||||
if (oauthOk === 0 || oauthOk === false) return "OAuth 异常";
|
if (oauthOk === 0 || oauthOk === false) {
|
||||||
|
if (oauthError?.includes("重授权中")) return "授权写入中";
|
||||||
|
if (oauthError?.includes("force-ssl")) return "缺 YPP 权限";
|
||||||
|
return "OAuth 异常";
|
||||||
|
}
|
||||||
if (authorized) return "已授权";
|
if (authorized) return "已授权";
|
||||||
return "未授权";
|
return "未授权";
|
||||||
}
|
}
|
||||||
@ -49,8 +55,13 @@ export function YtChannelMetaBadges({
|
|||||||
className={`${badge} ${oauthTone(meta.oauthOk, meta.authorized)}`}
|
className={`${badge} ${oauthTone(meta.oauthOk, meta.authorized)}`}
|
||||||
title={meta.oauthError || undefined}
|
title={meta.oauthError || undefined}
|
||||||
>
|
>
|
||||||
{oauthLabel(meta.oauthOk, meta.authorized)}
|
{oauthLabel(meta.oauthOk, meta.authorized, meta.oauthError)}
|
||||||
</span>
|
</span>
|
||||||
|
{meta.brandHint ? (
|
||||||
|
<span className={`${badge} text-sky-300/90`} title="Google 授权页选这个品牌账号">
|
||||||
|
Google·{meta.brandHint}
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
{meta.yppOk === 1 ? (
|
{meta.yppOk === 1 ? (
|
||||||
<span className={`${badge} text-emerald-300`} title="YouTube Partner Program · 上传后自动开广告获利">
|
<span className={`${badge} text-emerald-300`} title="YouTube Partner Program · 上传后自动开广告获利">
|
||||||
YPP·获利
|
YPP·获利
|
||||||
|
|||||||
31
frontend/src/lib/ytBrandHints.ts
Normal file
31
frontend/src/lib/ytBrandHints.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/** Google OAuth picker brand name ↔ YouTube channel (title/handle often differ). */
|
||||||
|
export const YT_OAUTH_BRAND_BY_HANDLE: Record<string, string> = {
|
||||||
|
"@ewfwefwefewf": "digitl nomad",
|
||||||
|
"@nomadstreetfood": "hackrobot-jp",
|
||||||
|
"@nomadrohub": "nomad Immigration",
|
||||||
|
"@evanstreetfood": "Nhat Vy",
|
||||||
|
"@nomadvloglife": "Lyca Hack",
|
||||||
|
"@walkingtour-c8t": "walking tour",
|
||||||
|
};
|
||||||
|
|
||||||
|
export function normalizeYtHandle(raw?: string | null): string {
|
||||||
|
const s = String(raw || "").trim();
|
||||||
|
if (!s) return "";
|
||||||
|
if (s.startsWith("@")) return s;
|
||||||
|
if (s.startsWith("UC")) return s;
|
||||||
|
return `@${s.replace(/^@/, "")}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function brandHintForChannel(profile?: { custom_url?: string; title?: string } | null, fallbackChannelId?: string, note?: string): string {
|
||||||
|
const fromNote = String(note || "").match(/Google品牌[::]\s*(.+)/i)?.[1]?.trim();
|
||||||
|
if (fromNote) return fromNote;
|
||||||
|
const handle = normalizeYtHandle(profile?.custom_url || fallbackChannelId);
|
||||||
|
if (handle && YT_OAUTH_BRAND_BY_HANDLE[handle]) return YT_OAUTH_BRAND_BY_HANDLE[handle];
|
||||||
|
const title = String(profile?.title || "").trim().toLowerCase();
|
||||||
|
if (title.includes("nomad vlog")) return "Lyca Hack";
|
||||||
|
if (title.includes("nomad street food")) return "hackrobot-jp";
|
||||||
|
if (title.includes("nomadro hub")) return "nomad Immigration";
|
||||||
|
if (title.includes("walking tour")) return "walking tour";
|
||||||
|
if (title.includes("nomdfsfbjksfbsjk")) return "digitl nomad";
|
||||||
|
return "";
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user