ab073c88ed
- 前端:设置页面添加检查更新菜单项,从 pubspec.yaml 动态获取版本号 - 后端:新增 /api/v1/app/check-updates 接口,自动扫描 releases 目录对比版本 - 配置:新增 AppVersionSettings,支持通过环境变量配置版本和下载链接 - Docker:添加 releases 目录挂载
60 lines
1.7 KiB
Dart
60 lines
1.7 KiB
Dart
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);
|
|
}
|
|
}
|