refactor: 将 WebUI 源码纳入仓库,移除打包产物

- 新增 webui/ 前端源码目录(React+Vite+TypeScript+Tailwind)
- 删除 api/webui/ 中旧的打包静态资源
- 更新 .gitignore 忽略 api/webui/ 构建输出和 webui/node_modules
- 更新 README 增加前端构建说明
This commit is contained in:
程序员阿江(Relakkes)
2026-07-01 23:05:03 +08:00
parent 2ac0716c41
commit 65ddaa8828
68 changed files with 9064 additions and 356 deletions
+74
View File
@@ -0,0 +1,74 @@
import { useState } from 'react'
import { Toaster } from 'sonner'
import { Sidebar } from '@/components/layout/Sidebar'
import { MainContent } from '@/components/layout/MainContent'
import { AuthorFooter } from '@/components/layout/AuthorFooter'
import { CrawlerConfigPanel } from '@/components/config/CrawlerConfigPanel'
import { EnvironmentCheck, isEnvChecked } from '@/components/env/EnvironmentCheck'
import { LicenseDisclaimer, isLicenseAccepted } from '@/components/license/LicenseDisclaimer'
function App() {
// Initialize by checking localStorage if license has been accepted
const [licenseAccepted, setLicenseAccepted] = useState(() => isLicenseAccepted())
// Initialize by checking localStorage if env check has passed
const [envChecked, setEnvChecked] = useState(() => isEnvChecked())
// State for showing disclaimer manually
const [showDisclaimer, setShowDisclaimer] = useState(false)
const handleEnvCheckComplete = () => {
setEnvChecked(true)
}
const handleLicenseAccept = () => {
setLicenseAccepted(true)
setShowDisclaimer(false)
}
const handleShowDisclaimer = () => {
setShowDisclaimer(true)
}
return (
<div className="flex flex-col h-screen cyber-grid overflow-hidden relative">
{/* License Disclaimer Modal - Shows first or when triggered */}
{(!licenseAccepted || showDisclaimer) && (
<LicenseDisclaimer onAccept={handleLicenseAccept} />
)}
{/* Environment Check Modal - Shows after license accepted */}
{licenseAccepted && !showDisclaimer && !envChecked && (
<EnvironmentCheck onCheckComplete={handleEnvCheckComplete} />
)}
{/* Header Bar */}
<Sidebar onShowDisclaimer={handleShowDisclaimer} />
{/* Main Area */}
<div className="flex-1 flex flex-col gap-4 p-4 overflow-hidden min-h-0">
{/* Config Panel - Primary Action Area (Always Expanded) */}
<div className="flex-shrink-0">
<CrawlerConfigPanel />
</div>
{/* Console - Collapsible Terminal */}
<MainContent />
</div>
{/* Author Footer */}
<AuthorFooter />
{/* Toast notifications - Theme-aware style */}
<Toaster
position="top-right"
toastOptions={{
className: 'glass-panel font-mono text-cyber-text-primary',
style: {
fontFamily: 'JetBrains Mono, monospace',
},
}}
/>
</div>
)
}
export default App
@@ -0,0 +1,415 @@
import type { ComponentType, ReactNode, KeyboardEvent } from 'react'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { Database, Globe, KeyRound, MessageSquare, Play, Square, X } from 'lucide-react'
import { Label } from '@/components/ui/label'
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
import { Input } from '@/components/ui/input'
import { Checkbox } from '@/components/ui/checkbox'
import { Button } from '@/components/ui/button'
import { useCrawlerStore } from '@/store/crawlerStore'
import { usePlatforms, useConfigOptions, useStartCrawler, useStopCrawler } from '@/hooks/useCrawler'
import { ParsedIdList } from './ParsedIdList'
type SectionProps = {
title: string
description: string
icon: ComponentType<{ className?: string }>
children: ReactNode
className?: string
}
function Section({ title, description, icon: Icon, children, className = '' }: SectionProps) {
return (
<section className={`rounded-lg glass-panel float-panel overflow-hidden ${className}`}>
<header className="px-4 py-3 border-b border-cyber-border-subtle/50 flex items-center gap-3 bg-cyber-bg-tertiary/30">
<div className="h-8 w-8 rounded-md bg-cyber-bg-tertiary border border-cyber-border-subtle flex items-center justify-center flex-shrink-0">
<Icon className="h-4 w-4 text-cyber-neon-cyan" />
</div>
<div className="min-w-0">
<div className="text-xs font-mono font-semibold text-cyber-text-primary tracking-wide">
{title}
</div>
<div className="text-[10px] text-cyber-text-muted leading-snug truncate">
{description}
</div>
</div>
</header>
<div className="p-4 space-y-4">
{children}
</div>
</section>
)
}
type FieldProps = {
label: string
hint?: string
children: ReactNode
}
function Field({ label, hint, children }: FieldProps) {
return (
<div className="space-y-2">
<div className="space-y-0.5">
<Label className="text-xs text-cyber-text-secondary font-mono">
{label}
</Label>
{hint ? (
<p className="text-[10px] text-cyber-text-muted leading-snug">
{hint}
</p>
) : null}
</div>
{children}
</div>
)
}
type KeywordInputProps = {
value: string
onChange: (value: string) => void
placeholder?: string
disabled?: boolean
}
function KeywordInput({ value, onChange, placeholder, disabled }: KeywordInputProps) {
const [inputValue, setInputValue] = useState('')
// 将逗号分隔的字符串转换为数组
const keywords = value ? value.split(',').map((k) => k.trim()).filter(Boolean) : []
const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
if (e.key === 'Enter') {
e.preventDefault()
const trimmed = inputValue.trim()
if (trimmed && !keywords.includes(trimmed)) {
const newKeywords = [...keywords, trimmed]
onChange(newKeywords.join(','))
setInputValue('')
}
}
}
const removeKeyword = (keywordToRemove: string) => {
const newKeywords = keywords.filter((k) => k !== keywordToRemove)
onChange(newKeywords.join(','))
}
return (
<div className="space-y-2">
<Input
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
onKeyDown={handleKeyDown}
placeholder={placeholder}
disabled={disabled}
className="h-9 text-xs"
/>
{keywords.length > 0 && (
<div className="flex flex-wrap gap-1.5">
{keywords.map((keyword) => (
<span
key={keyword}
className="inline-flex items-center gap-1 px-2 py-1 rounded-md bg-cyber-neon-cyan/10 border border-cyber-neon-cyan/30 text-cyber-neon-cyan text-xs font-mono"
>
{keyword}
{!disabled && (
<button
type="button"
onClick={() => removeKeyword(keyword)}
className="hover:text-cyber-neon-pink transition-colors"
>
<X className="w-3 h-3" />
</button>
)}
</span>
))}
</div>
)}
</div>
)
}
export function CrawlerConfigPanel() {
const { t } = useTranslation('config')
const config = useCrawlerStore((state) => state.config)
const updateConfig = useCrawlerStore((state) => state.updateConfig)
const status = useCrawlerStore((state) => state.status)
const { data: platforms } = usePlatforms()
const { data: options } = useConfigOptions()
const { mutate: startCrawler, isPending: isStarting } = useStartCrawler()
const { mutate: stopCrawler, isPending: isStopping } = useStopCrawler()
const isDisabled = status === 'running' || status === 'stopping'
const isRunning = status === 'running'
const isBusy = isStarting || isStopping || status === 'stopping'
const handleStart = () => {
startCrawler(config)
}
const handleStop = () => {
stopCrawler()
}
return (
<div className="space-y-4 animate-slide-up">
{/* Row 1: Three Config Columns */}
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
{/* Column 1: Target & Mode Section */}
<Section
title={t('section.targetMatrix.title')}
description={t('section.targetMatrix.description')}
icon={Globe}
>
<Field label={t('field.platform')}>
<Select
value={config.platform}
onValueChange={(value) => updateConfig({ platform: value })}
disabled={isDisabled}
>
<SelectTrigger className="h-9 text-xs">
<SelectValue placeholder={t('field.platformPlaceholder')} />
</SelectTrigger>
<SelectContent>
{platforms?.map((platform) => (
<SelectItem key={platform.value} value={platform.value}>
{platform.label}
</SelectItem>
))}
</SelectContent>
</Select>
</Field>
<div className="grid grid-cols-2 gap-3">
<Field label={t('field.crawlType')}>
<Select
value={config.crawler_type}
onValueChange={(value) => updateConfig({ crawler_type: value })}
disabled={isDisabled}
>
<SelectTrigger className="h-9 text-xs">
<SelectValue placeholder={t('field.crawlTypePlaceholder')} />
</SelectTrigger>
<SelectContent>
{options?.crawler_types.map((type) => (
<SelectItem key={type.value} value={type.value}>
{type.label}
</SelectItem>
))}
</SelectContent>
</Select>
</Field>
<Field label={t('field.startPage')}>
<Input
type="number"
min={1}
value={config.start_page}
onChange={(e) => updateConfig({ start_page: parseInt(e.target.value) || 1 })}
disabled={isDisabled}
className="h-9 text-xs"
/>
</Field>
</div>
{/* 根据爬虫类型显示不同的输入框 */}
{config.crawler_type === 'search' && (
<Field label={t('field.keywords')} hint={t('field.keywordsHint')}>
<KeywordInput
placeholder={t('field.keywordsPlaceholder')}
value={config.keywords}
onChange={(keywords) => updateConfig({ keywords })}
disabled={isDisabled}
/>
</Field>
)}
{config.crawler_type === 'detail' && (
<Field label={t('field.specifiedIds')} hint={t('field.specifiedIdsHint')}>
<textarea
value={config.specified_ids}
onChange={(e) => updateConfig({ specified_ids: e.target.value })}
disabled={isDisabled}
placeholder={t(`field.specifiedIdsPlaceholder.${config.platform}`, t('field.specifiedIdsPlaceholder.default'))}
className="min-h-[60px] w-full rounded-md border border-cyber-border-DEFAULT bg-cyber-bg-tertiary px-3 py-2 text-xs font-mono text-cyber-text-primary placeholder:text-cyber-text-muted focus-visible:outline-none focus-visible:border-cyber-neon-cyan/50 focus-visible:shadow-cyber-soft disabled:cursor-not-allowed disabled:opacity-50 transition-all resize-none"
/>
<ParsedIdList
value={config.specified_ids}
platform={config.platform}
type="detail"
disabled={isDisabled}
/>
{config.platform === 'xhs' && (
<div className="mt-2 rounded-lg border border-cyber-neon-orange/30 bg-cyber-neon-orange/5 p-2 text-[10px] leading-snug text-cyber-neon-orange font-mono">
{t('warning.xhsToken')}
</div>
)}
</Field>
)}
{config.crawler_type === 'creator' && (
<Field label={t('field.creatorIds')} hint={t('field.creatorIdsHint')}>
<textarea
value={config.creator_ids}
onChange={(e) => updateConfig({ creator_ids: e.target.value })}
disabled={isDisabled}
placeholder={t(`field.creatorIdsPlaceholder.${config.platform}`, t('field.creatorIdsPlaceholder.default'))}
className="min-h-[60px] w-full rounded-md border border-cyber-border-DEFAULT bg-cyber-bg-tertiary px-3 py-2 text-xs font-mono text-cyber-text-primary placeholder:text-cyber-text-muted focus-visible:outline-none focus-visible:border-cyber-neon-cyan/50 focus-visible:shadow-cyber-soft disabled:cursor-not-allowed disabled:opacity-50 transition-all resize-none"
/>
<ParsedIdList
value={config.creator_ids}
platform={config.platform}
type="creator"
disabled={isDisabled}
/>
{config.platform === 'xhs' && (
<div className="mt-2 rounded-lg border border-cyber-neon-orange/30 bg-cyber-neon-orange/5 p-2 text-[10px] leading-snug text-cyber-neon-orange font-mono">
{t('warning.xhsToken')}
</div>
)}
</Field>
)}
</Section>
{/* Column 2: Authentication Section */}
<Section
title={t('section.authMatrix.title')}
description={t('section.authMatrix.description')}
icon={KeyRound}
>
<Field label={t('field.loginMethod')}>
<Select
value={config.login_type}
onValueChange={(value) => updateConfig({ login_type: value })}
disabled={isDisabled}
>
<SelectTrigger className="h-9 text-xs">
<SelectValue placeholder={t('field.loginMethodPlaceholder')} />
</SelectTrigger>
<SelectContent>
{options?.login_types.map((type) => (
<SelectItem key={type.value} value={type.value}>
{type.label}
</SelectItem>
))}
</SelectContent>
</Select>
</Field>
{config.login_type === 'cookie' ? (
<Field label={t('field.cookies')} hint={t('field.cookiesHint')}>
<textarea
value={config.cookies}
onChange={(e) => updateConfig({ cookies: e.target.value })}
disabled={isDisabled}
placeholder={t('field.cookiesPlaceholder')}
className="min-h-[80px] w-full rounded-md border border-cyber-border-DEFAULT bg-cyber-bg-tertiary px-3 py-2 text-xs font-mono text-cyber-text-primary placeholder:text-cyber-text-muted focus-visible:outline-none focus-visible:border-cyber-neon-cyan/50 focus-visible:shadow-cyber-soft disabled:cursor-not-allowed disabled:opacity-50 transition-all resize-none"
/>
</Field>
) : null}
{config.login_type === 'cookie' && (config.platform === 'xhs' || config.platform === 'dy') ? (
<div className="rounded-lg border border-cyber-neon-orange/30 bg-cyber-neon-orange/5 p-3 text-[11px] leading-snug text-cyber-neon-orange font-mono">
{t('warning.cookieSlider')}
</div>
) : null}
</Section>
{/* Column 3: Output & Runtime Section */}
<Section
title={t('section.outputConfig.title')}
description={t('section.outputConfig.description')}
icon={Database}
>
<Field label={t('field.saveFormat')}>
<Select
value={config.save_option}
onValueChange={(value) => updateConfig({ save_option: value })}
disabled={isDisabled}
>
<SelectTrigger className="h-9 text-xs">
<SelectValue placeholder={t('field.saveFormatPlaceholder')} />
</SelectTrigger>
<SelectContent>
{options?.save_options.map((option) => (
<SelectItem key={option.value} value={option.value}>
{option.label}
</SelectItem>
))}
</SelectContent>
</Select>
</Field>
<div className="space-y-2">
<div className="flex items-center gap-3 rounded-lg border border-cyber-border-subtle bg-cyber-bg-tertiary/30 p-2.5 hover:border-cyber-border-DEFAULT transition-colors">
<Checkbox
checked={config.enable_comments}
onCheckedChange={(checked) => {
const isChecked = checked === true
updateConfig({
enable_comments: isChecked,
enable_sub_comments: isChecked ? config.enable_sub_comments : false,
})
}}
disabled={isDisabled}
/>
<div className="flex items-center gap-2">
<MessageSquare className="h-3.5 w-3.5 text-cyber-text-secondary" />
<p className="text-xs font-mono text-cyber-text-primary">{t('field.commentExtraction')}</p>
</div>
</div>
<div className="flex items-center gap-3 rounded-lg border border-cyber-border-subtle bg-cyber-bg-tertiary/30 p-2.5 hover:border-cyber-border-DEFAULT transition-colors">
<Checkbox
checked={config.enable_sub_comments}
onCheckedChange={(checked) => updateConfig({ enable_sub_comments: checked === true })}
disabled={isDisabled || !config.enable_comments}
/>
<p className="text-xs font-mono text-cyber-text-primary">{t('field.subComments')}</p>
</div>
<div className="flex items-center gap-3 rounded-lg border border-cyber-border-subtle bg-cyber-bg-tertiary/30 p-2.5 hover:border-cyber-border-DEFAULT transition-colors">
<Checkbox
checked={config.headless}
onCheckedChange={(checked) => updateConfig({ headless: checked === true })}
disabled={isDisabled}
/>
<div className="min-w-0 flex-1">
<p className="text-xs font-mono text-cyber-text-primary">{t('field.headlessMode')}</p>
<p className="text-[10px] text-cyber-text-muted leading-snug">
{t('field.headlessModeHint')}
</p>
</div>
</div>
</div>
</Section>
</div>
{/* Row 2: Start/Stop Button - Full Width */}
<div className="w-full">
{isRunning ? (
<Button
onClick={handleStop}
disabled={isBusy}
className="w-full h-12 bg-cyber-neon-pink text-white font-mono font-bold text-sm tracking-wider hover:bg-cyber-neon-pink/90 hover:shadow-glow-pink-sm transition-all"
>
<Square className="w-4 h-4" />
{isStopping ? t('button.stopping') : t('button.terminate')}
</Button>
) : (
<Button
onClick={handleStart}
disabled={isBusy}
className="w-full h-12 bg-cyber-neon-cyan text-cyber-bg-primary font-mono font-bold text-sm tracking-wider hover:bg-cyber-neon-cyan/90 hover:shadow-glow-cyan-sm transition-all"
>
<Play className="w-4 h-4" />
{isStarting ? t('button.initiating') : t('button.initiateScan')}
</Button>
)}
</div>
</div>
)
}
@@ -0,0 +1,96 @@
import { useMemo } from 'react'
import { Check, AlertTriangle, X } from 'lucide-react'
import { parseMultipleUrls, type ParsedId } from '@/lib/urlParser'
interface ParsedIdListProps {
value: string
platform: string
type: 'detail' | 'creator'
onRemove?: (index: number) => void
disabled?: boolean
}
export function ParsedIdList({ value, platform, type, onRemove, disabled }: ParsedIdListProps) {
const parsed = useMemo(() => {
return parseMultipleUrls(value, platform)
}, [value, platform])
if (parsed.length === 0) return null
const handleRemove = (index: number) => {
if (disabled || !onRemove) return
const items = value
.split(/[,\n]+/)
.map(s => s.trim())
.filter(Boolean)
items.splice(index, 1)
onRemove(index)
}
return (
<div className="space-y-1.5 mt-2">
<div className="text-[10px] text-cyber-text-muted font-mono">
已识别 {parsed.length} 个{type === 'detail' ? '帖子/视频' : '创作者'}:
</div>
<div className="flex flex-wrap gap-1.5">
{parsed.map((item, index) => (
<ParsedIdTag
key={`${item.id}-${index}`}
item={item}
expectedType={type}
onRemove={!disabled ? () => handleRemove(index) : undefined}
/>
))}
</div>
</div>
)
}
interface ParsedIdTagProps {
item: ParsedId
expectedType: 'detail' | 'creator'
onRemove?: () => void
}
function ParsedIdTag({ item, expectedType, onRemove }: ParsedIdTagProps) {
// 检查类型是否匹配
const typeMatch = item.type === 'unknown' ||
(expectedType === 'detail' && item.type === 'video') ||
(expectedType === 'creator' && item.type === 'creator')
// 警告状态:小红书需要xsec_token
const needsWarning = !item.isValid || !typeMatch
return (
<span
className={`
inline-flex items-center gap-1 px-2 py-1 rounded-md text-[10px] font-mono
${needsWarning
? 'bg-cyber-neon-orange/10 border border-cyber-neon-orange/30 text-cyber-neon-orange'
: 'bg-cyber-neon-cyan/10 border border-cyber-neon-cyan/30 text-cyber-neon-cyan'
}
`}
title={item.original}
>
{needsWarning ? (
<AlertTriangle className="w-3 h-3 flex-shrink-0" />
) : (
<Check className="w-3 h-3 flex-shrink-0" />
)}
<span className="max-w-[120px] truncate">
{item.id.length > 20 ? item.id.slice(0, 8) + '...' + item.id.slice(-8) : item.id}
</span>
{onRemove && (
<button
type="button"
onClick={onRemove}
className="hover:text-cyber-neon-pink transition-colors ml-0.5"
>
<X className="w-3 h-3" />
</button>
)}
</span>
)
}
+151
View File
@@ -0,0 +1,151 @@
import { useState, useEffect, useRef } from 'react'
import { useTranslation } from 'react-i18next'
import { ChevronDown, ChevronUp, Trash2, RefreshCw } from 'lucide-react'
import { TerminalLine } from './TerminalLine'
import { useCrawlerStore } from '@/store/crawlerStore'
import { Button } from '@/components/ui/button'
import { DataExplorerDialog } from '@/components/data/DataExplorerDialog'
export function Terminal() {
const { t } = useTranslation('terminal')
const [isCollapsed, setIsCollapsed] = useState(false)
const logs = useCrawlerStore((state) => state.logs)
const clearLogs = useCrawlerStore((state) => state.clearLogs)
const restoreLogs = useCrawlerStore((state) => state.restoreLogs)
const clearedAfterLogId = useCrawlerStore((state) => state.clearedAfterLogId)
const status = useCrawlerStore((state) => state.status)
const scrollRef = useRef<HTMLDivElement>(null)
// Auto scroll to bottom
useEffect(() => {
if (scrollRef.current && !isCollapsed) {
scrollRef.current.scrollTop = scrollRef.current.scrollHeight
}
}, [logs, isCollapsed])
return (
<div className={`flex flex-col rounded-lg overflow-hidden transition-all duration-300 border border-cyber-border-subtle bg-[#0d1117] ${isCollapsed ? 'h-12' : 'h-full'}`}>
{/* Terminal Header */}
<div className="flex items-center justify-between px-4 py-2.5 bg-[#161b22] border-b border-[#30363d] flex-shrink-0">
<div className="flex items-center gap-3">
{/* Window buttons */}
<div className="flex gap-1.5">
<span className="w-2.5 h-2.5 rounded-full bg-cyber-neon-pink/80" />
<span className="w-2.5 h-2.5 rounded-full bg-cyber-neon-orange/80" />
<span className="w-2.5 h-2.5 rounded-full bg-cyber-neon-green/80" />
</div>
<span className="text-xs text-[#8b949e] font-mono tracking-wider">
{t('header.title')}
</span>
</div>
<div className="flex items-center gap-3">
{/* Log count & status */}
<div className="flex items-center gap-3 text-xs font-mono">
<span className="text-[#8b949e]">{t('header.entries', { count: logs.length })}</span>
{status === 'running' && (
<div className="flex items-center gap-1.5">
<span className="w-1.5 h-1.5 bg-cyber-neon-green rounded-full shadow-glow-green-sm animate-pulse-fast" />
<span className="text-cyber-neon-green">{t('header.active')}</span>
</div>
)}
</div>
{/* Data Explorer */}
<DataExplorerDialog />
{/* Restore logs - 只在有清除标记时显示 */}
{clearedAfterLogId !== null && (
<Button
variant="ghost"
size="sm"
onClick={restoreLogs}
className="h-7 px-2 text-[#8b949e] hover:text-[#00ffff] hover:bg-[#00ffff]/10"
title={t('header.restore')}
>
<RefreshCw className="w-4 h-4" />
</Button>
)}
{/* Clear logs */}
<Button
variant="ghost"
size="sm"
onClick={clearLogs}
disabled={logs.length === 0}
className="h-7 px-2 text-[#8b949e] hover:text-[#ff0080] hover:bg-[#ff0080]/10 disabled:opacity-30"
title={t('header.clear')}
>
<Trash2 className="w-4 h-4" />
</Button>
{/* Collapse toggle */}
<Button
variant="ghost"
size="sm"
onClick={() => setIsCollapsed(!isCollapsed)}
className="h-7 px-2 text-[#8b949e] hover:text-[#00ffff] hover:bg-[#00ffff]/10"
>
{isCollapsed ? (
<ChevronDown className="w-4 h-4" />
) : (
<ChevronUp className="w-4 h-4" />
)}
</Button>
</div>
</div>
{/* Terminal Content - only show when not collapsed */}
{!isCollapsed && (
<>
<div
ref={scrollRef}
className="flex-1 overflow-auto p-4 font-mono text-sm terminal-scroll bg-[#0d1117] min-h-0"
>
{/* ASCII Art Banner when empty */}
{logs.length === 0 ? (
<div className="space-y-4">
<pre className="text-cyber-neon-cyan/70 text-xs leading-tight">
{` ╔══════════════════════════════════════════════════════╗
║ __ __ _ _ ____ ║
║ | \\/ | ___ __| (_) __ _/ ___|_ __ __ ___ __ ║
║ | |\\/| |/ _ \\/ _\` | |/ _\` | | | '__/ _\` \\ \\ /\\ / / ║
║ | | | | __/ (_| | | (_| | |___| | | (_| |\\ V V / ║
║ |_| |_|\\___|\\__,_|_|\\__,_|\\____|_| \\__,_| \\_/\\_/ ║
║ ║
║ [ NEURAL EXTRACTION UNIT v1.0 ] ║
╚══════════════════════════════════════════════════════╝`}
</pre>
<div className="text-[#c9d1d9] text-xs space-y-1">
<p className="text-cyber-neon-green/70">{t('banner.systemInit')}</p>
<p className="text-[#8b949e]">{t('banner.configHint')}</p>
</div>
</div>
) : (
<div className="space-y-0.5">
{logs.map((log) => (
<TerminalLine key={log.id} log={log} />
))}
</div>
)}
{/* Active Cursor */}
{status === 'running' && (
<div className="flex items-center gap-1 mt-3">
<span className="text-cyber-neon-green/80">root@crawler:~$</span>
<span className="w-2 h-4 bg-cyber-neon-green/80 cursor-blink" />
</div>
)}
</div>
{/* Terminal Footer */}
<div className="px-4 py-2 border-t border-[#30363d] bg-[#161b22] flex items-center justify-end flex-shrink-0">
<div className="text-xs font-mono text-[#8b949e]">
{status.toUpperCase()}
</div>
</div>
</>
)}
</div>
)
}
@@ -0,0 +1,70 @@
import { cn } from '@/lib/utils'
import type { LogEntry } from '@/types/crawler'
interface TerminalLineProps {
log: LogEntry
}
const levelConfig: Record<string, { text: string; bg: string; glow: string }> = {
info: {
text: 'text-cyber-neon-cyan',
bg: 'bg-cyber-neon-cyan/10',
glow: 'shadow-[0_0_3px_rgba(0,255,255,0.3)]'
},
success: {
text: 'text-cyber-neon-green',
bg: 'bg-cyber-neon-green/10',
glow: 'shadow-[0_0_3px_rgba(0,255,65,0.3)]'
},
warning: {
text: 'text-cyber-neon-orange',
bg: 'bg-cyber-neon-orange/10',
glow: 'shadow-[0_0_3px_rgba(255,152,0,0.3)]'
},
error: {
text: 'text-cyber-neon-pink',
bg: 'bg-cyber-neon-pink/10',
glow: 'shadow-[0_0_3px_rgba(255,0,128,0.3)]'
},
debug: {
text: 'text-[#8b949e]',
bg: 'bg-[#21262d]',
glow: ''
},
}
const levelIcons: Record<string, string> = {
info: 'DATA',
success: 'OK',
warning: 'WARN',
error: 'ERR',
debug: 'DBG',
}
export function TerminalLine({ log }: TerminalLineProps) {
const config = levelConfig[log.level] || levelConfig.info
return (
<div className="flex gap-2 text-xs leading-relaxed font-mono group hover:bg-[#21262d]/50 px-1 -mx-1 rounded transition-colors">
{/* Timestamp */}
<span className="text-[#8b949e] flex-shrink-0 opacity-60 group-hover:opacity-100 transition-opacity">
[{log.timestamp}]
</span>
{/* Level badge */}
<span className={cn(
'flex-shrink-0 w-14 px-1 rounded text-center',
config.bg,
config.text,
config.glow
)}>
[{levelIcons[log.level]}]
</span>
{/* Message */}
<span className={cn('break-all', config.text)}>
{log.message}
</span>
</div>
)
}
+157
View File
@@ -0,0 +1,157 @@
import { useState, useMemo } from 'react'
import { useQuery } from '@tanstack/react-query'
import { useTranslation } from 'react-i18next'
import { FolderOpen, RefreshCw } from 'lucide-react'
import { dataApi } from '@/lib/api'
import { FileCard } from './FileCard'
import { Button } from '@/components/ui/button'
import { Badge } from '@/components/ui/badge'
// 从文件名提取类别
function extractCategory(filename: string): string {
// 文件名格式: search_comments_xxx, search_creators_xxx, search_videos_xxx 等
const match = filename.match(/^(search_\w+?)_/)
if (match) {
return match[1]
}
// 其他格式尝试提取前缀
const parts = filename.split('_')
if (parts.length >= 2) {
return `${parts[0]}_${parts[1]}`
}
return 'other'
}
// 类别显示名称
function getCategoryLabel(category: string): string {
const labels: Record<string, string> = {
'search_comments': 'Comments',
'search_creators': 'Creators',
'search_videos': 'Videos',
'search_contents': 'Contents',
'search_notes': 'Notes',
'other': 'Other',
}
return labels[category] || category.replace(/_/g, ' ').replace(/\b\w/g, c => c.toUpperCase())
}
export function DataExplorer() {
const { t } = useTranslation('data')
const [activeTab, setActiveTab] = useState<string>('all')
const { data, isLoading, refetch, isRefetching } = useQuery({
queryKey: ['dataFiles'],
queryFn: async () => {
const { data } = await dataApi.getFiles()
return data.files
},
})
const files = data || []
// 按类别分组文件
const { categories, groupedFiles } = useMemo(() => {
const grouped: Record<string, typeof files> = {}
files.forEach(file => {
const category = extractCategory(file.name)
if (!grouped[category]) {
grouped[category] = []
}
grouped[category].push(file)
})
// 按文件数量排序类别
const sortedCategories = Object.keys(grouped).sort((a, b) =>
grouped[b].length - grouped[a].length
)
return { categories: sortedCategories, groupedFiles: grouped }
}, [files])
// 当前显示的文件
const displayFiles = activeTab === 'all' ? files : (groupedFiles[activeTab] || [])
return (
<div className="h-full flex flex-col">
{/* Header */}
<div className="flex items-center justify-between mb-4">
<div className="flex items-center gap-3">
<h2 className="text-lg font-mono font-bold text-cyber-neon-cyan glow-text-cyan tracking-wider">
{t('explorer.title')}
</h2>
<Badge variant="default" className="font-mono">
{t('explorer.records', { count: files.length })}
</Badge>
</div>
<Button
variant="outline"
size="sm"
onClick={() => refetch()}
disabled={isRefetching}
className="font-mono"
>
<RefreshCw className={`w-4 h-4 ${isRefetching ? 'animate-spin' : ''}`} />
{t('explorer.rescan')}
</Button>
</div>
{/* Category Tabs */}
{files.length > 0 && categories.length > 1 && (
<div className="flex items-center gap-2 mb-4 flex-wrap">
<button
onClick={() => setActiveTab('all')}
className={`px-3 py-1.5 rounded-md text-xs font-mono transition-all ${
activeTab === 'all'
? 'bg-cyber-neon-cyan text-black font-bold'
: 'bg-cyber-bg-tertiary text-cyber-text-secondary hover:text-cyber-text-primary border border-cyber-border-subtle hover:border-cyber-neon-cyan/50'
}`}
>
{t('explorer.allCategories')} ({files.length})
</button>
{categories.map(category => (
<button
key={category}
onClick={() => setActiveTab(category)}
className={`px-3 py-1.5 rounded-md text-xs font-mono transition-all ${
activeTab === category
? 'bg-cyber-neon-cyan text-black font-bold'
: 'bg-cyber-bg-tertiary text-cyber-text-secondary hover:text-cyber-text-primary border border-cyber-border-subtle hover:border-cyber-neon-cyan/50'
}`}
>
{getCategoryLabel(category)} ({groupedFiles[category].length})
</button>
))}
</div>
)}
{/* Content */}
{isLoading ? (
<div className="flex-1 flex items-center justify-center">
<div className="text-cyber-text-muted font-mono animate-pulse">
{t('explorer.loading')}
</div>
</div>
) : files.length === 0 ? (
<div className="flex-1 flex flex-col items-center justify-center text-center">
<div className="relative">
<FolderOpen className="w-16 h-16 text-cyber-neon-cyan/30 mb-4" />
<div className="absolute inset-0 blur-xl bg-cyber-neon-cyan/10" />
</div>
<h3 className="text-lg font-mono font-medium text-cyber-neon-cyan mb-2">
{t('explorer.noData')}
</h3>
<p className="text-sm text-cyber-text-muted max-w-md font-mono">
{t('explorer.noDataHint')}
</p>
</div>
) : (
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
{displayFiles.map((file) => (
<FileCard key={file.path} file={file} />
))}
</div>
)}
</div>
)
}
@@ -0,0 +1,38 @@
import { useTranslation } from 'react-i18next'
import { Database } from 'lucide-react'
import { Button } from '@/components/ui/button'
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogTrigger,
} from '@/components/ui/dialog'
import { DataExplorer } from './DataExplorer'
export function DataExplorerDialog() {
const { t } = useTranslation('data')
return (
<Dialog>
<DialogTrigger asChild>
<Button
variant="outline"
size="sm"
className="font-mono text-xs text-[#c9d1d9] border-[#30363d] bg-transparent hover:bg-[#21262d] hover:text-[#00ffff] hover:border-[#00ffff]/50"
>
<Database className="w-3.5 h-3.5" />
{t('dialog.button')}
</Button>
</DialogTrigger>
<DialogContent className="max-w-5xl max-h-[85vh] overflow-hidden">
<DialogHeader>
<DialogTitle>{t('dialog.title')}</DialogTitle>
</DialogHeader>
<div className="overflow-auto max-h-[calc(85vh-100px)] pr-2">
<DataExplorer />
</div>
</DialogContent>
</Dialog>
)
}
+132
View File
@@ -0,0 +1,132 @@
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { FileJson, FileSpreadsheet, FileText, Download, Eye } from 'lucide-react'
import { Card, CardContent } from '@/components/ui/card'
import { Button } from '@/components/ui/button'
import { Badge } from '@/components/ui/badge'
import { dataApi } from '@/lib/api'
import { formatFileSize, formatDateTime } from '@/lib/utils'
import { DataPreviewDialog } from './preview/DataPreviewDialog'
import type { DataFile } from '@/types/crawler'
interface FileCardProps {
file: DataFile
}
const fileIcons: Record<string, typeof FileJson> = {
json: FileJson,
csv: FileSpreadsheet,
xlsx: FileSpreadsheet,
xls: FileSpreadsheet,
}
const fileStyles: Record<string, { icon: string; border: string; badge: string }> = {
json: {
icon: 'text-cyber-neon-yellow',
border: 'hover:border-cyber-neon-yellow/50',
badge: 'border-cyber-neon-yellow/30 bg-cyber-neon-yellow/10 text-cyber-neon-yellow'
},
csv: {
icon: 'text-cyber-neon-green',
border: 'hover:border-cyber-neon-green/50',
badge: 'border-cyber-neon-green/30 bg-cyber-neon-green/10 text-cyber-neon-green'
},
xlsx: {
icon: 'text-cyber-neon-cyan',
border: 'hover:border-cyber-neon-cyan/50',
badge: 'border-cyber-neon-cyan/30 bg-cyber-neon-cyan/10 text-cyber-neon-cyan'
},
xls: {
icon: 'text-cyber-neon-cyan',
border: 'hover:border-cyber-neon-cyan/50',
badge: 'border-cyber-neon-cyan/30 bg-cyber-neon-cyan/10 text-cyber-neon-cyan'
},
}
export function FileCard({ file }: FileCardProps) {
const { t } = useTranslation('data')
const [previewOpen, setPreviewOpen] = useState(false)
const Icon = fileIcons[file.type] || FileText
const styles = fileStyles[file.type] || {
icon: 'text-cyber-text-muted',
border: 'hover:border-cyber-neon-cyan/50',
badge: 'border-cyber-border-DEFAULT bg-cyber-bg-tertiary text-cyber-text-secondary'
}
// 检查是否支持预览
const isPreviewable = ['json', 'csv', 'xlsx', 'xls'].includes(file.type.toLowerCase())
const handleDownload = () => {
const url = dataApi.getDownloadUrl(file.path)
window.open(url, '_blank')
}
return (
<>
<Card className={`relative overflow-hidden card-scan group transition-all ${styles.border} hover:shadow-[0_0_15px_rgb(var(--cyber-neon-cyan)/0.15)]`}>
{/* Scan effect overlay */}
<div className="absolute inset-0 bg-gradient-to-r from-transparent via-cyber-neon-cyan/5 to-transparent -translate-x-full group-hover:translate-x-full transition-transform duration-700 pointer-events-none" />
<CardContent className="p-4 relative">
<div className="flex items-start gap-3">
<div className={`p-2 rounded bg-cyber-bg-panel border border-cyber-border-DEFAULT ${styles.icon}`}>
<Icon className="w-6 h-6" />
</div>
<div className="flex-1 min-w-0">
<h3 className="font-mono font-medium text-sm text-cyber-text-primary truncate" title={file.name}>
{file.name}
</h3>
<p className="text-xs text-cyber-text-muted mt-1 font-mono">
{formatFileSize(file.size)}
{file.record_count !== null && (
<span className="text-cyber-neon-green"> | {t('file.entries', { count: file.record_count })}</span>
)}
</p>
<p className="text-xs text-cyber-text-muted mt-1 font-mono">
{formatDateTime(file.modified_at)}
</p>
</div>
</div>
<div className="flex items-center justify-between mt-3 pt-3 border-t border-cyber-border-subtle">
<Badge variant="outline" className={`text-[10px] font-mono ${styles.badge}`}>
.{file.type.toUpperCase()}
</Badge>
<div className="flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity">
{isPreviewable && (
<Button
variant="ghost"
size="sm"
className="h-7 px-2 font-mono text-cyber-neon-cyan hover:text-cyber-neon-cyan hover:bg-cyber-neon-cyan/10"
onClick={() => setPreviewOpen(true)}
>
<Eye className="w-3 h-3 mr-1" />
{t('file.preview')}
</Button>
)}
<Button
variant="ghost"
size="sm"
className="h-7 px-2 font-mono text-cyber-neon-cyan hover:text-cyber-neon-cyan hover:bg-cyber-neon-cyan/10"
onClick={handleDownload}
>
<Download className="w-3 h-3 mr-1" />
{t('file.extract')}
</Button>
</div>
</div>
</CardContent>
</Card>
{/* 预览对话框 */}
{isPreviewable && (
<DataPreviewDialog
file={file}
open={previewOpen}
onOpenChange={setPreviewOpen}
/>
)}
</>
)
}
@@ -0,0 +1,93 @@
import { useQuery } from '@tanstack/react-query'
import { useTranslation } from 'react-i18next'
import { Download } from 'lucide-react'
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog'
import { Button } from '@/components/ui/button'
import { Badge } from '@/components/ui/badge'
import { dataApi } from '@/lib/api'
import { DataPreviewTable } from './DataPreviewTable'
import type { DataFile } from '@/types/crawler'
interface DataPreviewDialogProps {
file: DataFile
open: boolean
onOpenChange: (open: boolean) => void
}
export function DataPreviewDialog({ file, open, onOpenChange }: DataPreviewDialogProps) {
const { t } = useTranslation('data')
const { data, isLoading, error } = useQuery({
queryKey: ['filePreview', file.path],
queryFn: async () => {
const { data } = await dataApi.getFileContent(file.path, 100)
return data
},
enabled: open,
})
const handleDownload = () => {
const url = dataApi.getDownloadUrl(file.path)
window.open(url, '_blank')
}
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="max-w-6xl max-h-[85vh] flex flex-col">
<DialogHeader className="flex-shrink-0">
<div className="flex items-center justify-between">
<div className="flex items-center gap-3">
<DialogTitle className="font-mono text-cyber-neon-cyan">
{file.name}
</DialogTitle>
<Badge variant="outline" className="font-mono text-[10px]">
.{file.type.toUpperCase()}
</Badge>
{data && (
<Badge variant="default" className="font-mono text-[10px]">
{t('preview.records', { count: data.total })}
</Badge>
)}
</div>
<Button
variant="outline"
size="sm"
onClick={handleDownload}
className="font-mono text-xs"
>
<Download className="w-3 h-3 mr-1" />
{t('preview.download')}
</Button>
</div>
</DialogHeader>
{/* 内容区域 */}
<div className="flex-1 overflow-hidden min-h-0 mt-4">
{isLoading ? (
<div className="flex items-center justify-center h-full">
<div className="text-cyber-text-muted font-mono animate-pulse">
{t('preview.loading')}
</div>
</div>
) : error ? (
<div className="flex items-center justify-center h-full">
<div className="text-cyber-neon-pink font-mono">
{t('preview.error')}
</div>
</div>
) : data ? (
<DataPreviewTable
data={data.data}
columns={data.columns}
/>
) : null}
</div>
</DialogContent>
</Dialog>
)
}
@@ -0,0 +1,104 @@
import { useMemo, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { Search } from 'lucide-react'
import { ScrollArea } from '@/components/ui/scroll-area'
import { Input } from '@/components/ui/input'
interface DataPreviewTableProps {
data: Record<string, unknown>[]
columns?: string[]
}
export function DataPreviewTable({ data, columns: propColumns }: DataPreviewTableProps) {
const { t } = useTranslation('data')
const [searchTerm, setSearchTerm] = useState('')
// 自动获取列名(JSON 可能没有 columns)
const columns = useMemo(() => {
if (propColumns && propColumns.length > 0) return propColumns
if (data.length === 0) return []
return Object.keys(data[0])
}, [data, propColumns])
// 过滤数据
const filteredData = useMemo(() => {
if (!searchTerm) return data
const term = searchTerm.toLowerCase()
return data.filter(row =>
Object.values(row).some(value =>
String(value ?? '').toLowerCase().includes(term)
)
)
}, [data, searchTerm])
// 格式化单元格值
const formatCellValue = (value: unknown): string => {
if (value === null || value === undefined) return '-'
if (typeof value === 'object') return JSON.stringify(value)
return String(value)
}
return (
<div className="h-full flex flex-col">
{/* 搜索栏 */}
<div className="flex-shrink-0 mb-3">
<div className="relative">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-cyber-text-muted" />
<Input
placeholder={t('preview.searchPlaceholder')}
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
className="pl-9 h-9 text-xs font-mono"
/>
</div>
</div>
{/* 表格 */}
<ScrollArea className="flex-1 border border-cyber-border-DEFAULT rounded-lg">
<div className="min-w-full">
<table className="w-full text-xs font-mono">
<thead className="sticky top-0 bg-cyber-bg-tertiary border-b border-cyber-border-DEFAULT">
<tr>
<th className="px-3 py-2 text-left text-cyber-text-muted w-12">#</th>
{columns.map((col) => (
<th
key={col}
className="px-3 py-2 text-left text-cyber-neon-cyan whitespace-nowrap"
>
{col}
</th>
))}
</tr>
</thead>
<tbody>
{filteredData.map((row, idx) => (
<tr
key={idx}
className="border-b border-cyber-border-subtle hover:bg-cyber-bg-elevated/50 transition-colors"
>
<td className="px-3 py-2 text-cyber-text-muted">{idx + 1}</td>
{columns.map((col) => (
<td
key={col}
className="px-3 py-2 text-cyber-text-primary max-w-xs truncate"
title={formatCellValue(row[col])}
>
{formatCellValue(row[col])}
</td>
))}
</tr>
))}
</tbody>
</table>
</div>
</ScrollArea>
{/* 过滤结果提示 */}
{searchTerm && (
<div className="flex-shrink-0 mt-2 text-xs text-cyber-text-muted font-mono">
{t('preview.showing', { filtered: filteredData.length, total: data.length })}
</div>
)}
</div>
)
}
@@ -0,0 +1,80 @@
import { useTranslation } from 'react-i18next'
import { Sparkles, Heart } from 'lucide-react'
export function AuthorFooter() {
const { t } = useTranslation('license')
return (
<footer className="h-24 flex-shrink-0 glass-panel border-t border-cyber-border-subtle">
<div className="h-full px-6 flex items-center justify-center gap-6">
{/* Author Avatar */}
<div className="w-14 h-14 rounded-lg overflow-hidden border-2 border-cyber-neon-cyan/60 flex-shrink-0 shadow-glow-cyan-sm">
<img
src="/logos/my_logo.png"
alt="程序员阿江-Relakkes"
className="w-full h-full object-cover"
/>
</div>
{/* Author Info */}
<div className="flex flex-col gap-1">
<div className="flex items-center gap-2">
<span className="text-lg font-bold text-cyber-text-primary">
{t('author.name')}
</span>
<Sparkles className="w-5 h-5 text-cyber-neon-cyan animate-pulse" />
</div>
<span className="text-sm text-cyber-text-muted hidden sm:inline">
{t('author.description')}
</span>
<div className="flex items-center gap-2 text-cyber-neon-cyan">
<Heart className="w-4 h-4 fill-current animate-pulse" />
<span className="text-sm font-medium">
{t('author.slogan')}
</span>
</div>
</div>
{/* Social Links */}
<div className="flex items-center gap-3">
<a
href="https://github.com/NanmiCoder"
target="_blank"
rel="noopener noreferrer"
className="w-11 h-11 rounded-lg flex items-center justify-center border border-cyber-border-subtle hover:border-cyber-neon-cyan hover:shadow-glow-cyan-sm transition-all bg-cyber-bg-tertiary hover:scale-110"
title="GitHub"
>
<img src="/logos/github.png" alt="GitHub" className="w-6 h-6 object-contain" />
</a>
<a
href="https://space.bilibili.com/434377496"
target="_blank"
rel="noopener noreferrer"
className="w-11 h-11 rounded-lg flex items-center justify-center border border-cyber-border-subtle hover:border-pink-400 hover:shadow-[0_0_10px_rgba(251,113,133,0.4)] transition-all bg-cyber-bg-tertiary hover:scale-110"
title="哔哩哔哩"
>
<img src="/logos/bilibili_logo.png" alt="Bilibili" className="w-6 h-6 object-contain" />
</a>
<a
href="https://www.xiaohongshu.com/user/profile/5f58bd990000000001003753"
target="_blank"
rel="noopener noreferrer"
className="w-11 h-11 rounded-lg flex items-center justify-center border border-cyber-border-subtle hover:border-red-400 hover:shadow-[0_0_10px_rgba(248,113,113,0.4)] transition-all bg-cyber-bg-tertiary hover:scale-110"
title="小红书"
>
<img src="/logos/xiaohongshu_logo.png" alt="小红书" className="w-6 h-6 object-contain" />
</a>
<a
href="https://www.douyin.com/user/MS4wLjABAAAATJPY7LAlaa5X-c8uNdWkvz0jUGgpw4eeXIwu_8BhvqE"
target="_blank"
rel="noopener noreferrer"
className="w-11 h-11 rounded-lg flex items-center justify-center border border-cyber-border-subtle hover:border-cyber-text-primary hover:shadow-[0_0_10px_rgba(255,255,255,0.3)] transition-all bg-cyber-bg-tertiary hover:scale-110"
title="抖音"
>
<img src="/logos/douyin.png" alt="抖音" className="w-6 h-6 object-contain" />
</a>
</div>
</div>
</footer>
)
}
@@ -0,0 +1,36 @@
import { Globe } from 'lucide-react'
import { useTranslation } from 'react-i18next'
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select'
const languages = [
{ code: 'zh-CN', label: '中文' },
{ code: 'en-US', label: 'EN' },
]
export function LanguageSwitch() {
const { i18n } = useTranslation()
const currentLang = languages.find(l => l.code === i18n.language) || languages[0]
return (
<Select value={i18n.language} onValueChange={(lang) => i18n.changeLanguage(lang)}>
<SelectTrigger className="w-20 h-7 text-xs font-mono border-cyber-border-subtle bg-cyber-bg-tertiary/50 hover:border-cyber-neon-cyan/50 transition-colors">
<Globe className="w-3 h-3 mr-1 text-cyber-text-secondary" />
<SelectValue>{currentLang.label}</SelectValue>
</SelectTrigger>
<SelectContent>
{languages.map((lang) => (
<SelectItem key={lang.code} value={lang.code} className="text-xs font-mono">
{lang.label}
</SelectItem>
))}
</SelectContent>
</Select>
)
}
@@ -0,0 +1,13 @@
import { Terminal } from '@/components/console/Terminal'
import { useLogWebSocket } from '@/hooks/useWebSocket'
export function MainContent() {
// Connect to WebSocket for logs
useLogWebSocket()
return (
<main className="flex-1 flex flex-col overflow-hidden min-h-0 relative z-10">
<Terminal />
</main>
)
}
+88
View File
@@ -0,0 +1,88 @@
import { Bug, Wifi, AlertTriangle, Github } from 'lucide-react'
import { useTranslation } from 'react-i18next'
import { Badge } from '@/components/ui/badge'
import { useCrawlerStore } from '@/store/crawlerStore'
import { useCrawlerStatus } from '@/hooks/useCrawler'
import { LanguageSwitch } from './LanguageSwitch'
import { ThemeToggle } from './ThemeToggle'
interface SidebarProps {
onShowDisclaimer?: () => void
}
export function Sidebar({ onShowDisclaimer }: SidebarProps) {
const { t } = useTranslation()
const { t: tLicense } = useTranslation('license')
const status = useCrawlerStore((state) => state.status)
// Poll status
useCrawlerStatus()
const isRunning = status === 'running'
return (
<header className="h-14 flex-shrink-0 glass-panel border-b border-cyber-border-subtle relative z-10">
<div className="h-full px-4 flex items-center justify-between">
{/* Left: Logo and GitHub Star */}
<div className="flex items-center gap-3">
<Bug className="w-5 h-5 text-cyber-neon-cyan" />
<span className="font-mono font-bold text-cyber-text-primary tracking-wider text-sm">
MediaCrawler
</span>
<a
href="https://github.com/NanmiCoder/MediaCrawler"
target="_blank"
rel="noopener noreferrer"
className="flex items-center gap-1.5 px-2 py-1 rounded-md border border-cyber-border-subtle hover:border-cyber-neon-cyan hover:shadow-glow-cyan-sm transition-all bg-cyber-bg-tertiary"
>
<Github className="w-4 h-4 text-cyber-text-secondary" />
<span className="text-xs font-mono text-cyber-text-secondary">Star</span>
</a>
{isRunning && (
<Badge variant="running" className="text-[10px]">
{t('status.active')}
</Badge>
)}
{isRunning && (
<span className="w-2 h-2 bg-cyber-neon-green rounded-full shadow-glow-green-sm animate-pulse-fast" />
)}
</div>
{/* Center: Warning Text */}
<button
onClick={onShowDisclaimer}
className="flex items-center gap-3 px-4 py-1.5 rounded-lg border border-cyber-neon-orange/50 bg-cyber-neon-orange/10 hover:bg-cyber-neon-orange/20 transition-all cursor-pointer"
>
<AlertTriangle className="w-4 h-4 text-cyber-neon-orange flex-shrink-0" />
<div className="flex items-center gap-4 text-xs font-mono">
<span className="text-cyber-neon-orange">
<span className="text-cyber-neon-pink font-bold">1.</span> {tLicense('content.line1')}
</span>
<span className="text-cyber-neon-orange">
<span className="text-cyber-neon-pink font-bold">2.</span> {tLicense('content.line2')}
</span>
</div>
</button>
{/* Right: Actions and Status */}
<div className="flex items-center gap-3">
{/* Theme Toggle */}
<ThemeToggle />
{/* Language Switch */}
<LanguageSwitch />
{/* Status Info */}
<div className="hidden lg:flex items-center gap-2 text-xs font-mono">
<span className="text-cyber-text-muted">{t('sidebar.api')}:</span>
<span className="text-cyber-neon-green">v1.0.0</span>
<div className="flex items-center gap-1.5">
<Wifi className="w-3 h-3 text-cyber-text-secondary" />
<span className="text-cyber-text-secondary">{t('sidebar.local')}</span>
<span className="status-dot status-dot-online" />
</div>
</div>
</div>
</div>
</header>
)
}
@@ -0,0 +1,43 @@
import { Sun, Moon, Monitor } from 'lucide-react'
import { useThemeStore } from '@/store/themeStore'
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select'
type Theme = 'light' | 'dark' | 'system'
const themes: { value: Theme; label: string; icon: typeof Sun }[] = [
{ value: 'light', label: 'Light', icon: Sun },
{ value: 'dark', label: 'Dark', icon: Moon },
{ value: 'system', label: 'Auto', icon: Monitor },
]
export function ThemeToggle() {
const { theme, setTheme } = useThemeStore()
const currentTheme = themes.find(t => t.value === theme) || themes[0]
const Icon = currentTheme.icon
return (
<Select value={theme} onValueChange={(value: Theme) => setTheme(value)}>
<SelectTrigger className="w-20 h-7 text-xs font-mono border-cyber-border-subtle bg-cyber-bg-tertiary/50 hover:border-cyber-neon-cyan/50 transition-colors">
<Icon className="w-3 h-3 mr-1 text-cyber-text-secondary" />
<SelectValue>{currentTheme.label}</SelectValue>
</SelectTrigger>
<SelectContent>
{themes.map(({ value, label, icon: ItemIcon }) => (
<SelectItem key={value} value={value} className="text-xs font-mono">
<div className="flex items-center gap-2">
<ItemIcon className="w-3 h-3" />
{label}
</div>
</SelectItem>
))}
</SelectContent>
</Select>
)
}
@@ -0,0 +1,144 @@
import { useTranslation } from 'react-i18next'
import { ShieldAlert, ExternalLink } from 'lucide-react'
import { Button } from '@/components/ui/button'
const LICENSE_KEY = 'mediacrawler_license_accepted'
// 检查是否已经接受协议
export function isLicenseAccepted(): boolean {
return localStorage.getItem(LICENSE_KEY) === 'true'
}
// 清除协议接受状态
export function clearLicenseAccepted(): void {
localStorage.removeItem(LICENSE_KEY)
}
interface LicenseDisclaimerProps {
onAccept: () => void
}
export function LicenseDisclaimer({ onAccept }: LicenseDisclaimerProps) {
const { t } = useTranslation('license')
const handleConfirm = () => {
localStorage.setItem(LICENSE_KEY, 'true')
onAccept()
}
const handleDecline = () => {
// 尝试关闭当前标签页(不会关闭整个浏览器,只关闭当前tab)
try {
// 方式1: 直接关闭当前标签页
window.close()
// 方式2: 将当前标签页导航到空白页
setTimeout(() => {
window.location.href = 'about:blank'
}, 100)
} catch {
// 忽略错误
}
// 如果无法关闭(浏览器安全限制),显示拒绝访问页面
setTimeout(() => {
document.body.innerHTML = `
<div style="
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
background: #0d1117;
color: #f85149;
font-family: 'JetBrains Mono', monospace;
text-align: center;
padding: 20px;
">
<div style="font-size: 48px; margin-bottom: 20px;">⛔</div>
<div style="font-size: 24px; font-weight: bold; margin-bottom: 10px;">访问已拒绝</div>
<div style="font-size: 14px; color: #8b949e;">您未同意使用条款,请关闭此标签页</div>
</div>
`
}, 200)
}
return (
<div className="fixed inset-0 bg-black/95 backdrop-blur-sm flex items-center justify-center z-[100] overflow-y-auto py-8">
<div className="bg-cyber-bg-panel border-2 border-cyber-neon-pink rounded-lg shadow-cyber-card p-6 max-w-2xl w-full mx-4 relative">
{/* Corner decorations - Pink/Red theme for seriousness */}
<div className="absolute top-0 left-0 w-6 h-6 border-t-2 border-l-2 border-cyber-neon-pink" />
<div className="absolute top-0 right-0 w-6 h-6 border-t-2 border-r-2 border-cyber-neon-pink" />
<div className="absolute bottom-0 left-0 w-6 h-6 border-b-2 border-l-2 border-cyber-neon-pink" />
<div className="absolute bottom-0 right-0 w-6 h-6 border-b-2 border-r-2 border-cyber-neon-pink" />
{/* Header with warning icon */}
<div className="flex items-center justify-center gap-3 mb-4">
<ShieldAlert className="w-8 h-8 text-cyber-neon-pink animate-pulse" />
<h2 className="text-xl font-mono font-bold text-cyber-neon-pink">
{t('title')}
</h2>
</div>
{/* Warning subtitle */}
<div className="text-center mb-4">
<span className="text-base font-mono text-cyber-neon-orange">
{t('warning')}
</span>
</div>
{/* Content box */}
<div className="bg-black/50 border border-cyber-neon-pink/30 rounded-lg p-4 mb-4">
<ul className="space-y-2 text-sm font-mono">
<li className="flex items-start gap-2">
<span className="text-cyber-neon-pink font-bold">1.</span>
<span className="text-cyber-text-primary">{t('content.line1')}</span>
</li>
<li className="flex items-start gap-2">
<span className="text-cyber-neon-pink font-bold">2.</span>
<span className="text-cyber-text-primary">{t('content.line2')}</span>
</li>
<li className="flex items-start gap-2">
<span className="text-cyber-neon-pink font-bold">3.</span>
<span className="text-cyber-text-primary">{t('content.line3')}</span>
</li>
<li className="flex items-start gap-2">
<span className="text-cyber-neon-pink font-bold">4.</span>
<span className="text-cyber-text-primary">{t('content.line4')}</span>
</li>
</ul>
</div>
{/* License Link */}
<div className="flex justify-center mb-6">
<a
href="https://github.com/NanmiCoder/MediaCrawler/blob/main/LICENSE"
target="_blank"
rel="noopener noreferrer"
className="flex items-center gap-1.5 text-cyber-neon-cyan hover:underline text-sm font-mono"
>
<ExternalLink className="w-4 h-4" />
{t('license')}
</a>
</div>
{/* Action buttons */}
<div className="flex gap-4">
<Button
onClick={handleDecline}
variant="outline"
className="flex-1 font-mono border-cyber-neon-pink/50 text-cyber-neon-pink hover:bg-cyber-neon-pink/10"
>
{t('decline')}
</Button>
<Button
onClick={handleConfirm}
className="flex-1 font-mono bg-cyber-neon-green text-black font-bold hover:bg-cyber-neon-green/90"
>
{t('confirm')}
</Button>
</div>
</div>
</div>
)
}
+55
View File
@@ -0,0 +1,55 @@
import * as React from 'react'
import * as AccordionPrimitive from '@radix-ui/react-accordion'
import { ChevronDown } from 'lucide-react'
import { cn } from '@/lib/utils'
const Accordion = AccordionPrimitive.Root
const AccordionItem = React.forwardRef<
React.ElementRef<typeof AccordionPrimitive.Item>,
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item>
>(({ className, ...props }, ref) => (
<AccordionPrimitive.Item
ref={ref}
className={cn('border-b', className)}
{...props}
/>
))
AccordionItem.displayName = 'AccordionItem'
const AccordionTrigger = React.forwardRef<
React.ElementRef<typeof AccordionPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger>
>(({ className, children, ...props }, ref) => (
<AccordionPrimitive.Header className="flex">
<AccordionPrimitive.Trigger
ref={ref}
className={cn(
'flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180',
className
)}
{...props}
>
{children}
<ChevronDown className="h-4 w-4 shrink-0 transition-transform duration-200" />
</AccordionPrimitive.Trigger>
</AccordionPrimitive.Header>
))
AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName
const AccordionContent = React.forwardRef<
React.ElementRef<typeof AccordionPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Content>
>(({ className, children, ...props }, ref) => (
<AccordionPrimitive.Content
ref={ref}
className="overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down"
{...props}
>
<div className={cn('pb-4 pt-0', className)}>{children}</div>
</AccordionPrimitive.Content>
))
AccordionContent.displayName = AccordionPrimitive.Content.displayName
export { Accordion, AccordionItem, AccordionTrigger, AccordionContent }
+44
View File
@@ -0,0 +1,44 @@
import * as React from 'react'
import { cva, type VariantProps } from 'class-variance-authority'
import { cn } from '@/lib/utils'
const badgeVariants = cva(
'inline-flex items-center rounded-sm border px-2 py-0.5 text-xs font-mono transition-colors focus:outline-none',
{
variants: {
variant: {
default:
'border-cyber-neon-cyan/30 bg-cyber-neon-cyan/10 text-cyber-neon-cyan',
secondary:
'border-cyber-border-DEFAULT bg-cyber-bg-tertiary text-cyber-text-secondary',
destructive:
'border-cyber-neon-pink/30 bg-cyber-neon-pink/10 text-cyber-neon-pink',
outline:
'border-cyber-border-DEFAULT text-cyber-text-primary',
success:
'border-cyber-neon-green/30 bg-cyber-neon-green/10 text-cyber-neon-green shadow-glow-green-sm',
warning:
'border-cyber-neon-orange/30 bg-cyber-neon-orange/10 text-cyber-neon-orange',
idle:
'border-cyber-border-DEFAULT bg-cyber-bg-tertiary text-cyber-text-muted',
running:
'border-cyber-neon-green/50 bg-cyber-neon-green/20 text-cyber-neon-green shadow-glow-green-sm animate-pulse-fast',
},
},
defaultVariants: {
variant: 'default',
},
}
)
export interface BadgeProps
extends React.HTMLAttributes<HTMLDivElement>,
VariantProps<typeof badgeVariants> {}
function Badge({ className, variant, ...props }: BadgeProps) {
return (
<div className={cn(badgeVariants({ variant }), className)} {...props} />
)
}
export { Badge, badgeVariants }
+60
View File
@@ -0,0 +1,60 @@
import * as React from 'react'
import { Slot } from '@radix-ui/react-slot'
import { cva, type VariantProps } from 'class-variance-authority'
import { cn } from '@/lib/utils'
const buttonVariants = cva(
'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-cyber-neon-cyan disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0',
{
variants: {
variant: {
default:
'bg-cyber-neon-cyan/20 text-cyber-neon-cyan border border-cyber-neon-cyan/50 hover:bg-cyber-neon-cyan/30 hover:shadow-glow-cyan-sm active:scale-95',
destructive:
'bg-cyber-neon-pink/20 text-cyber-neon-pink border border-cyber-neon-pink/50 hover:bg-cyber-neon-pink/30 hover:shadow-glow-pink-sm active:scale-95',
outline:
'border border-cyber-border-DEFAULT bg-transparent hover:bg-cyber-bg-tertiary hover:border-cyber-neon-cyan/50 hover:text-cyber-neon-cyan',
secondary:
'bg-cyber-neon-green/20 text-cyber-neon-green border border-cyber-neon-green/50 hover:bg-cyber-neon-green/30 hover:shadow-glow-green-sm active:scale-95',
ghost:
'hover:bg-cyber-bg-tertiary hover:text-cyber-neon-cyan',
link:
'text-cyber-neon-cyan underline-offset-4 hover:underline',
glow:
'bg-cyber-neon-cyan/20 text-cyber-neon-cyan border border-cyber-neon-cyan/50 shadow-glow-cyan-sm hover:shadow-glow-cyan hover:bg-cyber-neon-cyan/30 active:scale-95',
},
size: {
default: 'h-10 px-4 py-2',
sm: 'h-9 rounded-md px-3',
lg: 'h-12 rounded-md px-8 text-base',
icon: 'h-10 w-10',
},
},
defaultVariants: {
variant: 'default',
size: 'default',
},
}
)
export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
asChild?: boolean
}
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : 'button'
return (
<Comp
className={cn(buttonVariants({ variant, size, className }))}
ref={ref}
{...props}
/>
)
}
)
Button.displayName = 'Button'
export { Button, buttonVariants }
+78
View File
@@ -0,0 +1,78 @@
import * as React from 'react'
import { cn } from '@/lib/utils'
const Card = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn(
'rounded-lg border border-cyber-border-DEFAULT bg-cyber-bg-tertiary text-cyber-text-primary shadow-cyber-card transition-all hover:border-cyber-neon-cyan/30',
className
)}
{...props}
/>
))
Card.displayName = 'Card'
const CardHeader = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn('flex flex-col space-y-1.5 p-6', className)}
{...props}
/>
))
CardHeader.displayName = 'CardHeader'
const CardTitle = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLHeadingElement>
>(({ className, ...props }, ref) => (
<h3
ref={ref}
className={cn(
'text-2xl font-semibold leading-none tracking-tight text-cyber-neon-cyan',
className
)}
{...props}
/>
))
CardTitle.displayName = 'CardTitle'
const CardDescription = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLParagraphElement>
>(({ className, ...props }, ref) => (
<p
ref={ref}
className={cn('text-sm text-cyber-text-muted', className)}
{...props}
/>
))
CardDescription.displayName = 'CardDescription'
const CardContent = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div ref={ref} className={cn('p-6 pt-0', className)} {...props} />
))
CardContent.displayName = 'CardContent'
const CardFooter = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn('flex items-center p-6 pt-0', className)}
{...props}
/>
))
CardFooter.displayName = 'CardFooter'
export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent }
+36
View File
@@ -0,0 +1,36 @@
import * as React from 'react'
import { cn } from '@/lib/utils'
import { Check } from 'lucide-react'
export interface CheckboxProps
extends React.InputHTMLAttributes<HTMLInputElement> {
onCheckedChange?: (checked: boolean) => void
}
const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
({ className, checked, onCheckedChange, ...props }, ref) => {
return (
<label className="inline-flex items-center cursor-pointer">
<input
type="checkbox"
className="sr-only peer"
ref={ref}
checked={checked}
onChange={(e) => onCheckedChange?.(e.target.checked)}
{...props}
/>
<div
className={cn(
'h-4 w-4 shrink-0 rounded-sm border border-cyber-border-DEFAULT bg-cyber-bg-tertiary ring-offset-background focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-cyber-neon-cyan disabled:cursor-not-allowed disabled:opacity-50 peer-checked:bg-cyber-neon-cyan/20 peer-checked:border-cyber-neon-cyan peer-checked:shadow-glow-cyan-sm flex items-center justify-center transition-all',
className
)}
>
<Check className={cn('h-3 w-3 text-cyber-neon-cyan transition-opacity', checked ? 'opacity-100' : 'opacity-0')} />
</div>
</label>
)
}
)
Checkbox.displayName = 'Checkbox'
export { Checkbox }
+119
View File
@@ -0,0 +1,119 @@
import * as React from 'react'
import * as DialogPrimitive from '@radix-ui/react-dialog'
import { X } from 'lucide-react'
import { cn } from '@/lib/utils'
const Dialog = DialogPrimitive.Root
const DialogTrigger = DialogPrimitive.Trigger
const DialogPortal = DialogPrimitive.Portal
const DialogClose = DialogPrimitive.Close
const DialogOverlay = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Overlay
ref={ref}
className={cn(
'fixed inset-0 z-50 bg-black/60 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
className
)}
{...props}
/>
))
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName
const DialogContent = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
>(({ className, children, ...props }, ref) => (
<DialogPortal>
<DialogOverlay />
<DialogPrimitive.Content
ref={ref}
className={cn(
'fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 glass-panel-dark float-panel rounded-lg p-6 duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%]',
className
)}
{...props}
>
{children}
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 hover:text-cyber-neon-cyan focus:outline-none focus:ring-2 focus:ring-cyber-neon-cyan focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
<X className="h-4 w-4" />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
</DialogPrimitive.Content>
</DialogPortal>
))
DialogContent.displayName = DialogPrimitive.Content.displayName
const DialogHeader = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
'flex flex-col space-y-1.5 text-center sm:text-left',
className
)}
{...props}
/>
)
DialogHeader.displayName = 'DialogHeader'
const DialogFooter = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
'flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2',
className
)}
{...props}
/>
)
DialogFooter.displayName = 'DialogFooter'
const DialogTitle = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Title
ref={ref}
className={cn(
'text-lg font-semibold leading-none tracking-tight text-cyber-neon-cyan font-mono',
className
)}
{...props}
/>
))
DialogTitle.displayName = DialogPrimitive.Title.displayName
const DialogDescription = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Description
ref={ref}
className={cn('text-sm text-cyber-text-secondary', className)}
{...props}
/>
))
DialogDescription.displayName = DialogPrimitive.Description.displayName
export {
Dialog,
DialogPortal,
DialogOverlay,
DialogClose,
DialogTrigger,
DialogContent,
DialogHeader,
DialogFooter,
DialogTitle,
DialogDescription,
}
+24
View File
@@ -0,0 +1,24 @@
import * as React from 'react'
import { cn } from '@/lib/utils'
export interface InputProps
extends React.InputHTMLAttributes<HTMLInputElement> {}
const Input = React.forwardRef<HTMLInputElement, InputProps>(
({ className, type, ...props }, ref) => {
return (
<input
type={type}
className={cn(
'flex h-9 w-full rounded-md border border-cyber-border-DEFAULT bg-cyber-bg-tertiary px-3 py-2 text-sm font-mono text-cyber-text-primary ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-cyber-text-muted focus-visible:outline-none focus-visible:border-cyber-neon-cyan focus-visible:shadow-[0_0_10px_rgb(var(--cyber-neon-cyan)/0.2)] disabled:cursor-not-allowed disabled:opacity-50 transition-all',
className
)}
ref={ref}
{...props}
/>
)
}
)
Input.displayName = 'Input'
export { Input }
+23
View File
@@ -0,0 +1,23 @@
import * as React from 'react'
import * as LabelPrimitive from '@radix-ui/react-label'
import { cva, type VariantProps } from 'class-variance-authority'
import { cn } from '@/lib/utils'
const labelVariants = cva(
'text-sm font-mono leading-none text-cyber-text-secondary peer-disabled:cursor-not-allowed peer-disabled:opacity-70'
)
const Label = React.forwardRef<
React.ElementRef<typeof LabelPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
VariantProps<typeof labelVariants>
>(({ className, ...props }, ref) => (
<LabelPrimitive.Root
ref={ref}
className={cn(labelVariants(), className)}
{...props}
/>
))
Label.displayName = LabelPrimitive.Root.displayName
export { Label }
+45
View File
@@ -0,0 +1,45 @@
import * as React from 'react'
import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area'
import { cn } from '@/lib/utils'
const ScrollArea = React.forwardRef<
React.ElementRef<typeof ScrollAreaPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root>
>(({ className, children, ...props }, ref) => (
<ScrollAreaPrimitive.Root
ref={ref}
className={cn('relative overflow-hidden', className)}
{...props}
>
<ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]">
{children}
</ScrollAreaPrimitive.Viewport>
<ScrollBar />
<ScrollAreaPrimitive.Corner />
</ScrollAreaPrimitive.Root>
))
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName
const ScrollBar = React.forwardRef<
React.ElementRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>,
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>
>(({ className, orientation = 'vertical', ...props }, ref) => (
<ScrollAreaPrimitive.ScrollAreaScrollbar
ref={ref}
orientation={orientation}
className={cn(
'flex touch-none select-none transition-colors',
orientation === 'vertical' &&
'h-full w-2.5 border-l border-l-transparent p-[1px]',
orientation === 'horizontal' &&
'h-2.5 flex-col border-t border-t-transparent p-[1px]',
className
)}
{...props}
>
<ScrollAreaPrimitive.ScrollAreaThumb className="relative flex-1 rounded-full bg-border" />
</ScrollAreaPrimitive.ScrollAreaScrollbar>
))
ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName
export { ScrollArea, ScrollBar }
+157
View File
@@ -0,0 +1,157 @@
import * as React from 'react'
import * as SelectPrimitive from '@radix-ui/react-select'
import { Check, ChevronDown, ChevronUp } from 'lucide-react'
import { cn } from '@/lib/utils'
const Select = SelectPrimitive.Root
const SelectGroup = SelectPrimitive.Group
const SelectValue = SelectPrimitive.Value
const SelectTrigger = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
>(({ className, children, ...props }, ref) => (
<SelectPrimitive.Trigger
ref={ref}
className={cn(
'flex h-9 w-full items-center justify-between rounded-md border border-cyber-border-DEFAULT bg-cyber-bg-tertiary px-3 py-2 text-sm font-mono text-cyber-text-primary ring-offset-background placeholder:text-cyber-text-muted focus:outline-none focus:border-cyber-neon-cyan focus:shadow-[0_0_10px_rgb(var(--cyber-neon-cyan)/0.2)] disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1 transition-all',
className
)}
{...props}
>
{children}
<SelectPrimitive.Icon asChild>
<ChevronDown className="h-4 w-4 text-cyber-text-muted" />
</SelectPrimitive.Icon>
</SelectPrimitive.Trigger>
))
SelectTrigger.displayName = SelectPrimitive.Trigger.displayName
const SelectScrollUpButton = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>
>(({ className, ...props }, ref) => (
<SelectPrimitive.ScrollUpButton
ref={ref}
className={cn(
'flex cursor-default items-center justify-center py-1 text-cyber-text-muted',
className
)}
{...props}
>
<ChevronUp className="h-4 w-4" />
</SelectPrimitive.ScrollUpButton>
))
SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName
const SelectScrollDownButton = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>
>(({ className, ...props }, ref) => (
<SelectPrimitive.ScrollDownButton
ref={ref}
className={cn(
'flex cursor-default items-center justify-center py-1 text-cyber-text-muted',
className
)}
{...props}
>
<ChevronDown className="h-4 w-4" />
</SelectPrimitive.ScrollDownButton>
))
SelectScrollDownButton.displayName =
SelectPrimitive.ScrollDownButton.displayName
const SelectContent = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
>(({ className, children, position = 'popper', ...props }, ref) => (
<SelectPrimitive.Portal>
<SelectPrimitive.Content
ref={ref}
className={cn(
'relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border border-cyber-border-DEFAULT bg-cyber-bg-panel text-cyber-text-primary shadow-[0_0_20px_rgba(0,0,0,0.5)] data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
position === 'popper' &&
'data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1',
className
)}
position={position}
{...props}
>
<SelectScrollUpButton />
<SelectPrimitive.Viewport
className={cn(
'p-1',
position === 'popper' &&
'h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]'
)}
>
{children}
</SelectPrimitive.Viewport>
<SelectScrollDownButton />
</SelectPrimitive.Content>
</SelectPrimitive.Portal>
))
SelectContent.displayName = SelectPrimitive.Content.displayName
const SelectLabel = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Label>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>
>(({ className, ...props }, ref) => (
<SelectPrimitive.Label
ref={ref}
className={cn('py-1.5 pl-8 pr-2 text-sm font-semibold text-cyber-neon-cyan', className)}
{...props}
/>
))
SelectLabel.displayName = SelectPrimitive.Label.displayName
const SelectItem = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Item>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>
>(({ className, children, ...props }, ref) => (
<SelectPrimitive.Item
ref={ref}
className={cn(
'relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm font-mono outline-none focus:bg-cyber-neon-cyan/20 focus:text-cyber-neon-cyan data-[disabled]:pointer-events-none data-[disabled]:opacity-50 transition-colors',
className
)}
{...props}
>
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
<SelectPrimitive.ItemIndicator>
<Check className="h-4 w-4 text-cyber-neon-cyan" />
</SelectPrimitive.ItemIndicator>
</span>
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
</SelectPrimitive.Item>
))
SelectItem.displayName = SelectPrimitive.Item.displayName
const SelectSeparator = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Separator>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>
>(({ className, ...props }, ref) => (
<SelectPrimitive.Separator
ref={ref}
className={cn('-mx-1 my-1 h-px bg-cyber-border-DEFAULT', className)}
{...props}
/>
))
SelectSeparator.displayName = SelectPrimitive.Separator.displayName
export {
Select,
SelectGroup,
SelectValue,
SelectTrigger,
SelectContent,
SelectLabel,
SelectItem,
SelectSeparator,
SelectScrollUpButton,
SelectScrollDownButton,
}
+52
View File
@@ -0,0 +1,52 @@
import * as React from 'react'
import * as TabsPrimitive from '@radix-ui/react-tabs'
import { cn } from '@/lib/utils'
const Tabs = TabsPrimitive.Root
const TabsList = React.forwardRef<
React.ElementRef<typeof TabsPrimitive.List>,
React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>
>(({ className, ...props }, ref) => (
<TabsPrimitive.List
ref={ref}
className={cn(
'inline-flex h-9 items-center justify-center rounded-md bg-cyber-bg-tertiary border border-cyber-border-DEFAULT p-1 text-cyber-text-muted',
className
)}
{...props}
/>
))
TabsList.displayName = TabsPrimitive.List.displayName
const TabsTrigger = React.forwardRef<
React.ElementRef<typeof TabsPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>
>(({ className, ...props }, ref) => (
<TabsPrimitive.Trigger
ref={ref}
className={cn(
'inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1 text-sm font-mono ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-cyber-neon-cyan disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-cyber-neon-cyan/20 data-[state=active]:text-cyber-neon-cyan data-[state=active]:shadow-glow-cyan-sm',
className
)}
{...props}
/>
))
TabsTrigger.displayName = TabsPrimitive.Trigger.displayName
const TabsContent = React.forwardRef<
React.ElementRef<typeof TabsPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>
>(({ className, ...props }, ref) => (
<TabsPrimitive.Content
ref={ref}
className={cn(
'mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-cyber-neon-cyan',
className
)}
{...props}
/>
))
TabsContent.displayName = TabsPrimitive.Content.displayName
export { Tabs, TabsList, TabsTrigger, TabsContent }
+99
View File
@@ -0,0 +1,99 @@
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
import { toast } from 'sonner'
import { crawlerApi, configApi } from '@/lib/api'
import { useCrawlerStore } from '@/store/crawlerStore'
import type { CrawlerConfig } from '@/types/crawler'
export function useCrawlerStatus() {
const setStatus = useCrawlerStore((state) => state.setStatus)
const setRunningInfo = useCrawlerStore((state) => state.setRunningInfo)
return useQuery({
queryKey: ['crawlerStatus'],
queryFn: async () => {
const { data } = await crawlerApi.getStatus()
setStatus(data.status)
setRunningInfo(data.platform, data.crawler_type, data.started_at)
return data
},
refetchInterval: 2000,
})
}
export function useStartCrawler() {
const queryClient = useQueryClient()
const setStatus = useCrawlerStore((state) => state.setStatus)
const clearLogs = useCrawlerStore((state) => state.clearLogs)
return useMutation({
mutationFn: (config: CrawlerConfig) => crawlerApi.start(config),
onMutate: () => {
clearLogs()
setStatus('running')
},
onSuccess: () => {
toast.success('Crawler started successfully')
queryClient.invalidateQueries({ queryKey: ['crawlerStatus'] })
},
onError: (error: Error) => {
setStatus('idle')
toast.error(`Failed to start crawler: ${error.message}`)
},
})
}
export function useStopCrawler() {
const queryClient = useQueryClient()
const setStatus = useCrawlerStore((state) => state.setStatus)
return useMutation({
mutationFn: () => crawlerApi.stop(),
onMutate: () => {
setStatus('stopping')
},
onSuccess: () => {
toast.success('Crawler stopped')
setStatus('idle')
queryClient.invalidateQueries({ queryKey: ['crawlerStatus'] })
},
onError: (error: Error) => {
toast.error(`Failed to stop crawler: ${error.message}`)
},
})
}
export function useCrawlerLogs() {
const setLogs = useCrawlerStore((state) => state.setLogs)
return useQuery({
queryKey: ['crawlerLogs'],
queryFn: async () => {
const { data } = await crawlerApi.getLogs(500)
setLogs(data.logs)
return data.logs
},
refetchInterval: false, // Use WebSocket instead
})
}
export function usePlatforms() {
return useQuery({
queryKey: ['platforms'],
queryFn: async () => {
const { data } = await configApi.getPlatforms()
return data.platforms
},
staleTime: Infinity,
})
}
export function useConfigOptions() {
return useQuery({
queryKey: ['configOptions'],
queryFn: async () => {
const { data } = await configApi.getOptions()
return data
},
staleTime: Infinity,
})
}
+111
View File
@@ -0,0 +1,111 @@
import { useEffect, useRef } from 'react'
import { useCrawlerStore } from '@/store/crawlerStore'
import type { LogEntry } from '@/types/crawler'
// 模块级单例,确保全局只有一个 WebSocket 连接
let globalWs: WebSocket | null = null
let globalReconnectTimer: ReturnType<typeof setTimeout> | null = null
let connectionCount = 0 // 跟踪连接使用者数量
export function useLogWebSocket() {
const addLog = useCrawlerStore((state) => state.addLog)
const addLogRef = useRef(addLog)
// 保持 addLog 引用最新
useEffect(() => {
addLogRef.current = addLog
}, [addLog])
useEffect(() => {
connectionCount++
const connect = () => {
if (globalReconnectTimer) {
clearTimeout(globalReconnectTimer)
globalReconnectTimer = null
}
// 如果已经连接或正在连接,不重复创建
if (globalWs && (globalWs.readyState === WebSocket.OPEN || globalWs.readyState === WebSocket.CONNECTING)) {
return
}
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'
const host = window.location.host
const wsUrl = `${protocol}//${host}/api/ws/logs`
const ws = new WebSocket(wsUrl)
globalWs = ws
ws.onopen = () => {
if (globalWs !== ws) return
console.log('WebSocket connected')
}
ws.onmessage = (event) => {
if (globalWs !== ws) return
if (event.data === 'ping') {
ws.send('pong')
return
}
if (event.data === 'pong') {
return
}
try {
const log: LogEntry = JSON.parse(event.data)
if (log.id && log.message) {
addLogRef.current(log)
}
} catch (e) {
console.warn('Failed to parse WebSocket message:', event.data)
}
}
ws.onclose = () => {
if (globalWs !== ws) return
console.log('WebSocket disconnected')
globalWs = null
// 只在还有使用者时才重连
if (connectionCount > 0) {
globalReconnectTimer = setTimeout(connect, 2000)
}
}
ws.onerror = (error) => {
if (globalWs !== ws) return
console.error('WebSocket error:', error)
}
}
// 首次连接
connect()
// Heartbeat
const heartbeat = setInterval(() => {
if (globalWs && globalWs.readyState === WebSocket.OPEN) {
globalWs.send('ping')
}
}, 30000)
return () => {
connectionCount--
clearInterval(heartbeat)
// 只在没有使用者时才断开连接
if (connectionCount === 0) {
if (globalReconnectTimer) {
clearTimeout(globalReconnectTimer)
globalReconnectTimer = null
}
if (globalWs) {
const ws = globalWs
globalWs = null
ws.close()
}
}
}
}, []) // 空依赖数组
return { ws: globalWs }
}
+57
View File
@@ -0,0 +1,57 @@
import i18n from 'i18next'
import { initReactI18next } from 'react-i18next'
import LanguageDetector from 'i18next-browser-languagedetector'
// 中文翻译
import zhCommon from './locales/zh-CN/common.json'
import zhConfig from './locales/zh-CN/config.json'
import zhTerminal from './locales/zh-CN/terminal.json'
import zhData from './locales/zh-CN/data.json'
import zhEnv from './locales/zh-CN/env.json'
import zhLicense from './locales/zh-CN/license.json'
// 英文翻译
import enCommon from './locales/en-US/common.json'
import enConfig from './locales/en-US/config.json'
import enTerminal from './locales/en-US/terminal.json'
import enData from './locales/en-US/data.json'
import enEnv from './locales/en-US/env.json'
import enLicense from './locales/en-US/license.json'
const resources = {
'zh-CN': {
common: zhCommon,
config: zhConfig,
terminal: zhTerminal,
data: zhData,
env: zhEnv,
license: zhLicense,
},
'en-US': {
common: enCommon,
config: enConfig,
terminal: enTerminal,
data: enData,
env: enEnv,
license: enLicense,
},
}
i18n
.use(LanguageDetector)
.use(initReactI18next)
.init({
resources,
fallbackLng: 'zh-CN',
defaultNS: 'common',
interpolation: {
escapeValue: false,
},
detection: {
order: ['localStorage', 'navigator'],
caches: ['localStorage'],
lookupLocalStorage: 'mediacrawler_language',
},
})
export default i18n
+26
View File
@@ -0,0 +1,26 @@
{
"status": {
"active": "ACTIVE",
"standby": "STANDBY",
"idle": "IDLE",
"running": "RUNNING",
"stopping": "STOPPING",
"error": "ERROR"
},
"sidebar": {
"title": "MediaCrawler",
"api": "API",
"local": "LOCAL",
"disclaimer": "For personal learning only, commercial use prohibited",
"license": "License"
},
"action": {
"loading": "Loading...",
"skip": "SKIP_CHECK",
"retry": "RETRY_SCAN"
},
"unit": {
"entries": "entries",
"records": "records"
}
}
+71
View File
@@ -0,0 +1,71 @@
{
"section": {
"targetMatrix": {
"title": "TARGET_MATRIX",
"description": "Platform, mode & search parameters"
},
"authMatrix": {
"title": "AUTH_MATRIX",
"description": "Login method configuration"
},
"outputConfig": {
"title": "OUTPUT_CONFIG",
"description": "Save format & comment options"
},
"runtime": {
"title": "RUNTIME",
"description": "Runtime parameters"
}
},
"field": {
"platform": "PLATFORM",
"platformPlaceholder": "Select platform",
"crawlType": "CRAWL_TYPE",
"crawlTypePlaceholder": "Select type",
"startPage": "START_PAGE",
"keywords": "KEYWORDS",
"keywordsHint": "Press Enter to add keyword",
"keywordsPlaceholder": "Type keyword, press Enter to add...",
"specifiedIds": "POST/VIDEO_ID",
"specifiedIdsHint": "Enter post or video ID/URL, one per line or comma-separated",
"specifiedIdsPlaceholder": {
"bili": "Examples:\nBV1xxxx\nhttps://www.bilibili.com/video/BV1xxxx",
"xhs": "Examples:\nhttps://www.xiaohongshu.com/explore/xxx?xsec_token=xxx\n(must include xsec_token)",
"dy": "Examples:\n7525538910311632128\nhttps://www.douyin.com/video/xxx\nhttps://v.douyin.com/xxx (short link)",
"wb": "Examples:\n4982041758140155\nhttps://weibo.com/xxx/xxx",
"ks": "Examples:\n3xf8enb8dbj6uig\nhttps://www.kuaishou.com/short-video/xxx",
"default": "Enter post/video ID or URL..."
},
"creatorIds": "CREATOR_ID",
"creatorIdsHint": "Enter creator ID/URL, one per line or comma-separated",
"creatorIdsPlaceholder": {
"bili": "Examples:\n434377496\nhttps://space.bilibili.com/434377496",
"xhs": "Examples:\nhttps://www.xiaohongshu.com/user/profile/xxx?xsec_token=xxx\n(must include xsec_token)",
"dy": "Examples:\nMS4wLjABAAAAxxx\nhttps://www.douyin.com/user/MS4wLjABAAAAxxx",
"wb": "Examples:\n5533390220\nhttps://weibo.com/u/5533390220",
"ks": "Examples:\n3x84qugg4ch9zhs\nhttps://www.kuaishou.com/profile/xxx",
"default": "Enter creator ID or URL..."
},
"loginMethod": "LOGIN_METHOD",
"loginMethodPlaceholder": "Select login method",
"cookies": "COOKIES",
"cookiesHint": "Paste cookie string",
"cookiesPlaceholder": "Paste cookies here...",
"saveFormat": "SAVE_FORMAT",
"saveFormatPlaceholder": "Select format",
"commentExtraction": "Comment Extraction",
"subComments": "Sub-comments",
"headlessMode": "HEADLESS_MODE",
"headlessModeHint": "Run browser without GUI"
},
"button": {
"initiateScan": "INITIATE SCAN",
"initiating": "INITIATING...",
"terminate": "TERMINATE",
"stopping": "STOPPING..."
},
"warning": {
"cookieSlider": "[Note] Cookie login is not recommended for Xiaohongshu and Douyin due to slider captcha",
"xhsToken": "[Important] Xiaohongshu URLs must contain xsec_token parameter, please copy the full URL from browser"
}
}
+29
View File
@@ -0,0 +1,29 @@
{
"dialog": {
"button": "PAYLOAD_MATRIX",
"title": "DATA_EXPLORER"
},
"explorer": {
"title": "CAPTURED_PAYLOAD_MATRIX",
"records": "{{count}} RECORDS",
"rescan": "RESCAN",
"loading": "[LOADING] Scanning payload directory...",
"noData": "NO_DATA_CAPTURED",
"noDataHint": "Initialize crawler to begin data extraction sequence. Results will appear here upon completion.",
"allCategories": "ALL"
},
"file": {
"entries": "{{count}} entries",
"extract": "EXTRACT",
"preview": "PREVIEW"
},
"preview": {
"title": "Data Preview",
"records": "{{count}} RECORDS",
"download": "DOWNLOAD",
"loading": "[LOADING] Decoding payload...",
"error": "[ERROR] Failed to decode payload",
"searchPlaceholder": "Search in data...",
"showing": "Showing {{filtered}} of {{total}} records"
}
}
+18
View File
@@ -0,0 +1,18 @@
{
"title": "ENV_DIAGNOSTICS",
"scanning": "[SCAN] Analyzing MediaCrawler environment...",
"success": "[OK] {{message}}",
"error": "[ERR] {{message}}",
"defaultError": "Cannot connect to API server",
"defaultErrorHint": "Please ensure backend service is running (uvicorn api.main:app --port 8080)",
"showDetails": "[+] SHOW_DETAILS",
"hideDetails": "[-] HIDE_DETAILS",
"requirements": "[REQUIREMENTS]",
"requirementsList": {
"1": "Install uv package manager",
"2": "Execute uv sync in project root",
"3": "Verify all dependencies installed"
},
"skipCheck": "SKIP_CHECK",
"retryCheck": "RETRY_SCAN"
}
+21
View File
@@ -0,0 +1,21 @@
{
"title": "Usage Notice",
"warning": "Please read the following terms carefully",
"content": {
"line1": "This project is for personal learning and research purposes only",
"line2": "Commercial use or profit-making activities are strictly prohibited",
"line3": "By using this project, you agree to comply with all applicable laws",
"line4": "Users bear full responsibility for any consequences of misuse"
},
"license": "View Full License",
"github": "Visit GitHub Repository",
"confirm": "I understand and agree to the above terms",
"decline": "Disagree, Exit",
"author": {
"name": "Relakkes (阿江)",
"tagline": "40K+ Star Open Source Author",
"description": "Author of MediaCrawler (40K stars), focused on crawler tech and AI Agent knowledge sharing",
"support": "If you find this project helpful, please follow the author on social media",
"slogan": "Open source is hard, please star ⭐"
}
}
@@ -0,0 +1,16 @@
{
"header": {
"title": "SYSTEM_CONSOLE",
"entries": "{{count}} entries",
"active": "ACTIVE",
"clear": "CLEAR",
"restore": "RESTORE ALL LOGS"
},
"banner": {
"systemInit": "[SYS] System initialized successfully",
"configHint": "[INFO] Configure parameters and initiate scan sequence..."
},
"footer": {
"awaiting": "awaiting_command..."
}
}
+26
View File
@@ -0,0 +1,26 @@
{
"status": {
"active": "运行中",
"standby": "待机",
"idle": "空闲",
"running": "运行中",
"stopping": "停止中",
"error": "错误"
},
"sidebar": {
"title": "MediaCrawler",
"api": "API",
"local": "本地",
"disclaimer": "仅供个人学习研究使用,禁止商业用途",
"license": "查看协议"
},
"action": {
"loading": "加载中...",
"skip": "跳过检测",
"retry": "重新扫描"
},
"unit": {
"entries": "条记录",
"records": "条"
}
}
+71
View File
@@ -0,0 +1,71 @@
{
"section": {
"targetMatrix": {
"title": "目标配置",
"description": "平台、模式与搜索参数"
},
"authMatrix": {
"title": "登录配置",
"description": "登录方式配置"
},
"outputConfig": {
"title": "输出配置",
"description": "保存格式与评论选项"
},
"runtime": {
"title": "运行参数",
"description": "运行时参数"
}
},
"field": {
"platform": "平台",
"platformPlaceholder": "选择平台",
"crawlType": "爬取类型",
"crawlTypePlaceholder": "选择类型",
"startPage": "起始页",
"keywords": "关键词",
"keywordsHint": "输入关键词后按回车添加",
"keywordsPlaceholder": "输入关键词,按回车添加...",
"specifiedIds": "帖子/视频 ID",
"specifiedIdsHint": "输入帖子或视频的ID/URL,每行一个或用逗号分隔",
"specifiedIdsPlaceholder": {
"bili": "示例:\nBV1xxxx\nhttps://www.bilibili.com/video/BV1xxxx",
"xhs": "示例:\nhttps://www.xiaohongshu.com/explore/xxx?xsec_token=xxx\n(必须包含xsec_token参数)",
"dy": "示例:\n7525538910311632128\nhttps://www.douyin.com/video/xxx\nhttps://v.douyin.com/xxx (短链接)",
"wb": "示例:\n4982041758140155\nhttps://weibo.com/xxx/xxx",
"ks": "示例:\n3xf8enb8dbj6uig\nhttps://www.kuaishou.com/short-video/xxx",
"default": "输入帖子/视频 ID 或 URL..."
},
"creatorIds": "创作者 ID",
"creatorIdsHint": "输入创作者的ID/URL,每行一个或用逗号分隔",
"creatorIdsPlaceholder": {
"bili": "示例:\n434377496\nhttps://space.bilibili.com/434377496",
"xhs": "示例:\nhttps://www.xiaohongshu.com/user/profile/xxx?xsec_token=xxx\n(必须包含xsec_token参数)",
"dy": "示例:\nMS4wLjABAAAAxxx\nhttps://www.douyin.com/user/MS4wLjABAAAAxxx",
"wb": "示例:\n5533390220\nhttps://weibo.com/u/5533390220",
"ks": "示例:\n3x84qugg4ch9zhs\nhttps://www.kuaishou.com/profile/xxx",
"default": "输入创作者 ID 或 URL..."
},
"loginMethod": "登录方式",
"loginMethodPlaceholder": "选择登录方式",
"cookies": "Cookies",
"cookiesHint": "粘贴 Cookie 字符串",
"cookiesPlaceholder": "在此粘贴 Cookies...",
"saveFormat": "保存格式",
"saveFormatPlaceholder": "选择格式",
"commentExtraction": "评论抓取",
"subComments": "子评论",
"headlessMode": "无头模式",
"headlessModeHint": "无 GUI 运行浏览器"
},
"button": {
"initiateScan": "开始爬虫",
"initiating": "启动中...",
"terminate": "终止",
"stopping": "停止中..."
},
"warning": {
"cookieSlider": "[提示] 小红书和抖音平台不建议使用 Cookie 登录,因为可能会触发滑块验证",
"xhsToken": "[重要] 小红书 URL 必须包含 xsec_token 参数,请从浏览器复制完整 URL"
}
}
+29
View File
@@ -0,0 +1,29 @@
{
"dialog": {
"button": "数据管理",
"title": "数据浏览器"
},
"explorer": {
"title": "数据文件管理",
"records": "{{count}} 条",
"rescan": "重新扫描",
"loading": "[加载中] 正在扫描数据目录...",
"noData": "暂无数据",
"noDataHint": "启动爬虫开始数据采集,完成后结果将显示在此处。",
"allCategories": "全部"
},
"file": {
"entries": "{{count}} 条",
"extract": "下载",
"preview": "预览"
},
"preview": {
"title": "数据预览",
"records": "{{count}} 条记录",
"download": "下载",
"loading": "[加载中] 正在解析数据...",
"error": "[错误] 数据解析失败",
"searchPlaceholder": "搜索数据...",
"showing": "显示 {{filtered}} / {{total}} 条记录"
}
}
+18
View File
@@ -0,0 +1,18 @@
{
"title": "环境检测",
"scanning": "[扫描] 正在分析 MediaCrawler 环境...",
"success": "[成功] {{message}}",
"error": "[错误] {{message}}",
"defaultError": "无法连接到 API 服务器",
"defaultErrorHint": "请确保后端服务已启动 (uvicorn api.main:app --port 8080)",
"showDetails": "[+] 显示详情",
"hideDetails": "[-] 隐藏详情",
"requirements": "[环境要求]",
"requirementsList": {
"1": "安装 uv 包管理器",
"2": "在项目根目录执行 uv sync",
"3": "确认所有依赖已安装"
},
"skipCheck": "跳过检测",
"retryCheck": "重新检测"
}
+21
View File
@@ -0,0 +1,21 @@
{
"title": "使用须知",
"warning": "请仔细阅读以下条款",
"content": {
"line1": "本项目仅供个人学习和研究爬虫技术使用",
"line2": "严禁将本项目用于任何商业用途或盈利活动",
"line3": "使用本项目即表示您同意遵守相关法律法规",
"line4": "任何因违规使用造成的后果由使用者自行承担"
},
"license": "查看完整协议",
"github": "访问 GitHub 仓库",
"confirm": "我已知晓并同意上述条款",
"decline": "不同意,退出",
"author": {
"name": "程序员阿江-Relakkes",
"tagline": "40K+ Star 开源项目作者",
"description": "40K开源项目MediaCrawler作者,专注爬虫技术和AI Agent知识分享",
"support": "如果觉得项目有帮助,欢迎关注作者的社交媒体账号",
"slogan": "开源不易,求个关注 ⭐"
}
}
@@ -0,0 +1,16 @@
{
"header": {
"title": "系统控制台",
"entries": "{{count}} 条记录",
"active": "活跃",
"clear": "清除",
"restore": "恢复所有日志"
},
"banner": {
"systemInit": "[系统] 系统初始化成功",
"configHint": "[信息] 配置参数并启动扫描序列..."
},
"footer": {
"awaiting": "等待命令..."
}
}
+490
View File
@@ -0,0 +1,490 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
/* Light theme (default) - Clean Cyber */
:root {
/* Semantic colors for shadcn compatibility */
--background: 210 20% 98%;
--foreground: 220 20% 15%;
--card: 0 0% 100%;
--card-foreground: 220 20% 15%;
--popover: 0 0% 100%;
--popover-foreground: 220 20% 15%;
--primary: 187 80% 42%;
--primary-foreground: 0 0% 100%;
--secondary: 330 75% 55%;
--secondary-foreground: 0 0% 100%;
--muted: 210 20% 95%;
--muted-foreground: 215 15% 45%;
--accent: 187 80% 42%;
--accent-foreground: 0 0% 100%;
--destructive: 330 75% 55%;
--destructive-foreground: 0 0% 100%;
--border: 214 20% 88%;
--input: 214 20% 88%;
--ring: 187 80% 42%;
--radius: 0.375rem;
/* Cyberpunk color system - Clean Light with Cyan accent */
--cyber-bg-primary: 248 250 252;
--cyber-bg-secondary: 241 245 249;
--cyber-bg-tertiary: 226 232 240;
--cyber-bg-panel: 255 255 255;
--cyber-bg-elevated: 248 250 252;
--cyber-neon-cyan: 6 182 212;
--cyber-neon-cyan-dim: 8 145 178;
--cyber-neon-pink: 236 72 153;
--cyber-neon-pink-dim: 219 39 119;
--cyber-neon-green: 34 197 94;
--cyber-neon-green-dim: 22 163 74;
--cyber-neon-orange: 249 115 22;
--cyber-neon-yellow: 234 179 8;
--cyber-neon-purple: 168 85 247;
--cyber-text-primary: 15 23 42;
--cyber-text-secondary: 71 85 105;
--cyber-text-muted: 148 163 184;
--cyber-border-default: 203 213 225;
--cyber-border-subtle: 226 232 240;
--cyber-border-glow: 6 182 212;
/* Glass effect */
--glass-bg: 255 255 255 / 0.85;
--glass-border: 203 213 225 / 0.5;
--glass-dark-bg: 241 245 249 / 0.9;
--glass-dark-border: 203 213 225 / 0.6;
/* Shadows - subtle for light mode */
--shadow-glow-opacity: 0.2;
--shadow-glow-spread: 6px;
}
/* Dark theme - Full Cyberpunk */
.dark {
/* Semantic colors */
--background: 233 67% 4%;
--foreground: 210 20% 93%;
--card: 215 21% 11%;
--card-foreground: 210 20% 93%;
--popover: 213 18% 13%;
--popover-foreground: 210 20% 93%;
--primary: 180 100% 50%;
--primary-foreground: 233 67% 4%;
--secondary: 330 100% 50%;
--secondary-foreground: 0 0% 100%;
--muted: 215 14% 17%;
--muted-foreground: 215 16% 57%;
--accent: 180 100% 50%;
--accent-foreground: 233 67% 4%;
--destructive: 330 100% 50%;
--destructive-foreground: 0 0% 100%;
--border: 215 14% 25%;
--input: 215 14% 25%;
--ring: 180 100% 50%;
/* Cyberpunk color system - Dark variants (original neon) */
--cyber-bg-primary: 10 10 15;
--cyber-bg-secondary: 13 17 23;
--cyber-bg-tertiary: 22 27 34;
--cyber-bg-panel: 28 33 40;
--cyber-bg-elevated: 33 38 45;
--cyber-neon-cyan: 0 255 255;
--cyber-neon-cyan-dim: 37 177 191;
--cyber-neon-pink: 255 0 128;
--cyber-neon-pink-dim: 222 40 59;
--cyber-neon-green: 0 255 65;
--cyber-neon-green-dim: 57 255 20;
--cyber-neon-orange: 255 152 0;
--cyber-neon-yellow: 255 234 0;
--cyber-neon-purple: 191 0 255;
--cyber-text-primary: 230 237 243;
--cyber-text-secondary: 139 148 158;
--cyber-text-muted: 72 79 88;
--cyber-border-default: 48 54 61;
--cyber-border-subtle: 33 38 45;
--cyber-border-glow: 0 255 255;
/* Glass effect */
--glass-bg: 22 27 34 / 0.7;
--glass-border: 48 54 61 / 0.5;
--glass-dark-bg: 13 17 23 / 0.85;
--glass-dark-border: 48 54 61 / 0.4;
/* Shadows - vibrant for dark mode */
--shadow-glow-opacity: 0.5;
--shadow-glow-spread: 10px;
}
* {
border-color: rgb(var(--cyber-border-default));
}
body {
background-color: rgb(var(--cyber-bg-primary));
color: rgb(var(--cyber-text-primary));
font-family: Inter, system-ui, sans-serif;
font-size: 15px;
line-height: 1.6;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
}
/* ============================
Cyberpunk Scrollbar Styles
============================ */
/* Default scrollbar - Light */
::-webkit-scrollbar {
width: 8px;
height: 8px;
}
::-webkit-scrollbar-track {
background: rgb(var(--cyber-bg-secondary));
border-left: 1px solid rgb(var(--cyber-neon-cyan) / 0.1);
}
::-webkit-scrollbar-thumb {
background: linear-gradient(180deg, rgb(var(--cyber-neon-cyan) / 0.4), rgb(var(--cyber-neon-pink) / 0.3));
border-radius: 0;
}
::-webkit-scrollbar-thumb:hover {
background: linear-gradient(180deg, rgb(var(--cyber-neon-cyan) / 0.6), rgb(var(--cyber-neon-pink) / 0.5));
}
::-webkit-scrollbar-corner {
background: rgb(var(--cyber-bg-secondary));
}
/* Terminal scrollbar - always dark */
.terminal-scroll::-webkit-scrollbar {
width: 6px;
}
.terminal-scroll::-webkit-scrollbar-track {
background: #000000;
}
.terminal-scroll::-webkit-scrollbar-thumb {
background: rgba(0, 255, 65, 0.4);
border-radius: 0;
}
.terminal-scroll::-webkit-scrollbar-thumb:hover {
background: rgba(0, 255, 65, 0.6);
}
/* ============================
Cyberpunk Grid Background
============================ */
.cyber-grid {
background-color: rgb(var(--cyber-bg-primary));
background-image:
linear-gradient(rgb(var(--cyber-neon-cyan) / 0.03) 1px, transparent 1px),
linear-gradient(90deg, rgb(var(--cyber-neon-cyan) / 0.03) 1px, transparent 1px),
radial-gradient(ellipse at 50% 0%, rgb(var(--cyber-neon-cyan) / 0.06) 0%, transparent 60%);
background-size: 50px 50px, 50px 50px, 100% 100%;
background-position: -1px -1px, -1px -1px, center top;
}
.dark .cyber-grid {
background-image:
linear-gradient(rgba(0, 255, 255, 0.02) 1px, transparent 1px),
linear-gradient(90deg, rgba(0, 255, 255, 0.02) 1px, transparent 1px),
radial-gradient(ellipse at 50% 0%, rgba(0, 255, 255, 0.08) 0%, transparent 60%);
}
/* ============================
Glassmorphism Effects
============================ */
.glass-panel {
background: rgb(var(--glass-bg));
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
border: 1px solid rgb(var(--glass-border));
}
.glass-panel-dark {
background: rgb(var(--glass-dark-bg));
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
border: 1px solid rgb(var(--glass-dark-border));
}
.float-panel {
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1), 0 0 1px rgb(var(--cyber-neon-cyan) / 0.1);
}
.dark .float-panel {
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 0 1px rgba(0, 255, 255, 0.15);
}
.elevated-panel {
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
}
.dark .elevated-panel {
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
/* ============================
Neon Glow Effects
============================ */
/* Text glow - Light mode: subtle shadow, Dark mode: neon glow */
.glow-text-cyan {
text-shadow: 0 1px 3px rgb(var(--cyber-neon-cyan) / 0.3);
}
.dark .glow-text-cyan {
text-shadow:
0 0 5px rgba(0, 255, 255, 0.8),
0 0 10px rgba(0, 255, 255, 0.5),
0 0 20px rgba(0, 255, 255, 0.3);
}
.glow-text-pink {
text-shadow: 0 1px 3px rgb(var(--cyber-neon-pink) / 0.3);
}
.dark .glow-text-pink {
text-shadow:
0 0 5px rgba(255, 0, 128, 0.8),
0 0 10px rgba(255, 0, 128, 0.5),
0 0 20px rgba(255, 0, 128, 0.3);
}
.glow-text-green {
text-shadow: 0 1px 3px rgb(var(--cyber-neon-green) / 0.3);
}
.dark .glow-text-green {
text-shadow:
0 0 5px rgba(0, 255, 65, 0.8),
0 0 10px rgba(0, 255, 65, 0.5),
0 0 20px rgba(0, 255, 65, 0.3);
}
/* Box glow - Light mode: subtle shadow, Dark mode: neon glow */
.glow-cyan {
box-shadow: 0 4px 12px rgb(var(--cyber-neon-cyan) / var(--shadow-glow-opacity));
}
.dark .glow-cyan {
box-shadow:
0 0 5px rgba(0, 255, 255, 0.5),
0 0 10px rgba(0, 255, 255, 0.3),
0 0 20px rgba(0, 255, 255, 0.2),
inset 0 0 5px rgba(0, 255, 255, 0.1);
}
.glow-pink {
box-shadow: 0 4px 12px rgb(var(--cyber-neon-pink) / var(--shadow-glow-opacity));
}
.dark .glow-pink {
box-shadow:
0 0 5px rgba(255, 0, 128, 0.5),
0 0 10px rgba(255, 0, 128, 0.3),
0 0 20px rgba(255, 0, 128, 0.2);
}
.glow-green {
box-shadow: 0 4px 12px rgb(var(--cyber-neon-green) / var(--shadow-glow-opacity));
}
.dark .glow-green {
box-shadow:
0 0 5px rgba(0, 255, 65, 0.5),
0 0 10px rgba(0, 255, 65, 0.3),
0 0 20px rgba(0, 255, 65, 0.2);
}
/* ============================
Corner Decorations
============================ */
.cyber-corner {
position: relative;
}
.cyber-corner::before,
.cyber-corner::after {
content: '';
position: absolute;
width: 12px;
height: 12px;
pointer-events: none;
}
.cyber-corner::before {
top: -1px;
left: -1px;
border-top: 2px solid rgb(var(--cyber-neon-cyan) / 0.5);
border-left: 2px solid rgb(var(--cyber-neon-cyan) / 0.5);
}
.cyber-corner::after {
bottom: -1px;
right: -1px;
border-bottom: 2px solid rgb(var(--cyber-neon-cyan) / 0.5);
border-right: 2px solid rgb(var(--cyber-neon-cyan) / 0.5);
}
/* Four corners variant */
.cyber-corners {
position: relative;
}
.cyber-corners::before {
content: '';
position: absolute;
inset: 0;
background:
linear-gradient(to right, rgb(var(--cyber-neon-cyan) / 0.5) 12px, transparent 12px) 0 0,
linear-gradient(to right, rgb(var(--cyber-neon-cyan) / 0.5) 12px, transparent 12px) 0 100%,
linear-gradient(to left, rgb(var(--cyber-neon-cyan) / 0.5) 12px, transparent 12px) 100% 0,
linear-gradient(to left, rgb(var(--cyber-neon-cyan) / 0.5) 12px, transparent 12px) 100% 100%,
linear-gradient(to bottom, rgb(var(--cyber-neon-cyan) / 0.5) 12px, transparent 12px) 0 0,
linear-gradient(to bottom, rgb(var(--cyber-neon-cyan) / 0.5) 12px, transparent 12px) 100% 0,
linear-gradient(to top, rgb(var(--cyber-neon-cyan) / 0.5) 12px, transparent 12px) 0 100%,
linear-gradient(to top, rgb(var(--cyber-neon-cyan) / 0.5) 12px, transparent 12px) 100% 100%;
background-repeat: no-repeat;
background-size: 2px 12px, 2px 12px, 2px 12px, 2px 12px, 12px 2px, 12px 2px, 12px 2px, 12px 2px;
pointer-events: none;
}
/* ============================
Card Hover Effects
============================ */
/* Scan effect on hover */
.card-scan {
position: relative;
overflow: hidden;
}
.card-scan::after {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(
90deg,
transparent,
rgb(var(--cyber-neon-cyan) / 0.1),
transparent
);
transition: left 0.6s ease-in-out;
pointer-events: none;
}
.card-scan:hover::after {
left: 100%;
}
/* ============================
Cursor Blink
============================ */
.cursor-blink {
animation: cursorBlink 1s step-end infinite;
}
@keyframes cursorBlink {
0%, 100% { opacity: 1; }
50% { opacity: 0; }
}
/* ============================
Status Indicators
============================ */
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
}
.status-dot-online {
background: rgb(var(--cyber-neon-green));
box-shadow: 0 0 8px rgb(var(--cyber-neon-green) / 0.6);
animation: pulseGlow 2s ease-in-out infinite;
}
.status-dot-offline {
background: rgb(var(--cyber-text-muted));
}
.status-dot-warning {
background: rgb(var(--cyber-neon-orange));
box-shadow: 0 0 8px rgb(var(--cyber-neon-orange) / 0.6);
}
.status-dot-error {
background: rgb(var(--cyber-neon-pink));
box-shadow: 0 0 8px rgb(var(--cyber-neon-pink) / 0.6);
}
@keyframes pulseGlow {
0%, 100% {
box-shadow: 0 0 5px currentColor;
}
50% {
box-shadow: 0 0 15px currentColor, 0 0 25px currentColor;
}
}
/* ============================
Input Focus Ring
============================ */
.cyber-focus {
transition: box-shadow 0.2s ease-in-out;
}
.cyber-focus:focus {
outline: none;
box-shadow: 0 0 0 1px rgb(var(--cyber-neon-cyan)), 0 0 10px rgb(var(--cyber-neon-cyan) / 0.3);
border-color: rgb(var(--cyber-neon-cyan));
}
/* ============================
Selection
============================ */
::selection {
background: rgb(var(--cyber-neon-cyan) / 0.3);
color: rgb(var(--cyber-text-primary));
}
::-moz-selection {
background: rgb(var(--cyber-neon-cyan) / 0.3);
color: rgb(var(--cyber-text-primary));
}
/* ============================
Performance Optimizations
============================ */
.will-change-transform {
will-change: transform;
}
.gpu-accelerate {
transform: translateZ(0);
backface-visibility: hidden;
}
+25
View File
@@ -0,0 +1,25 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import App from './App'
import './index.css'
import './i18n'
// Initialize theme store early to prevent flash of wrong theme
import './store/themeStore'
const queryClient = new QueryClient({
defaultOptions: {
queries: {
refetchOnWindowFocus: false,
retry: 1,
},
},
})
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<QueryClientProvider client={queryClient}>
<App />
</QueryClientProvider>
</React.StrictMode>,
)
+153
View File
@@ -0,0 +1,153 @@
import { create } from 'zustand'
import type { LogEntry, CrawlerConfig } from '@/types/crawler'
interface CrawlerState {
// Status
status: 'idle' | 'running' | 'stopping' | 'error'
platform: string | null
crawlerType: string | null
startedAt: string | null
// Logs
logs: LogEntry[]
clearedAfterLogId: number | null // 清除日志后,只显示 id 大于此值的日志
// Config
config: CrawlerConfig
// Actions
setStatus: (status: CrawlerState['status']) => void
setRunningInfo: (platform: string | null, crawlerType: string | null, startedAt: string | null) => void
addLog: (log: LogEntry) => void
setLogs: (logs: LogEntry[]) => void
clearLogs: () => void
restoreLogs: () => void
updateConfig: (config: Partial<CrawlerConfig>) => void
reset: () => void
}
// 持久化相关的 localStorage key
const CLEARED_LOG_ID_KEY = 'mediacrawler_cleared_log_id'
// 从 localStorage 读取清除标记
function getClearedLogIdFromStorage(): number | null {
const stored = localStorage.getItem(CLEARED_LOG_ID_KEY)
if (stored === null) return null
const value = parseInt(stored, 10)
return isNaN(value) ? null : value
}
// 保存清除标记到 localStorage
function saveClearedLogIdToStorage(id: number | null): void {
if (id === null) {
localStorage.removeItem(CLEARED_LOG_ID_KEY)
} else {
localStorage.setItem(CLEARED_LOG_ID_KEY, id.toString())
}
}
const defaultConfig: CrawlerConfig = {
platform: 'bili',
login_type: 'qrcode',
crawler_type: 'search',
keywords: '',
specified_ids: '',
creator_ids: '',
start_page: 1,
enable_comments: true,
enable_sub_comments: false,
save_option: 'json',
cookies: '',
headless: false,
}
export const useCrawlerStore = create<CrawlerState>((set, get) => ({
status: 'idle',
platform: null,
crawlerType: null,
startedAt: null,
logs: [],
clearedAfterLogId: getClearedLogIdFromStorage(), // 从 localStorage 初始化
config: defaultConfig,
setStatus: (status) => {
set({ status })
// 当开始新的爬虫任务时,清除之前的清除标记
if (status === 'running') {
const currentClearedId = get().clearedAfterLogId
if (currentClearedId !== null) {
set({ clearedAfterLogId: null })
saveClearedLogIdToStorage(null)
}
}
},
setRunningInfo: (platform, crawlerType, startedAt) => {
set({ platform, crawlerType, startedAt })
// 当设置新的运行信息时,也清除之前的清除标记
if (startedAt !== null) {
const currentClearedId = get().clearedAfterLogId
if (currentClearedId !== null) {
set({ clearedAfterLogId: null })
saveClearedLogIdToStorage(null)
}
}
},
addLog: (log) => {
const { clearedAfterLogId, logs } = get()
// 如果有清除标记,过滤掉 id 小于等于该标记的日志
if (clearedAfterLogId !== null && log.id <= clearedAfterLogId) {
return
}
// 防止 WebSocket 重连/重复连接导致的重复日志
if (logs.length > 0 && logs[logs.length - 1].id === log.id) {
return
}
if (logs.some((existing) => existing.id === log.id)) {
return
}
set((state) => ({
logs: [...state.logs.slice(-499), log], // Keep last 500 logs
}))
},
setLogs: (logs) => {
const { clearedAfterLogId } = get()
// 如果有清除标记,过滤掉 id 小于等于该标记的日志
const filteredLogs = clearedAfterLogId !== null
? logs.filter((log) => log.id > clearedAfterLogId)
: logs
set({ logs: filteredLogs })
},
clearLogs: () => {
const { logs } = get()
// 记录当前最大的 log id,清除后只显示比这个 id 大的日志
const maxLogId = logs.length > 0 ? Math.max(...logs.map(l => l.id)) : 0
set({ logs: [], clearedAfterLogId: maxLogId })
// 持久化到 localStorage
saveClearedLogIdToStorage(maxLogId)
},
restoreLogs: () => {
// 清除清除标记,这样下次重新加载日志时就会显示所有日志
set({ clearedAfterLogId: null })
saveClearedLogIdToStorage(null)
// 触发日志重新加载(通过刷新页面或重新连接 WebSocket)
window.location.reload()
},
updateConfig: (config) =>
set((state) => ({
config: { ...state.config, ...config },
})),
reset: () =>
set({
status: 'idle',
platform: null,
crawlerType: null,
startedAt: null,
}),
}))
+69
View File
@@ -0,0 +1,69 @@
import { create } from 'zustand'
type Theme = 'light' | 'dark' | 'system'
interface ThemeState {
theme: Theme
resolvedTheme: 'light' | 'dark'
setTheme: (theme: Theme) => void
}
const THEME_KEY = 'mediacrawler_theme'
function getSystemTheme(): 'light' | 'dark' {
if (typeof window === 'undefined') return 'light'
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
}
function getStoredTheme(): Theme {
if (typeof window === 'undefined') return 'light'
const stored = localStorage.getItem(THEME_KEY) as Theme | null
if (stored && ['light', 'dark', 'system'].includes(stored)) {
return stored
}
return 'light' // Default to light
}
function applyTheme(resolved: 'light' | 'dark') {
const root = document.documentElement
if (resolved === 'dark') {
root.classList.add('dark')
} else {
root.classList.remove('dark')
}
}
function resolveTheme(theme: Theme): 'light' | 'dark' {
return theme === 'system' ? getSystemTheme() : theme
}
// Initialize theme immediately to prevent flash
const initialTheme = getStoredTheme()
const initialResolved = resolveTheme(initialTheme)
if (typeof window !== 'undefined') {
applyTheme(initialResolved)
}
export const useThemeStore = create<ThemeState>((set) => ({
theme: initialTheme,
resolvedTheme: initialResolved,
setTheme: (theme) => {
const resolved = resolveTheme(theme)
localStorage.setItem(THEME_KEY, theme)
applyTheme(resolved)
set({ theme, resolvedTheme: resolved })
},
}))
// Listen for system theme changes
if (typeof window !== 'undefined') {
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
const state = useThemeStore.getState()
if (state.theme === 'system') {
const resolved = e.matches ? 'dark' : 'light'
applyTheme(resolved)
useThemeStore.setState({ resolvedTheme: resolved })
}
})
}
+49
View File
@@ -0,0 +1,49 @@
export interface CrawlerConfig {
platform: string
login_type: string
crawler_type: string
keywords: string
specified_ids: string // 详情模式下的帖子/视频ID
creator_ids: string // 创作者模式下的创作者ID
start_page: number
enable_comments: boolean
enable_sub_comments: boolean
save_option: string
cookies: string
headless: boolean
}
export interface CrawlerStatus {
status: 'idle' | 'running' | 'stopping' | 'error'
platform: string | null
crawler_type: string | null
started_at: string | null
error_message: string | null
}
export interface LogEntry {
id: number
timestamp: string
level: 'info' | 'warning' | 'error' | 'success' | 'debug'
message: string
}
export interface DataFile {
name: string
path: string
size: number
modified_at: number
record_count: number | null
type: string
}
export interface Platform {
value: string
label: string
icon: string
}
export interface ConfigOption {
value: string
label: string
}
+1
View File
@@ -0,0 +1 @@
/// <reference types="vite/client" />