feat: 도메인 시스템 개선 + 검색 한글→영문 번역

주요 변경:
- Domain Agent 제거, 코드 직접 처리로 전환
- suggest_domains: 등록 가능 도메인만 표시, 10개 미만 시 재시도
- search_web: 한글 검색어 자동 영문 번역 (GPT-4o-mini)
- WHOIS: raw 데이터 파싱으로 상세 정보 추출
- 가격 조회: API 필드명 수정 (register_krw → krw)
- 동적 도구 로딩 시스템 추가
- 문서 정리 및 업데이트

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
kappa
2026-01-18 11:15:49 +09:00
parent 28ac6737ad
commit 42ab702d1c
7 changed files with 1056 additions and 231 deletions

View File

@@ -275,6 +275,121 @@ export default {
}
}
// Deposit API - 잔액 조회 (namecheap-api 전용)
if (url.pathname === '/api/deposit/balance' && request.method === 'GET') {
try {
const apiSecret = env.DEPOSIT_API_SECRET;
const authHeader = request.headers.get('X-API-Key');
if (!apiSecret || authHeader !== apiSecret) {
return Response.json({ error: 'Unauthorized' }, { status: 401 });
}
const telegramId = url.searchParams.get('telegram_id');
if (!telegramId) {
return Response.json({ error: 'telegram_id required' }, { status: 400 });
}
// 사용자 조회
const user = await env.DB.prepare(
'SELECT id FROM users WHERE telegram_id = ?'
).bind(telegramId).first<{ id: number }>();
if (!user) {
return Response.json({ error: 'User not found' }, { status: 404 });
}
// 잔액 조회
const deposit = await env.DB.prepare(
'SELECT balance FROM user_deposits WHERE user_id = ?'
).bind(user.id).first<{ balance: number }>();
return Response.json({
telegram_id: telegramId,
balance: deposit?.balance || 0,
});
} catch (error) {
console.error('[API] Deposit balance error:', error);
return Response.json({ error: String(error) }, { status: 500 });
}
}
// Deposit API - 잔액 차감 (namecheap-api 전용)
if (url.pathname === '/api/deposit/deduct' && request.method === 'POST') {
try {
const apiSecret = env.DEPOSIT_API_SECRET;
const authHeader = request.headers.get('X-API-Key');
if (!apiSecret || authHeader !== apiSecret) {
return Response.json({ error: 'Unauthorized' }, { status: 401 });
}
const body = await request.json() as {
telegram_id: string;
amount: number;
reason: string;
reference_id?: string;
};
if (!body.telegram_id || !body.amount || !body.reason) {
return Response.json({ error: 'telegram_id, amount, reason required' }, { status: 400 });
}
if (body.amount <= 0) {
return Response.json({ error: 'Amount must be positive' }, { status: 400 });
}
// 사용자 조회
const user = await env.DB.prepare(
'SELECT id FROM users WHERE telegram_id = ?'
).bind(body.telegram_id).first<{ id: number }>();
if (!user) {
return Response.json({ error: 'User not found' }, { status: 404 });
}
// 현재 잔액 확인
const deposit = await env.DB.prepare(
'SELECT balance FROM user_deposits WHERE user_id = ?'
).bind(user.id).first<{ balance: number }>();
const currentBalance = deposit?.balance || 0;
if (currentBalance < body.amount) {
return Response.json({
error: 'Insufficient balance',
current_balance: currentBalance,
required: body.amount,
}, { status: 400 });
}
// 트랜잭션: 잔액 차감 + 거래 기록
await env.DB.batch([
env.DB.prepare(
'UPDATE user_deposits SET balance = balance - ?, updated_at = CURRENT_TIMESTAMP WHERE user_id = ?'
).bind(body.amount, user.id),
env.DB.prepare(
`INSERT INTO deposit_transactions (user_id, type, amount, status, description, confirmed_at)
VALUES (?, 'deduct', ?, 'confirmed', ?, CURRENT_TIMESTAMP)`
).bind(user.id, body.amount, body.reason),
]);
const newBalance = currentBalance - body.amount;
console.log(`[API] Deposit deducted: user=${body.telegram_id}, amount=${body.amount}, reason=${body.reason}`);
return Response.json({
success: true,
telegram_id: body.telegram_id,
deducted: body.amount,
previous_balance: currentBalance,
new_balance: newBalance,
});
} catch (error) {
console.error('[API] Deposit deduct error:', error);
return Response.json({ error: String(error) }, { status: 500 });
}
}
// Telegram Webhook 처리
if (url.pathname === '/webhook') {
// 보안 검증