Skip to content

Commit 3c2c191

Browse files
committed
fix: pre-release
- Upgraded kotlin version - Fixed JVM - Upgraded DIO version for security issue
1 parent bcaee2b commit 3c2c191

16 files changed

Lines changed: 113 additions & 171 deletions

android/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ GeneratedPluginRegistrant.java
99
# Remember to never publicly share your keystore.
1010
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
1111
key.properties
12+
/build/.last_build_id

android/app/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ android {
3434
compileOptions {
3535
// Flag to enable support for the new language APIs
3636
coreLibraryDesugaringEnabled true
37-
// Sets Java compatibility to Java 8
38-
sourceCompatibility JavaVersion.VERSION_1_8
39-
targetCompatibility JavaVersion.VERSION_1_8
37+
// Sets Java compatibility to Java 11
38+
sourceCompatibility JavaVersion.VERSION_11
39+
targetCompatibility JavaVersion.VERSION_11
4040
}
4141

4242
kotlinOptions {
43-
jvmTarget = '1.8'
43+
jvmTarget = '11'
4444
}
4545

4646
sourceSets {

android/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pluginManagement {
1919
plugins {
2020
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
2121
id "com.android.application" version "7.1.3" apply false
22-
id "org.jetbrains.kotlin.android" version "1.7.10" apply false
22+
id "org.jetbrains.kotlin.android" version "1.9.0" apply false
2323
}
2424

2525
include ":app"

lib/network/albums.dart

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ Future<ApiResponse<List<AlbumModel>>> fetchAlbums(int albumID) async {
2727
);
2828

2929
if (response.statusCode == 200) {
30-
List<dynamic> jsonAlbums =
31-
tryParseJson(response.data)['result']['categories'];
30+
List<dynamic> jsonAlbums = tryParseJson(response.data)['result']['categories'];
3231
List<AlbumModel> albums = List<AlbumModel>.from(jsonAlbums.map(
3332
(album) {
34-
bool canUpload =
35-
appPreferences.getBool(Preferences.isAdminKey) ?? false;
33+
bool canUpload = appPreferences.getBool(Preferences.isAdminKey) ?? false;
3634
album['can_upload'] = canUpload;
3735
return AlbumModel.fromJson(album);
3836
},
@@ -47,8 +45,7 @@ Future<ApiResponse<List<AlbumModel>>> fetchAlbums(int albumID) async {
4745
}
4846
if (communityResult.hasData) {
4947
for (AlbumModel communityAlbum in communityResult.data) {
50-
int index =
51-
albums.indexWhere((album) => album.id == communityAlbum.id);
48+
int index = albums.indexWhere((album) => album.id == communityAlbum.id);
5249
if (index >= 0) {
5350
AlbumModel newAlbum = albums.elementAt(index);
5451
newAlbum.canUpload = true;
@@ -65,7 +62,7 @@ Future<ApiResponse<List<AlbumModel>>> fetchAlbums(int albumID) async {
6562
data: albums,
6663
);
6764
}
68-
} on DioError catch (e) {
65+
} on DioException catch (e) {
6966
debugPrint(e.message);
7067
} catch (e) {
7168
debugPrint("$e");
@@ -86,8 +83,7 @@ Future<ApiResponse<List<AlbumModel>>> fetchCommunityAlbums(int albumID) async {
8683
);
8784

8885
if (response.statusCode == 200) {
89-
List<dynamic> jsonAlbums =
90-
json.decode(response.data)['result']['categories'];
86+
List<dynamic> jsonAlbums = json.decode(response.data)['result']['categories'];
9187
List<AlbumModel> albums = List<AlbumModel>.from(jsonAlbums.map(
9288
(album) => AlbumModel.fromJson(album),
9389
));
@@ -96,7 +92,7 @@ Future<ApiResponse<List<AlbumModel>>> fetchCommunityAlbums(int albumID) async {
9692
data: albums,
9793
);
9894
}
99-
} on DioError catch (e) {
95+
} on DioException catch (e) {
10096
debugPrint(e.message);
10197
} catch (e) {
10298
debugPrint("$e");
@@ -129,7 +125,7 @@ Future<ApiResponse<List<AlbumModel>>> getAlbumTree([int? startId]) async {
129125
data: albums,
130126
);
131127
}
132-
} on DioError catch (e) {
128+
} on DioException catch (e) {
133129
debugPrint(e.message);
134130
} catch (e) {
135131
debugPrint("$e");
@@ -164,7 +160,7 @@ Future<ApiResponse<bool>> addAlbum({
164160
}
165161
return ApiResponse(data: true);
166162
}
167-
} on DioError catch (e) {
163+
} on DioException catch (e) {
168164
debugPrint(e.message);
169165
} catch (e) {
170166
debugPrint("$e");
@@ -197,7 +193,7 @@ Future<ApiResponse<bool>> moveAlbum(int catId, int parentCatId) async {
197193
}
198194
return ApiResponse(data: true);
199195
}
200-
} on DioError catch (e) {
196+
} on DioException catch (e) {
201197
debugPrint("${e.message}");
202198
} catch (e) {
203199
debugPrint("$e");
@@ -239,7 +235,7 @@ Future<ApiResponse<bool>> editAlbum({
239235
print(data);
240236
return ApiResponse(data: true);
241237
}
242-
} on DioError catch (e) {
238+
} on DioException catch (e) {
243239
debugPrint("${e.message}");
244240
} catch (e) {
245241
debugPrint("$e");
@@ -276,7 +272,7 @@ Future<ApiResponse<bool>> deleteAlbum(
276272
}
277273
return ApiResponse(data: true);
278274
}
279-
} on DioError catch (e) {
275+
} on DioException catch (e) {
280276
debugPrint("${e.message}");
281277
} catch (e) {
282278
debugPrint("$e");

lib/network/api_client.dart

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import 'dart:convert';
22
import 'dart:io';
33

44
import 'package:cookie_jar/cookie_jar.dart';
5-
import 'package:dio/adapter.dart';
65
import 'package:dio/dio.dart';
6+
import 'package:dio/io.dart';
77
import 'package:dio_cookie_manager/dio_cookie_manager.dart';
88
import 'package:flutter/foundation.dart';
99
import 'package:piwigo_ng/services/preferences_service.dart';
@@ -17,13 +17,9 @@ class ApiClient {
1717
..interceptors.add(CookieManager(cookieJar))
1818
..httpClientAdapter = sslHttpClientAdapter;
1919

20-
static HttpClientAdapter get sslHttpClientAdapter {
21-
return DefaultHttpClientAdapter()
22-
..onHttpClientCreate = (HttpClient client) {
23-
client.badCertificateCallback = piwigoSSLBypass;
24-
return client;
25-
};
26-
}
20+
static HttpClientAdapter get sslHttpClientAdapter => IOHttpClientAdapter(
21+
createHttpClient: () => HttpClient()..badCertificateCallback = piwigoSSLBypass,
22+
);
2723

2824
static bool piwigoSSLBypass(X509Certificate cert, String host, int port) {
2925
if (Preferences.getEnableSSL) {
@@ -138,8 +134,7 @@ class ApiClient {
138134
class SSLHttpOverrides extends HttpOverrides {
139135
@override
140136
HttpClient createHttpClient(SecurityContext? context) {
141-
return super.createHttpClient(context)
142-
..badCertificateCallback = ApiClient.piwigoSSLBypass;
137+
return super.createHttpClient(context)..badCertificateCallback = ApiClient.piwigoSSLBypass;
143138
}
144139
}
145140

lib/network/api_interceptor.dart

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ class ApiInterceptor extends Interceptor {
2121
if (prefs.getBool(Preferences.enableBasicAuthKey) ?? false) {
2222
String? username = prefs.getString(Preferences.basicUsernameKey) ?? '';
2323
String? password = prefs.getString(Preferences.basicPasswordKey) ?? '';
24-
String basicAuth =
25-
"Basic ${base64.encode(utf8.encode('$username:$password'))}";
24+
String basicAuth = "Basic ${base64.encode(utf8.encode('$username:$password'))}";
2625
options.headers['authorization'] = basicAuth;
2726
}
2827
return super.onRequest(options, handler);
@@ -33,18 +32,16 @@ class ApiInterceptor extends Interceptor {
3332
Response response,
3433
ResponseInterceptorHandler handler,
3534
) async {
36-
debugPrint(
37-
"[${response.statusCode}] ${response.requestOptions.queryParameters['method']}");
35+
debugPrint("[${response.statusCode}] ${response.requestOptions.queryParameters['method']}");
3836
return super.onResponse(response, handler);
3937
}
4038

4139
@override
4240
void onError(
43-
DioError err,
41+
DioException err,
4442
ErrorInterceptorHandler handler,
4543
) async {
46-
debugPrint(
47-
"[${err.response?.statusCode}] ${err.requestOptions.queryParameters['method']}");
44+
debugPrint("[${err.response?.statusCode}] ${err.requestOptions.queryParameters['method']}");
4845
debugPrint('${err.error}\n${err.response?.data}\n${err.stackTrace}');
4946

5047
switch (err.response?.statusCode) {
@@ -61,8 +58,7 @@ class ApiInterceptor extends Interceptor {
6158
if (err.error is HandshakeException) {
6259
HandshakeException handshakeError = err.error as HandshakeException;
6360
String? message = handshakeError.osError?.message;
64-
if (message != null &&
65-
message.contains('CERTIFICATE_VERIFY_FAILED')) {
61+
if (message != null && message.contains('CERTIFICATE_VERIFY_FAILED')) {
6662
App.scaffoldMessengerKey.currentState?.showSnackBar(
6763
errorSnackBar(
6864
message: appStrings.loginCertFailed_title,

lib/network/authentication.dart

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Future<ApiResponse<String>> pingAPI() async {
2323
if (data['stat'] == 'ok') {
2424
return ApiResponse<String>(data: data['result']);
2525
}
26-
} on DioError catch (e) {
26+
} on DioException catch (e) {
2727
debugPrint(e.message);
2828
} catch (e) {
2929
debugPrint('Error $e');
@@ -88,15 +88,14 @@ Future<ApiResponse<bool>> loginUser(
8888
}
8989
ApiResponse<StatusModel> status = await sessionStatus();
9090
if (status.hasData) {
91-
Preferences.saveId(status.data!,
92-
username: username, password: password);
91+
Preferences.saveId(status.data!, username: username, password: password);
9392
}
9493
askMediaPermission();
9594
return ApiResponse<bool>(
9695
data: true,
9796
);
9897
}
99-
} on DioError catch (e) {
98+
} on DioException catch (e) {
10099
debugPrint(e.message);
101100
} catch (e) {
102101
debugPrint('Error $e');
@@ -108,10 +107,7 @@ Future<ApiResponse<bool>> loginUser(
108107
}
109108

110109
Future<ApiResponse<StatusModel>> sessionStatus() async {
111-
Map<String, String> queries = {
112-
'format': 'json',
113-
'method': 'pwg.session.getStatus'
114-
};
110+
Map<String, String> queries = {'format': 'json', 'method': 'pwg.session.getStatus'};
115111

116112
try {
117113
Response response = await ApiClient.get(queryParameters: queries);
@@ -125,7 +121,7 @@ Future<ApiResponse<StatusModel>> sessionStatus() async {
125121
data: StatusModel.fromJson(data['result']),
126122
);
127123
}
128-
} on DioError catch (e) {
124+
} on DioException catch (e) {
129125
debugPrint(e.message);
130126
} catch (e) {
131127
debugPrint('Session Status Error: $e');
@@ -139,18 +135,15 @@ Future<ApiResponse<StatusModel>> sessionStatus() async {
139135
}
140136

141137
Future<String?> communityStatus() async {
142-
Map<String, String> queries = {
143-
'format': 'json',
144-
'method': 'community.session.getStatus'
145-
};
138+
Map<String, String> queries = {'format': 'json', 'method': 'community.session.getStatus'};
146139

147140
try {
148141
Response response = await ApiClient.get(queryParameters: queries);
149142
var data = json.decode(response.data);
150143
if (data['stat'] == 'ok') {
151144
return data['result']['real_user_status'];
152145
}
153-
} on DioError catch (e) {
146+
} on DioException catch (e) {
154147
debugPrint(e.message);
155148
} catch (e) {
156149
debugPrint('Error $e');
@@ -169,7 +162,7 @@ Future<ApiResponse<InfoModel>> getInfo() async {
169162
data: InfoModel.fromJson(data['result']),
170163
);
171164
}
172-
} on DioError catch (e) {
165+
} on DioException catch (e) {
173166
debugPrint(e.message);
174167
} catch (e) {
175168
debugPrint('Error $e');
@@ -180,18 +173,14 @@ Future<ApiResponse<InfoModel>> getInfo() async {
180173
}
181174

182175
Future<ApiResponse<List<String>>> getMethods() async {
183-
Map<String, String> queries = {
184-
'format': 'json',
185-
'method': 'reflection.getMethodList'
186-
};
176+
Map<String, String> queries = {'format': 'json', 'method': 'reflection.getMethodList'};
187177

188178
try {
189179
Response response = await ApiClient.get(queryParameters: queries);
190180
Map<String, dynamic> data = json.decode(response.data);
191-
final List<String> methods =
192-
data['result']['methods'].map<String>((e) => e.toString()).toList();
181+
final List<String> methods = data['result']['methods'].map<String>((e) => e.toString()).toList();
193182
return ApiResponse<List<String>>(data: methods);
194-
} on DioError catch (e) {
183+
} on DioException catch (e) {
195184
debugPrint(e.message);
196185
} catch (e) {
197186
debugPrint('Error $e');

lib/network/groups.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Future<List<GroupModel>?> getAllGroups({
5757
}
5858

5959
return groupsResponse;
60-
} on DioError catch (e) {
60+
} on DioException catch (e) {
6161
debugPrint('Fetch all groups: ${e.message}');
6262
} on Error catch (e) {
6363
debugPrint('Fetch all groups: ${e.stackTrace}');
@@ -89,7 +89,7 @@ Future<ApiResponse<List<GroupModel>?>> getGroups([int page = 0]) async {
8989
data: groups,
9090
);
9191
}
92-
} on DioError catch (e) {
92+
} on DioException catch (e) {
9393
debugPrint('Fetch groups: ${e.message}');
9494
} on Error catch (e) {
9595
debugPrint('Fetch groups: ${e.stackTrace}');

0 commit comments

Comments
 (0)