trading 不再管理 ラクマ 的购物车购买、支付与订单监控。删除 auth_site / auth_session / login_runner / models.AuthSite 中的 rakuma 分支与常量、 account.yaml.example 的 rakuma 段,并清理相关测试。scraping 侧的 ラクマ 抓取 API(/api/rakuma/*)保留不动。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
71 lines
2.1 KiB
Python
71 lines
2.1 KiB
Python
"""交易侧 API 数据模型:登录态、(后续的)加购、下单与订单监控
|
|
|
|
与抓取侧模型(app/scraping/models/scrape.py)分开的理由和服务本身拆开的理由
|
|
一致:抓取模型描述的是「站点上有什么」,这里描述的是「我们对某个账号做了什么、
|
|
现在处于哪一步」——后者有生命周期、有状态迁移,会持久化,不是一次请求的产物。
|
|
|
|
响应信封 `ApiResponse` 与抓取侧共用,在 app/shared/api.py。
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from enum import StrEnum
|
|
from typing import Any
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class AuthSite(StrEnum):
|
|
"""支持登录的站点
|
|
|
|
交易服务只管理乐天市场的购物车购买、支付与订单监控;ラクマ 不进入交易链路。
|
|
"""
|
|
|
|
RAKUTEN = "rakuten"
|
|
|
|
|
|
class AuthStatusRequest(BaseModel):
|
|
"""登录态查询请求"""
|
|
|
|
site: AuthSite | None = None # 不传则返回所有已配置站点
|
|
refresh: bool = True # 是否真实打一次请求探测;false 时只读缓存
|
|
|
|
|
|
class AuthSiteStatus(BaseModel):
|
|
"""单站登录态"""
|
|
|
|
site: str
|
|
state_file_exists: bool # 是否已跑过 scripts/login.py
|
|
logged_in: bool | None # None 表示尚未探测
|
|
checked_age_seconds: float | None = None
|
|
detail: str = ""
|
|
|
|
|
|
class AuthStatusData(BaseModel):
|
|
"""登录态查询响应"""
|
|
|
|
sites: list[AuthSiteStatus] = Field(default_factory=list)
|
|
|
|
|
|
class AuthReloadRequest(BaseModel):
|
|
"""重新加载登录态请求(人工登录完成后调用,免重启服务)"""
|
|
|
|
site: AuthSite | None = None # 不传则重载所有已配置站点
|
|
|
|
|
|
class AuthReloadData(BaseModel):
|
|
"""重新加载登录态响应"""
|
|
|
|
reloaded: dict[str, int] = Field(default_factory=dict) # site -> cookie 条数
|
|
sites: list[AuthSiteStatus] = Field(default_factory=list)
|
|
|
|
|
|
class TradingHealthData(BaseModel):
|
|
"""交易服务健康检查响应数据
|
|
|
|
只读缓存的登录态,不触发网络探测——健康检查会被高频轮询,实时结果请用
|
|
POST /api/auth/status。
|
|
"""
|
|
|
|
status: str
|
|
auth: dict[str, Any] = Field(default_factory=dict)
|