2026-03-29 20:26:30 +08:00
|
|
|
import 'package:social_app/data/network/i_api_client.dart';
|
2026-03-16 16:09:07 +08:00
|
|
|
|
|
|
|
|
class AppVersionResponse {
|
|
|
|
|
final bool hasUpdate;
|
2026-03-17 12:18:09 +08:00
|
|
|
final String latestVersionName;
|
|
|
|
|
final int latestVersionCode;
|
|
|
|
|
final int minSupportedVersionCode;
|
2026-03-16 16:09:07 +08:00
|
|
|
final String updateType;
|
|
|
|
|
final String? downloadUrl;
|
|
|
|
|
final String? releaseNotes;
|
2026-03-17 12:18:09 +08:00
|
|
|
final String? fileName;
|
|
|
|
|
final int? fileSize;
|
|
|
|
|
final String? sha256;
|
2026-03-16 16:09:07 +08:00
|
|
|
|
|
|
|
|
AppVersionResponse({
|
|
|
|
|
required this.hasUpdate,
|
2026-03-17 12:18:09 +08:00
|
|
|
required this.latestVersionName,
|
|
|
|
|
required this.latestVersionCode,
|
|
|
|
|
required this.minSupportedVersionCode,
|
2026-03-16 16:09:07 +08:00
|
|
|
required this.updateType,
|
|
|
|
|
this.downloadUrl,
|
|
|
|
|
this.releaseNotes,
|
2026-03-17 12:18:09 +08:00
|
|
|
this.fileName,
|
|
|
|
|
this.fileSize,
|
|
|
|
|
this.sha256,
|
2026-03-16 16:09:07 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
factory AppVersionResponse.fromJson(Map<String, dynamic> json) {
|
|
|
|
|
return AppVersionResponse(
|
|
|
|
|
hasUpdate: json['has_update'] as bool,
|
2026-03-17 12:18:09 +08:00
|
|
|
latestVersionName: json['latest_version_name'] as String,
|
|
|
|
|
latestVersionCode: json['latest_version_code'] as int,
|
|
|
|
|
minSupportedVersionCode: json['min_supported_version_code'] as int,
|
2026-03-16 16:09:07 +08:00
|
|
|
updateType: json['update_type'] as String,
|
|
|
|
|
downloadUrl: json['download_url'] as String?,
|
|
|
|
|
releaseNotes: json['release_notes'] as String?,
|
2026-03-17 12:18:09 +08:00
|
|
|
fileName: json['file_name'] as String?,
|
|
|
|
|
fileSize: json['file_size'] as int?,
|
|
|
|
|
sha256: json['sha256'] as String?,
|
2026-03-16 16:09:07 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class SettingsApi {
|
|
|
|
|
final IApiClient _client;
|
|
|
|
|
static const _prefix = '/api/v1/app';
|
|
|
|
|
|
|
|
|
|
SettingsApi(this._client);
|
|
|
|
|
|
|
|
|
|
Future<AppVersionResponse> checkUpdates({
|
2026-03-17 12:18:09 +08:00
|
|
|
required int currentVersionCode,
|
|
|
|
|
required String currentVersionName,
|
2026-03-16 16:09:07 +08:00
|
|
|
String platform = 'android',
|
2026-03-17 12:18:09 +08:00
|
|
|
String channel = 'release',
|
2026-03-16 16:09:07 +08:00
|
|
|
}) async {
|
2026-03-30 11:37:41 +08:00
|
|
|
final queryParameters = <String, String>{
|
2026-03-16 16:09:07 +08:00
|
|
|
'platform': platform,
|
2026-03-17 12:18:09 +08:00
|
|
|
'channel': channel,
|
|
|
|
|
'current_version_code': currentVersionCode.toString(),
|
|
|
|
|
'current_version_name': currentVersionName,
|
2026-03-16 16:09:07 +08:00
|
|
|
};
|
2026-03-30 11:37:41 +08:00
|
|
|
final response = await _client.get(
|
|
|
|
|
'$_prefix/check-updates',
|
|
|
|
|
queryParameters: queryParameters,
|
|
|
|
|
);
|
2026-03-16 16:09:07 +08:00
|
|
|
return AppVersionResponse.fromJson(response.data);
|
|
|
|
|
}
|
|
|
|
|
}
|