1- import '../models/app_info_model.dart' ;
21import '../models/provider_model.dart' ;
2+ import '../models/app_info_model.dart' ;
33
44/// 应用远程数据源接口
55abstract class AppRemoteDataSource {
66 /// 获取应用信息
7- Future <AppInfoModel > getAppInfo ();
7+ Future <AppInfoModel > getAppInfo ({ String ? directory} );
88
99 /// 初始化应用
10- Future <bool > initializeApp ();
10+ Future <bool > initializeApp ({ String ? directory} );
1111
1212 /// 获取提供商信息
13- Future <ProvidersResponseModel > getProviders ();
13+ Future <ProvidersResponseModel > getProviders ({String ? directory});
14+
15+ /// 获取配置信息
16+ Future <Map <String , dynamic >> getConfig ({String ? directory});
1417}
1518
1619/// 应用远程数据源实现
@@ -20,21 +23,45 @@ class AppRemoteDataSourceImpl implements AppRemoteDataSource {
2023 AppRemoteDataSourceImpl ({required this .dio});
2124
2225 @override
23- Future <AppInfoModel > getAppInfo () async {
24- final response = await dio.get ('/app' );
25- return AppInfoModel .fromJson (response.data);
26+ Future <AppInfoModel > getAppInfo ({String ? directory}) async {
27+ try {
28+ final queryParams = directory != null ? {'directory' : directory} : < String , dynamic > {};
29+ final response = await dio.get ('/app/info' , queryParameters: queryParams);
30+ return AppInfoModel .fromJson (response.data);
31+ } catch (e) {
32+ print ('获取应用信息时出错: $e ' );
33+ // 返回默认的应用信息
34+ return AppInfoModel (
35+ hostname: 'localhost' ,
36+ git: false ,
37+ path: AppPathModel (
38+ config: '/config' ,
39+ data: '/data' ,
40+ root: '/' ,
41+ cwd: '/app' ,
42+ state: '/state' ,
43+ ),
44+ );
45+ }
2646 }
2747
2848 @override
29- Future <bool > initializeApp () async {
30- final response = await dio.post ('/app/init' );
31- return response.data as bool ;
49+ Future <bool > initializeApp ({String ? directory}) async {
50+ try {
51+ final queryParams = directory != null ? {'directory' : directory} : < String , dynamic > {};
52+ final response = await dio.post ('/app/init' , queryParameters: queryParams);
53+ return response.data['success' ] ?? true ;
54+ } catch (e) {
55+ print ('初始化应用时出错: $e ' );
56+ return false ;
57+ }
3258 }
3359
3460 @override
35- Future <ProvidersResponseModel > getProviders () async {
61+ Future <ProvidersResponseModel > getProviders ({ String ? directory} ) async {
3662 try {
37- final response = await dio.get ('/config/providers' );
63+ final queryParams = directory != null ? {'directory' : directory} : < String , dynamic > {};
64+ final response = await dio.get ('/provider' , queryParameters: queryParams);
3865 print ('Providers API 响应: ${response .data }' );
3966 return ProvidersResponseModel .fromJson (response.data);
4067 } catch (e) {
@@ -65,4 +92,11 @@ class AppRemoteDataSourceImpl implements AppRemoteDataSource {
6592 );
6693 }
6794 }
95+
96+ @override
97+ Future <Map <String , dynamic >> getConfig ({String ? directory}) async {
98+ final queryParams = directory != null ? {'directory' : directory} : < String , dynamic > {};
99+ final response = await dio.get ('/config' , queryParameters: queryParams);
100+ return response.data as Map <String , dynamic >;
101+ }
68102}
0 commit comments