fix(mobile): fix version check API and platform detection in both apps
genex-mobile/lib/core/updater/version_checker.dart
- platform 从写死 'android' 改为运行时检测 Platform.isIOS ? 'IOS' : 'ANDROID'
admin-app/lib/core/updater/version_checker.dart
- API 路径修正: /api/app/version/check → /api/v1/app/version/check
- 新增 app_type: 'ADMIN_APP'(原缺失,后端默认返回 GENEX_MOBILE 版本)
- platform 从写死 'android' 改为运行时检测
- 响应解析修正: 原逻辑把外层 {code,data} 当版本数据用,
改为正确取 response.data['data'] 内层对象
- 新增 downloadUrl 相对路径修复(向下兼容旧记录)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
7ba5401e2f
commit
0c3ef3b598
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'dart:io' show Platform;
|
||||
import 'models/version_info.dart';
|
||||
|
||||
/// 版本检测器
|
||||
|
|
@ -27,26 +28,34 @@ class VersionChecker {
|
|||
final currentInfo = await getCurrentVersion();
|
||||
debugPrint('[VersionChecker] 当前版本: ${currentInfo.version}, buildNumber: ${currentInfo.buildNumber}');
|
||||
|
||||
final platform = Platform.isIOS ? 'IOS' : 'ANDROID';
|
||||
final response = await _dio.get(
|
||||
'/api/app/version/check',
|
||||
'/api/v1/app/version/check',
|
||||
queryParameters: {
|
||||
'platform': 'android',
|
||||
'app_type': 'ADMIN_APP',
|
||||
'platform': platform,
|
||||
'current_version': currentInfo.version,
|
||||
'current_version_code': currentInfo.buildNumber,
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200 && response.data != null) {
|
||||
final data = response.data is Map<String, dynamic>
|
||||
? response.data as Map<String, dynamic>
|
||||
: (response.data['data'] as Map<String, dynamic>?) ?? response.data;
|
||||
final responseMap = response.data as Map<String, dynamic>;
|
||||
final data = (responseMap['data'] as Map<String, dynamic>?) ?? responseMap;
|
||||
|
||||
final needUpdate = data['needUpdate'] as bool? ?? true;
|
||||
final needUpdate = data['needUpdate'] as bool? ?? false;
|
||||
if (!needUpdate) {
|
||||
debugPrint('[VersionChecker] 无需更新');
|
||||
return null;
|
||||
}
|
||||
return VersionInfo.fromJson(data);
|
||||
|
||||
// Fix relative downloadUrl → prepend apiBaseUrl for backward compatibility
|
||||
final rawUrl = data['downloadUrl'] as String? ?? '';
|
||||
final fixedData = (rawUrl.isNotEmpty && !rawUrl.startsWith('http'))
|
||||
? (Map<String, dynamic>.from(data)..['downloadUrl'] = '$apiBaseUrl$rawUrl')
|
||||
: data;
|
||||
|
||||
return VersionInfo.fromJson(fixedData);
|
||||
}
|
||||
return null;
|
||||
} catch (e) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'dart:io' show Platform;
|
||||
import 'models/version_info.dart';
|
||||
|
||||
/// 版本检测器
|
||||
|
|
@ -27,11 +28,12 @@ class VersionChecker {
|
|||
final currentInfo = await getCurrentVersion();
|
||||
debugPrint('[VersionChecker] 当前版本: ${currentInfo.version}, buildNumber: ${currentInfo.buildNumber}');
|
||||
|
||||
final platform = Platform.isIOS ? 'IOS' : 'ANDROID';
|
||||
final response = await _dio.get(
|
||||
'/api/v1/app/version/check',
|
||||
queryParameters: {
|
||||
'app_type': 'GENEX_MOBILE',
|
||||
'platform': 'android',
|
||||
'platform': platform,
|
||||
'current_version': currentInfo.version,
|
||||
'current_version_code': currentInfo.buildNumber,
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue