feat(monitor): 粘贴视频链接换出博主主页
Deploy VitePress site to Pages / build (push) Canceled after 0s
Deploy VitePress site to Pages / Deploy (push) Canceled after 0s

运营手上常常只有一条作品的分享链接,可监控任务认的是主页里的 sec_uid。

- 从整段分享文案里抠链接(链接前后都是字,按行切切不开),短链先展开,
  再从中取作品 id,最后用详情接口换 author.sec_uid
- 一次最多 20 条,串行 + 0.4 秒间隔;单条失败只在那一条上报错,不连累整批
- normalize_aweme 补上 creator_id:哈希拼不出主页地址,顺带让以后入库的
  抖音作品也带主页链接
- 监控页左上角「视频转主页」,支持逐条复制和一键复制全部(http 下没有
  navigator.clipboard,走 execCommand 兜底)
This commit is contained in:
2026-10-23 08:55:26 +08:00
parent 8e398a5ba1
commit 1474e5e3eb
12 changed files with 651 additions and 6 deletions
@@ -1,5 +1,5 @@
import { useState } from 'react'
import { Activity, BellRing, Download, FileText, MessageSquare, Plus } from 'lucide-react'
import { Activity, BellRing, Download, FileText, Link2, MessageSquare, Plus } from 'lucide-react'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
@@ -18,6 +18,7 @@ import { RunHistory } from './RunHistory'
import { StatTile } from './StatTile'
import { TaskCard } from './TaskCard'
import { TaskEditorDialog } from './TaskEditorDialog'
import { VideoLinkTool } from './VideoLinkTool'
export function MonitorDashboard() {
const { data: overview } = useMonitorOverview()
@@ -31,6 +32,7 @@ export function MonitorDashboard() {
const [selectedTaskId, setSelectedTaskId] = useState<number | null>(null)
const [editorOpen, setEditorOpen] = useState(false)
const [linkToolOpen, setLinkToolOpen] = useState(false)
const [editingTask, setEditingTask] = useState<MonitorTask | null>(null)
const [onlyNew, setOnlyNew] = useState(false)
// 选中的标签。空数组 = 不筛。
@@ -87,10 +89,22 @@ export function MonitorDashboard() {
<span className="font-mono text-xs tracking-wider text-cyber-text-primary">
监控任务
</span>
<Button size="sm" onClick={openCreate}>
<Plus className="w-3 h-3 mr-1" />
新建
</Button>
<div className="flex items-center gap-1">
{/* 手上只有一条作品链接时,先把它的号找出来 —— 建任务要的是主页里的 sec_uid。 */}
<Button
variant="outline"
size="sm"
onClick={() => setLinkToolOpen(true)}
title="粘贴视频链接,换出博主主页"
>
<Link2 className="w-3 h-3 mr-1" />
视频转主页
</Button>
<Button size="sm" onClick={openCreate}>
<Plus className="w-3 h-3 mr-1" />
新建
</Button>
</div>
</div>
<div className="flex-1 overflow-y-auto terminal-scroll space-y-2 pr-1">
@@ -217,6 +231,7 @@ export function MonitorDashboard() {
</div>
<TaskEditorDialog open={editorOpen} onOpenChange={setEditorOpen} task={editingTask} />
<VideoLinkTool open={linkToolOpen} onOpenChange={setLinkToolOpen} />
</div>
)
}
@@ -0,0 +1,189 @@
import { useMemo, useState } from 'react'
import { AlertTriangle, Check, Copy, ExternalLink, Link2, Loader2 } from 'lucide-react'
import { Button } from '@/components/ui/button'
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog'
import { useResolveVideoLinks } from '@/hooks/useMonitor'
import { copyText } from '@/lib/clipboard'
interface VideoLinkToolProps {
open: boolean
onOpenChange: (open: boolean) => void
}
const TEXTAREA_CLASS =
'w-full rounded-md border border-cyber-border-DEFAULT bg-cyber-bg-tertiary p-2 font-mono text-[11px] text-cyber-text-primary outline-none focus-visible:border-cyber-neon-cyan/50'
/**
* 粘贴视频链接 → 拿博主主页。
*
* 只读不写:解析出来的主页地址不会自动变成监控任务,建不建由人决定 —— 一次粘十几条
* 就顺手建十几个任务,不是这里该干的事。
*/
export function VideoLinkTool({ open, onOpenChange }: VideoLinkToolProps) {
const [text, setText] = useState('')
const [copied, setCopied] = useState('')
const resolve = useResolveVideoLinks()
const results = resolve.data?.results ?? []
const okCount = results.filter((item) => item.ok).length
// 同一个博主发了好几条时只留一行 —— 复制一堆重复地址没有意义。
const uniqueProfiles = useMemo(
() => Array.from(new Set(results.map((item) => item.profile_url).filter(Boolean))),
[results],
)
const copy = async (value: string) => {
if (await copyText(value)) {
setCopied(value)
window.setTimeout(() => setCopied(''), 1500)
}
}
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="max-w-2xl">
<DialogHeader>
<DialogTitle className="flex items-center gap-2 font-mono text-sm">
<Link2 className="h-4 w-4 text-cyber-neon-cyan" />
视频链接转博主主页
</DialogTitle>
<DialogDescription className="text-[11px] font-mono leading-relaxed">
粘贴抖音视频链接或分享文案,一行一条,一次最多 20 条。
解析走作品详情接口,需要一个能用的登录态。
</DialogDescription>
</DialogHeader>
<textarea
value={text}
onChange={(event) => setText(event.target.value)}
rows={5}
placeholder={
'https://www.douyin.com/video/7353137957861084427\n' +
'7.42 复制打开抖音,看看【某某的作品】 https://v.douyin.com/iAbCdEf/\n' +
'7353137957861084427'
}
className={TEXTAREA_CLASS}
/>
<div className="flex flex-wrap items-center gap-2">
<Button
size="sm"
onClick={() => resolve.mutate(text)}
disabled={!text.trim() || resolve.isPending}
>
{resolve.isPending ? (
<Loader2 className="mr-1 h-3 w-3 animate-spin" />
) : (
<Link2 className="mr-1 h-3 w-3" />
)}
{resolve.isPending ? '解析中…' : '解析'}
</Button>
{results.length > 0 && (
<>
<span className="font-mono text-[11px] text-cyber-text-muted">
共 {results.length} 条,成功 {okCount} 条,去重后 {uniqueProfiles.length} 个博主
</span>
<Button
variant="outline"
size="sm"
className="ml-auto"
disabled={uniqueProfiles.length === 0}
onClick={() => copy(uniqueProfiles.join('\n'))}
>
{copied === uniqueProfiles.join('\n') ? (
<Check className="mr-1 h-3 w-3" />
) : (
<Copy className="mr-1 h-3 w-3" />
)}
复制全部主页
</Button>
</>
)}
</div>
{resolve.data?.truncated && (
<p className="flex items-center gap-1 font-mono text-[11px] text-cyber-neon-orange">
<AlertTriangle className="h-3 w-3" />
超过 20 条,只解析了前面的 20 条。
</p>
)}
{results.length > 0 && (
<div className="max-h-[320px] space-y-1 overflow-y-auto terminal-scroll pr-1">
{results.map((item, index) => (
<div
key={`${item.input}-${index}`}
className="flex items-center gap-2 rounded-md border border-cyber-border-subtle bg-cyber-bg-tertiary/60 px-2 py-1.5"
>
<span
className={`h-1.5 w-1.5 flex-shrink-0 rounded-full ${
item.ok ? 'bg-cyber-neon-green' : 'bg-cyber-neon-pink'
}`}
/>
<div className="min-w-0 flex-1">
{item.ok ? (
<>
<div className="truncate font-mono text-[11px] text-cyber-text-primary">
{item.nickname || '(无昵称)'}
</div>
<a
href={item.profile_url}
target="_blank"
rel="noreferrer noopener"
className="block truncate font-mono text-[10px] text-cyber-neon-cyan hover:underline"
>
{item.profile_url}
</a>
</>
) : (
<>
<div className="truncate font-mono text-[10px] text-cyber-text-muted">
{item.input}
</div>
<div className="truncate font-mono text-[10px] text-cyber-neon-pink">
{item.error || '解析失败'}
</div>
</>
)}
</div>
{item.ok && (
<>
<Button
variant="ghost"
size="sm"
onClick={() => copy(item.profile_url)}
title="复制主页链接"
>
{copied === item.profile_url ? (
<Check className="h-3 w-3" />
) : (
<Copy className="h-3 w-3" />
)}
</Button>
<a
href={item.profile_url}
target="_blank"
rel="noreferrer noopener"
className="text-cyber-text-muted hover:text-cyber-neon-cyan"
title="在新标签页打开"
>
<ExternalLink className="h-3 w-3" />
</a>
</>
)}
</div>
))}
</div>
)}
</DialogContent>
</Dialog>
)
}
+10
View File
@@ -438,6 +438,16 @@ export function useSendDailyDigest() {
})
}
// --- 视频链接 → 博主主页 ---------------------------------------------------
export function useResolveVideoLinks() {
return useMutation({
mutationFn: async (text: string) => (await monitorApi.resolveVideoLinks(text)).data,
// 单条失败在结果里各自有 error,这里只管整批都没走到的情况(网络、鉴权)。
onError: (error: Error) => toast.error(`解析失败:${error.message}`),
})
}
// --- 博主备注 --------------------------------------------------------------
export function useSetCreatorAlias() {
+9
View File
@@ -20,6 +20,7 @@ import type {
SettingsResponse,
TaskCreatePayload,
UpstreamStatus,
VideoLinkResolveResponse,
WebhookStatus,
} from '@/types/monitor'
import type {
@@ -308,6 +309,14 @@ export const monitorApi = {
api.get<LoginState>('/monitor/login/state', { params: { force } }),
getWebhook: () => api.get<WebhookStatus>('/monitor/webhook'),
/**
* 视频链接/分享文案 → 博主主页。
*
* 后端逐条串行请求详情接口(一次最多 20 条),所以超时给得比默认的 30 秒宽 ——
* 按 30 秒算会把一批本来能解析完的链接误报成失败。
*/
resolveVideoLinks: (text: string) =>
api.post<VideoLinkResolveResponse>('/monitor/video-links', { text }, { timeout: 90_000 }),
/** 昨天视频情况图:手动发一次(每天早上那条由后端按设置触发)。 */
sendDailyDigest: (platform?: string) =>
api.post<{ ok: boolean; rows: number; detail: string }>('/monitor/digest/send', null, {
+35
View File
@@ -0,0 +1,35 @@
/**
* 复制文本。
*
* **必须留兜底**:这个站点是走 http://192.168.x.x:18051 访问的,不是安全上下文,
* 浏览器在这种情况下根本不提供 `navigator.clipboard`(不是拒绝,是 undefined)。
* 只写新 API 的话,局域网里点「复制」永远没反应。
*/
export async function copyText(value: string): Promise<boolean> {
if (!value) return false
if (window.isSecureContext && navigator.clipboard) {
try {
await navigator.clipboard.writeText(value)
return true
} catch {
// 落到下面的兜底
}
}
try {
const area = document.createElement('textarea')
area.value = value
// 定位到视口外而不是 display:none —— 隐藏元素选不中,复制会失败。
area.style.position = 'fixed'
area.style.top = '-1000px'
area.style.opacity = '0'
document.body.appendChild(area)
area.select()
const ok = document.execCommand('copy')
document.body.removeChild(area)
return ok
} catch {
return false
}
}
+21
View File
@@ -551,3 +551,24 @@ export interface MonitorIdentity {
last_ok_at: number | null
last_error: string | null
}
/**
* 「视频链接 → 博主主页」的一条结果。
*
* `ok` 为 false 时 `error` 一定有值 —— 批量粘贴时每条各自成败,不能整批共用一个错误。
*/
export interface VideoLinkResult {
input: string
aweme_id: string
ok: boolean
nickname: string
sec_uid: string
profile_url: string
error: string
}
export interface VideoLinkResolveResponse {
results: VideoLinkResult[]
/** 超过一次能解析的上限,后面的没处理 —— 前端要说出来,不能默默截断。 */
truncated: boolean
}