Files
social-app/apps/lib/features/settings/data/settings_api.dart
T

60 lines
1.7 KiB
Dart
Raw Normal View History

2026-03-16 16:09:07 +08:00
import 'package:social_app/core/api/i_api_client.dart';
class AppVersionResponse {
final bool hasUpdate;
final String latestVersion;
final int latestBuild;
final String minRequiredVersion;
final String updateType;
final String? downloadUrl;
final String? releaseNotes;
AppVersionResponse({
required this.hasUpdate,
required this.latestVersion,
required this.latestBuild,
required this.minRequiredVersion,
required this.updateType,
this.downloadUrl,
this.releaseNotes,
});
factory AppVersionResponse.fromJson(Map<String, dynamic> json) {
return AppVersionResponse(
hasUpdate: json['has_update'] as bool,
latestVersion: json['latest_version'] as String,
latestBuild: json['latest_build'] as int,
minRequiredVersion: json['min_required_version'] as String,
updateType: json['update_type'] as String,
downloadUrl: json['download_url'] as String?,
releaseNotes: json['release_notes'] as String?,
);
}
}
class SettingsApi {
final IApiClient _client;
static const _prefix = '/api/v1/app';
SettingsApi(this._client);
Future<AppVersionResponse> checkUpdates({
required int currentBuild,
String? currentVersion,
String platform = 'android',
}) async {
final params = <String, String>{
'platform': platform,
'current_build': currentBuild.toString(),
};
if (currentVersion != null) {
params['current_version'] = currentVersion;
}
final queryString = params.entries
.map((e) => '${e.key}=${e.value}')
.join('&');
final response = await _client.get('$_prefix/check-updates?$queryString');
return AppVersionResponse.fromJson(response.data);
}
}