feat(client): invite api + provider + auth_api.register 加 inviteCode

This commit is contained in:
wangjia
2026-07-13 07:39:01 +08:00
parent 54d106ca8b
commit cdf67a200c
4 changed files with 86 additions and 0 deletions
+2
View File
@@ -115,12 +115,14 @@ class AuthApi {
required String code,
required String password,
Map<String, dynamic>? device,
String? inviteCode,
}) async {
final resp = await _post('/v1/auth/register', {
'email': email,
'code': code,
'password': password,
if (device != null) 'device': device,
if (inviteCode != null && inviteCode.isNotEmpty) 'invite_code': inviteCode,
});
if (resp.statusCode != 200 && resp.statusCode != 201) {
_throwFromResponse(resp);
+35
View File
@@ -0,0 +1,35 @@
// invite_api.dart — 邀请/奖励任务代理端点封装(JWT 经 ApiClient 自动注入)。
import 'api_client.dart';
class InviteInfo {
const InviteInfo({
required this.code, required this.link, required this.invited,
required this.converted, required this.earnedDays,
required this.tgEnabled, required this.tgJoined, required this.channel,
});
final String code, link, channel;
final int invited, converted, earnedDays;
final bool tgEnabled, tgJoined;
factory InviteInfo.fromJson(Map<String, dynamic> j) {
final tg = (j['telegram'] as Map<String, dynamic>?) ?? const {};
return InviteInfo(
code: j['invite_code'] as String? ?? '',
link: j['invite_link'] as String? ?? '',
invited: (j['invited'] as num?)?.toInt() ?? 0,
converted: (j['converted'] as num?)?.toInt() ?? 0,
earnedDays: (j['earned_days'] as num?)?.toInt() ?? 0,
tgEnabled: tg['enabled'] as bool? ?? false,
tgJoined: tg['joined'] as bool? ?? false,
channel: tg['channel'] as String? ?? '',
);
}
}
class InviteApi {
InviteApi(this._c);
final ApiClient _c;
Future<InviteInfo> fetch() async => InviteInfo.fromJson(await _c.getJson('/v1/invite'));
Future<String> telegramStartLink() async =>
(await _c.getJson('/v1/tasks/telegram/start'))['deep_link'] as String? ?? '';
}