Add Docker build with Gitea Actions CI

- Add Dockerfile with Python 3.13 + uv
- Add Gitea Actions workflow for auto-build on push
- Add deposit_api.py for balance management
- Update api_server.py with domain registration endpoint

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
kaffa
2026-02-03 00:25:10 +09:00
parent 050fb8205e
commit e171440ffd
6 changed files with 185 additions and 13 deletions

View File

@@ -383,6 +383,7 @@ class DomainRegisterRequest(BaseModel):
domain: str
years: int = 1
add_whois_guard: bool = True
telegram_id: Optional[str] = None # 예치금 결제 시 필수
# Registrant info (optional - uses default if not provided)
first_name: Optional[str] = None
last_name: Optional[str] = None
@@ -415,15 +416,55 @@ def get_default_registrant() -> RegistrantInfo:
@app.post("/domains/register")
def register_domain(req: DomainRegisterRequest):
async def register_domain(req: DomainRegisterRequest):
"""
Register a new domain. WARNING: This will charge your account.
If registrant info is not provided, uses default from environment.
Register a new domain with deposit balance check.
- telegram_id: Required for deposit payment
- Checks balance before registration
- Deducts from deposit after successful registration
"""
from namecheap import NamecheapError
# Use provided info or fall back to defaults
from deposit_api import get_balance, deduct_balance
from db import get_prices, init_db
# telegram_id 필수 체크
if not req.telegram_id:
raise HTTPException(
status_code=400,
detail="telegram_id is required for domain registration"
)
# 1. 도메인 가격 조회
init_db()
tld = req.domain.rsplit(".", 1)[-1] if "." in req.domain else req.domain
prices = get_prices()
price_info = next((p for p in prices if p["tld"] == tld), None)
if not price_info:
raise HTTPException(
status_code=400,
detail=f"TLD '{tld}' pricing not found"
)
price_krw = price_info["krw"] * req.years
# 2. 예치금 잔액 확인
balance_result = await get_balance(req.telegram_id)
if "error" in balance_result:
raise HTTPException(
status_code=400,
detail=f"잔액 조회 실패: {balance_result['error']}"
)
current_balance = balance_result.get("balance", 0)
if current_balance < price_krw:
raise HTTPException(
status_code=400,
detail=f"잔액 부족: 현재 {current_balance:,}원, 필요 {price_krw:,}"
)
# 3. Registrant 정보 준비
default = get_default_registrant()
registrant = RegistrantInfo(
first_name=req.first_name or default.first_name,
@@ -438,17 +479,18 @@ def register_domain(req: DomainRegisterRequest):
phone=req.phone or default.phone,
email=req.email or default.email,
)
# Validate required fields
required = ["first_name", "last_name", "address1", "city", "state_province",
# 필수 필드 체크
required = ["first_name", "last_name", "address1", "city", "state_province",
"postal_code", "country", "phone", "email"]
missing = [f for f in required if not getattr(registrant, f)]
if missing:
raise HTTPException(
status_code=400,
detail=f"Missing required registrant fields: {', '.join(missing)}. Set DEFAULT_* env vars or provide in request."
status_code=400,
detail=f"Missing required registrant fields: {', '.join(missing)}. Set REGISTRANT_* env vars."
)
# 4. 도메인 등록
try:
result = api.domains_create(
domain=req.domain,
@@ -456,10 +498,25 @@ def register_domain(req: DomainRegisterRequest):
years=req.years,
add_whois_guard=req.add_whois_guard,
)
return result
except NamecheapError as e:
raise HTTPException(status_code=400, detail=str(e))
# 5. 등록 성공 시 예치금 차감
if result.get("registered"):
deduct_result = await deduct_balance(
telegram_id=req.telegram_id,
amount=price_krw,
reason=f"도메인 등록: {req.domain} ({req.years}년)"
)
if "error" in deduct_result:
# 차감 실패 시 경고 (도메인은 이미 등록됨)
result["warning"] = f"도메인은 등록되었으나 예치금 차감 실패: {deduct_result['error']}"
else:
result["deposit_deducted"] = price_krw
result["new_balance"] = deduct_result.get("new_balance", 0)
return result
if __name__ == "__main__":
import uvicorn