feat: initial commit - Go + CGO captcha recognition service
Build and Deploy / build-frontend (push) Failing after 2s
Build and Deploy / build-backend (push) Has been skipped
Build and Deploy / build-docker (push) Has been skipped
Build and Deploy / deploy (push) Has been skipped

Features:
- Go + CGO ONNX/OpenCV wrapper for high performance
- SQLite (default) / MySQL database support
- Optional Redis caching
- JWT authentication system
- Multiple captcha recognition APIs:
  - OCR text recognition
  - Slider captcha matching
  - Image similarity comparison
  - Rotation captcha detection
  - Object detection
- React frontend with install wizard
- Docker and docker-compose support
- Gitea CI/CD pipeline

Project structure:
- cmd/server: Main entry point
- internal/: Core business logic
- pkg/onnx: ONNX Runtime CGO wrapper
- pkg/opencv: OpenCV CGO wrapper
- web/: React frontend
- deploy/: Deployment configs
- scripts/: Utility scripts
This commit is contained in:
2026-07-16 08:56:38 +00:00
commit 524c404194
32 changed files with 2971 additions and 0 deletions
+101
View File
@@ -0,0 +1,101 @@
import { useState } from 'react'
interface Props {
token: string
}
export default function AdminPage({ token }: Props) {
const [points, setPoints] = useState(1000)
const [codes, setCodes] = useState<any[]>([])
const [loading, setLoading] = useState(false)
const generateCode = async () => {
setLoading(true)
try {
const res = await fetch('/api/admin/generate_code', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({ points })
})
if (res.ok) {
loadCodes()
}
} finally {
setLoading(false)
}
}
const loadCodes = async () => {
const res = await fetch('/api/admin/regcodes', {
headers: { 'Authorization': `Bearer ${token}` }
})
if (res.ok) {
setCodes(await res.json())
}
}
return (
<div className="container">
<h1 className="mb-4"></h1>
<div className="card">
<h2 className="mb-4"></h2>
<div className="flex gap-4 items-center">
<div className="form-group" style={{ flex: 1 }}>
<label className="label"></label>
<input
type="number"
className="input"
value={points}
onChange={e => setPoints(Number(e.target.value))}
/>
</div>
<button
className="button"
onClick={generateCode}
disabled={loading}
>
{loading ? '生成中...' : '生成注册码'}
</button>
</div>
</div>
<div className="card">
<h2 className="mb-4"></h2>
{codes.length === 0 ? (
<p style={{ color: 'var(--text-muted)' }}></p>
) : (
<div style={{ overflowX: 'auto' }}>
<table style={{ width: '100%', borderCollapse: 'collapse' }}>
<thead>
<tr style={{ borderBottom: '1px solid var(--border)' }}>
<th style={{ padding: '12px', textAlign: 'left' }}></th>
<th style={{ padding: '12px', textAlign: 'left' }}></th>
<th style={{ padding: '12px', textAlign: 'left' }}></th>
</tr>
</thead>
<tbody>
{codes.map((code: any) => (
<tr key={code.id} style={{ borderBottom: '1px solid var(--border)' }}>
<td style={{ padding: '12px' }}>{code.code}</td>
<td style={{ padding: '12px' }}>{code.points}</td>
<td style={{ padding: '12px' }}>
{code.is_used ? '已使用' : '未使用'}
</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</div>
</div>
)
}
+48
View File
@@ -0,0 +1,48 @@
import { Link } from 'react-router-dom'
interface Props {
token: string
}
export default function HomePage({ token }: Props) {
const handleLogout = () => {
localStorage.removeItem('token')
window.location.href = '/login'
}
return (
<div className="container">
<div className="flex justify-between items-center mb-4">
<h1>AntiCaptcha </h1>
<div className="flex gap-2">
<Link to="/admin" className="button button-secondary"></Link>
<button onClick={handleLogout} className="button button-secondary">退</button>
</div>
</div>
<div className="card">
<h2 className="mb-4">API 使</h2>
<p style={{ color: 'var(--text-secondary)', marginBottom: '16px' }}>
使 Authorization: Bearer {token.substring(0, 20)}...
</p>
<div style={{ background: 'var(--bg-tertiary)', padding: '16px', borderRadius: '8px' }}>
<code style={{ color: 'var(--text-primary)' }}>
POST /api/ocr - OCR <br/>
POST /api/slider/match - <br/>
POST /api/compare/similarity - <br/>
POST /api/rotate/single/rotate - <br/>
POST /api/detection/icon - <br/>
</code>
</div>
</div>
<div className="card">
<h2 className="mb-4"></h2>
<p style={{ color: 'var(--text-secondary)' }}>
</p>
</div>
</div>
)
}
+319
View File
@@ -0,0 +1,319 @@
import { useState } from 'react'
interface Props {
onInstall: () => void
}
export default function InstallPage({ onInstall }: Props) {
const [step, setStep] = useState(1)
const [loading, setLoading] = useState(false)
const [error, setError] = useState('')
const [config, setConfig] = useState({
database: {
type: 'sqlite',
host: 'localhost',
port: 3306,
user: 'root',
password: '',
database: 'anticaptcha',
sqlite: { path: './data/app.db' }
},
redis: {
enabled: false,
host: 'localhost',
port: 6379,
password: '',
db: 0
},
admin: {
username: 'admin',
password: ''
}
})
const handleSubmit = async () => {
setLoading(true)
setError('')
try {
const res = await fetch('/api/install', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(config)
})
const data = await res.json()
if (!res.ok) {
setError(data.error || '安装失败')
return
}
onInstall()
window.location.href = '/'
} catch {
setError('网络错误')
} finally {
setLoading(false)
}
}
return (
<div className="container" style={{ maxWidth: '600px', marginTop: '50px' }}>
<div className="card">
<h1 style={{ marginBottom: '8px' }}>AntiCaptcha </h1>
<p style={{ color: 'var(--text-muted)', marginBottom: '32px' }}>
{step} / 3
</p>
{step === 1 && (
<>
<h2 className="mb-4"></h2>
<div className="form-group">
<label className="label"></label>
<select
className="input"
value={config.database.type}
onChange={e => setConfig({
...config,
database: { ...config.database, type: e.target.value }
})}
>
<option value="sqlite">SQLite</option>
<option value="mysql">MySQL</option>
</select>
</div>
{config.database.type === 'sqlite' ? (
<div className="form-group">
<label className="label"></label>
<input
type="text"
className="input"
value={config.database.sqlite.path}
onChange={e => setConfig({
...config,
database: {
...config.database,
sqlite: { path: e.target.value }
}
})}
/>
</div>
) : (
<>
<div className="grid grid-cols-2 gap-4">
<div className="form-group">
<label className="label"></label>
<input
type="text"
className="input"
value={config.database.host}
onChange={e => setConfig({
...config,
database: { ...config.database, host: e.target.value }
})}
/>
</div>
<div className="form-group">
<label className="label"></label>
<input
type="number"
className="input"
value={config.database.port}
onChange={e => setConfig({
...config,
database: { ...config.database, port: Number(e.target.value) }
})}
/>
</div>
</div>
<div className="grid grid-cols-2 gap-4">
<div className="form-group">
<label className="label"></label>
<input
type="text"
className="input"
value={config.database.user}
onChange={e => setConfig({
...config,
database: { ...config.database, user: e.target.value }
})}
/>
</div>
<div className="form-group">
<label className="label"></label>
<input
type="password"
className="input"
value={config.database.password}
onChange={e => setConfig({
...config,
database: { ...config.database, password: e.target.value }
})}
/>
</div>
</div>
<div className="form-group">
<label className="label"></label>
<input
type="text"
className="input"
value={config.database.database}
onChange={e => setConfig({
...config,
database: { ...config.database, database: e.target.value }
})}
/>
</div>
</>
)}
<button className="button" onClick={() => setStep(2)}>
</button>
</>
)}
{step === 2 && (
<>
<h2 className="mb-4">Redis </h2>
<div className="form-group">
<label className="flex gap-2 items-center">
<input
type="checkbox"
checked={config.redis.enabled}
onChange={e => setConfig({
...config,
redis: { ...config.redis, enabled: e.target.checked }
})}
/>
Redis
</label>
</div>
{config.redis.enabled && (
<>
<div className="grid grid-cols-2 gap-4">
<div className="form-group">
<label className="label"></label>
<input
type="text"
className="input"
value={config.redis.host}
onChange={e => setConfig({
...config,
redis: { ...config.redis, host: e.target.value }
})}
/>
</div>
<div className="form-group">
<label className="label"></label>
<input
type="number"
className="input"
value={config.redis.port}
onChange={e => setConfig({
...config,
redis: { ...config.redis, port: Number(e.target.value) }
})}
/>
</div>
</div>
<div className="grid grid-cols-2 gap-4">
<div className="form-group">
<label className="label"></label>
<input
type="password"
className="input"
value={config.redis.password}
onChange={e => setConfig({
...config,
redis: { ...config.redis, password: e.target.value }
})}
/>
</div>
<div className="form-group">
<label className="label"></label>
<input
type="number"
className="input"
value={config.redis.db}
onChange={e => setConfig({
...config,
redis: { ...config.redis, db: Number(e.target.value) }
})}
/>
</div>
</div>
</>
)}
<div className="flex gap-2">
<button className="button button-secondary" onClick={() => setStep(1)}>
</button>
<button className="button" onClick={() => setStep(3)}>
</button>
</div>
</>
)}
{step === 3 && (
<>
<h2 className="mb-4"></h2>
<div className="form-group">
<label className="label"></label>
<input
type="text"
className="input"
value={config.admin.username}
onChange={e => setConfig({
...config,
admin: { ...config.admin, username: e.target.value }
})}
/>
</div>
<div className="form-group">
<label className="label"></label>
<input
type="password"
className="input"
value={config.admin.password}
onChange={e => setConfig({
...config,
admin: { ...config.admin, password: e.target.value }
})}
placeholder="请输入管理员密码"
/>
</div>
{error && <div className="error">{error}</div>}
<div className="flex gap-2">
<button className="button button-secondary" onClick={() => setStep(2)}>
</button>
<button
className="button"
onClick={handleSubmit}
disabled={loading}
>
{loading ? '安装中...' : '完成安装'}
</button>
</div>
</>
)}
</div>
</div>
)
}
+84
View File
@@ -0,0 +1,84 @@
import { useState } from 'react'
interface Props {
onLogin: (token: string) => void
}
export default function LoginPage({ onLogin }: Props) {
const [username, setUsername] = useState('')
const [password, setPassword] = useState('')
const [error, setError] = useState('')
const [loading, setLoading] = useState(false)
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault()
setError('')
setLoading(true)
try {
const res = await fetch('/api/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password }),
})
const data = await res.json()
if (!res.ok) {
setError(data.error || '登录失败')
return
}
localStorage.setItem('token', data.access_token)
onLogin(data.access_token)
} catch {
setError('网络错误')
} finally {
setLoading(false)
}
}
return (
<div className="container" style={{ maxWidth: '400px', marginTop: '100px' }}>
<div className="card">
<h1 style={{ marginBottom: '24px', textAlign: 'center' }}></h1>
<form onSubmit={handleSubmit}>
<div className="form-group">
<label className="label"></label>
<input
type="text"
className="input"
value={username}
onChange={e => setUsername(e.target.value)}
placeholder="请输入用户名"
required
/>
</div>
<div className="form-group">
<label className="label"></label>
<input
type="password"
className="input"
value={password}
onChange={e => setPassword(e.target.value)}
placeholder="请输入密码"
required
/>
</div>
{error && <div className="error">{error}</div>}
<button type="submit" className="button" style={{ width: '100%' }} disabled={loading}>
{loading ? '登录中...' : '登录'}
</button>
</form>
<div className="text-center mt-4">
<a href="/register" style={{ color: 'var(--primary)' }}></a>
</div>
</div>
</div>
)
}
+96
View File
@@ -0,0 +1,96 @@
import { useState } from 'react'
export default function RegisterPage() {
const [username, setUsername] = useState('')
const [password, setPassword] = useState('')
const [code, setCode] = useState('')
const [error, setError] = useState('')
const [success, setSuccess] = useState('')
const [loading, setLoading] = useState(false)
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault()
setError('')
setSuccess('')
setLoading(true)
try {
const res = await fetch('/api/register', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password, registration_code: code }),
})
const data = await res.json()
if (!res.ok) {
setError(data.error || '注册失败')
return
}
setSuccess('注册成功,请登录')
setTimeout(() => window.location.href = '/login', 2000)
} catch {
setError('网络错误')
} finally {
setLoading(false)
}
}
return (
<div className="container" style={{ maxWidth: '400px', marginTop: '100px' }}>
<div className="card">
<h1 style={{ marginBottom: '24px', textAlign: 'center' }}></h1>
<form onSubmit={handleSubmit}>
<div className="form-group">
<label className="label"></label>
<input
type="text"
className="input"
value={username}
onChange={e => setUsername(e.target.value)}
placeholder="请输入用户名"
required
/>
</div>
<div className="form-group">
<label className="label"></label>
<input
type="password"
className="input"
value={password}
onChange={e => setPassword(e.target.value)}
placeholder="请输入密码"
required
/>
</div>
<div className="form-group">
<label className="label"></label>
<input
type="text"
className="input"
value={code}
onChange={e => setCode(e.target.value)}
placeholder="请输入注册码"
required
/>
</div>
{error && <div className="error">{error}</div>}
{success && <div className="success">{success}</div>}
<button type="submit" className="button" style={{ width: '100%' }} disabled={loading}>
{loading ? '注册中...' : '注册'}
</button>
</form>
<div className="text-center mt-4">
<a href="/login" style={{ color: 'var(--primary)' }}></a>
</div>
</div>
</div>
)
}