重构: 账号管理抽离、强类型返回、消除反射、删除死字段

- 抽离账号管理为独立 AccountStore,Scheduler 只持有引用,
  职责单一化(scheduler.go 减少 ~110 行)
- Wails 绑定方法返回结构体替代 map[string]any(新增 responses.go),
  前端获得强类型,字段名保持兼容无需改前端
- ExchangeRecord 移至 types 包,消除 types↔client 循环依赖
- extractAPIStatus 用 apiResponder 接口替代 reflect 逐字段查找,
  types.APIResponse 与 ExchangeListResponse 实现 APIStatus 方法
- 删除 types.Account.Password 死字段(鉴权仅用 Cookie)
- 重新生成 Wails 绑定,前端 vue-tsc 类型检查通过
This commit is contained in:
yml2213
2026-07-29 12:47:01 +08:00
parent 3ae9cb4a42
commit 7c2c5a61a6
7 changed files with 450 additions and 287 deletions
+138
View File
@@ -0,0 +1,138 @@
package types
// 本文件定义 Wails 绑定方法的结构化返回类型,替代原先的 map[string]any。
// 字段名与历史 map key 保持一致,前端无需改动。
// 使用 omitempty 让 error 在成功时不出现在 JSON 中。
// SimpleResult 仅含 success 标志的结果。
type SimpleResult struct {
Success bool `json:"success"`
}
// ErrorResult 携带错误信息的结果。
type ErrorResult struct {
Success bool `json:"success"`
Error string `json:"error,omitempty"`
}
// MessageResult 携带成功消息的结果。
type MessageResult struct {
Success bool `json:"success"`
Msg string `json:"msg,omitempty"`
Error string `json:"error,omitempty"`
}
// CountResult 携带计数的通用结果。
type CountResult struct {
Success bool `json:"success"`
Count int `json:"count"`
Error string `json:"error,omitempty"`
}
// ReloadAccountsResult 重新加载账号结果。
type ReloadAccountsResult struct {
Success bool `json:"success"`
Count int `json:"count"`
}
// CancelScheduleResult 取消定时抢购结果。
type CancelScheduleResult struct {
Success bool `json:"success"`
Stopped bool `json:"stopped"`
}
// LogsResult 增量日志查询结果。
type LogsResult struct {
Success bool `json:"success"`
Logs []LogEntry `json:"logs"`
Since int64 `json:"since"`
File string `json:"file"`
}
// TimeResult 服务端/本地时间查询结果。
type TimeResult struct {
ServerTime string `json:"serverTime"`
LocalTime string `json:"localTime"`
Source string `json:"source"`
}
// ScoreResult 积分查询结果。score 为字符串:成功时为数字字符串,失败时为错误描述。
type ScoreResult struct {
Score string `json:"score"`
}
// ExchangeRecordsResult 兑换记录查询结果。
type ExchangeRecordsResult struct {
Success bool `json:"success"`
Records []ExchangeRecord `json:"records,omitempty"`
Count int `json:"count"`
Error string `json:"error,omitempty"`
}
// AccountExchangeResult 单账号兑换记录查询结果(VerifyAllExchange 的 value)。
type AccountExchangeResult struct {
Success bool `json:"success"`
Records []ExchangeRecord `json:"records,omitempty"`
Count int `json:"count"`
Error string `json:"error,omitempty"`
}
// AccountHitResult 单账号命中结果(VerifyAndExport 的 value)。
type AccountHitResult struct {
Success bool `json:"success"`
Hit bool `json:"hit,omitempty"`
Error string `json:"error,omitempty"`
}
// VerifyAndExportResult 复验并导出结果。
type VerifyAndExportResult struct {
Success bool `json:"success"`
HitCount int `json:"hitCount"`
MissCount int `json:"missCount"`
HitAccounts []string `json:"hitAccounts"`
MissAccounts []string `json:"missAccounts"`
Details map[string]AccountHitResult `json:"details"`
}
// VerifyAllExchangeResult 批量复验结果。
type VerifyAllExchangeResult struct {
Results map[string]AccountExchangeResult `json:"results"`
}
// ExportAccountsResult 导出账号结果。
type ExportAccountsResult struct {
Success bool `json:"success"`
Count int `json:"count"`
FilePath string `json:"filePath,omitempty"`
Error string `json:"error,omitempty"`
}
// OrganizeAccountsResult 整理账号结果。
type OrganizeAccountsResult struct {
Success bool `json:"success"`
HitCount int `json:"hitCount"`
MissCount int `json:"missCount"`
HitAccounts []string `json:"hitAccounts"`
MissAccounts []string `json:"missAccounts"`
ExportResult ExportAccountsResult `json:"exportResult,omitempty"`
Error string `json:"error,omitempty"`
}
// SwitchActivityResult 切换活动结果。
type SwitchActivityResult struct {
Success bool `json:"success"`
Activity string `json:"activity,omitempty"`
DisplayName string `json:"displayName,omitempty"`
Error string `json:"error,omitempty"`
}
// ScheduleResult 定时抢购设置结果。
type ScheduleResult struct {
Success bool `json:"success"`
TargetTime string `json:"targetTime"`
TriggerTime string `json:"triggerTime"`
RemainSecond int `json:"remainSecond"`
OffsetMs int64 `json:"offsetMs"`
ErrorBoundMs int64 `json:"errorBoundMs"`
RttMs int64 `json:"rttMs"`
}
+19 -3
View File
@@ -54,10 +54,10 @@ type TraceConfig struct {
}
// Account 账号信息。
// 密码段保留在账号文件中以兼容历史格式,但程序不读取也不使用密码,鉴权完全基于 Cookie。
type Account struct {
Name string `json:"name"`
Password string `json:"password"`
Cookie string `json:"cookie"`
Name string `json:"name"`
Cookie string `json:"cookie"`
}
// Product 商品信息。
@@ -106,6 +106,11 @@ type APIResponse struct {
Data json.RawMessage `json:"data"`
}
// APIStatus 返回斗鱼 API 的 error/msg 状态,实现 client.apiResponder 接口。
func (a APIResponse) APIStatus() (int, string, bool) {
return a.Error, a.Msg, true
}
// LogEntry 日志条目。
type LogEntry struct {
ID int64 `json:"id"`
@@ -193,3 +198,14 @@ type AttemptCache struct {
Qualified bool
LastCheck time.Time
}
// ExchangeRecord 兑换记录。
type ExchangeRecord struct {
CommodityID string `json:"commodityId"`
CommodityName string `json:"commodityName"`
NickName string `json:"nickName"`
ShowName string `json:"showName"`
ExchangeNum int `json:"exchangeNum"`
Time string `json:"time"`
Score string `json:"score"`
}