Files
pangolin/client/lib/models/me.dart
T
wangjia 64f96fe018 refactor(api): /v1/me 收敛 expire_at → 只发 expires_at(无 web 用户中心)
之前后端同时发 expire_at + expires_at(分别给 app + web 用户中心)。现已无 web 端,
双发是纯冗余,统一只用 expires_at:
- account.go:meResponse 删 ExpireAt 字段 + GetMe handler 不再赋值
- client me.dart:fromJson 删 (expires_at ?? expire_at) 别名回退
- 两端契约快照同步:Go meResponse 冻结集去 expire_at(12→11 key)、删 Dart 别名测试
- 验证:go test httpapi 绿、flutter test contract(14)绿、analyze EXIT 0、e2e 全链路绿

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-25 10:08:50 +08:00

62 lines
1.8 KiB
Dart

// me.dart — 当前账户聚合视图(GET /v1/me)。
//
// 一发覆盖账号/套餐/配额/今日+周流量,对齐后端契约
// (server/internal/httpapi/account.go + web/usercenter http.ts)。
/// 账户档案。字段对齐后端 snake_case JSON。
class Me {
const Me({
required this.email,
required this.plan,
this.expiresAt,
this.devicesUsed = 0,
this.devicesMax = 1,
this.quotaTodayMin,
this.dataTodayGb = 0,
this.weeklyGb = const [],
this.totpEnabled = false,
});
final String email;
/// 'free' | 'pro' | 'team'。
final String plan;
/// 订阅到期(UTC);免费版/无订阅为 null。
final DateTime? expiresAt;
final int devicesUsed;
final int devicesMax;
/// 今日**剩余**额度(分钟);null = 不限(pro/team)。
/// 后端已算好 = 套餐每日上限 − 今日已用。
final int? quotaTodayMin;
/// 今日已用流量(GB)。
final double dataTodayGb;
/// 近 7 天每日流量(GB),旧→新。
final List<double> weeklyGb;
final bool totpEnabled;
bool get isFree => plan == 'free';
factory Me.fromJson(Map<String, dynamic> m) {
final exp = m['expires_at'] as String?;
return Me(
email: m['email'] as String? ?? '',
plan: m['plan'] as String? ?? 'free',
expiresAt: (exp != null && exp.isNotEmpty) ? DateTime.tryParse(exp) : null,
devicesUsed: (m['devices_used'] as num?)?.toInt() ?? 0,
devicesMax: (m['devices_max'] as num?)?.toInt() ?? 1,
quotaTodayMin: (m['quota_today_min'] as num?)?.toInt(),
dataTodayGb: (m['data_today_gb'] as num?)?.toDouble() ?? 0,
weeklyGb: ((m['weekly_gb'] as List<dynamic>?) ?? const [])
.map((e) => (e as num).toDouble())
.toList(),
totpEnabled: m['totp_enabled'] as bool? ?? false,
);
}
}