Update: 2026-06-12 20:40:40
This commit is contained in:
@@ -11,6 +11,7 @@ import 'package:siro_driver/constant/info.dart';
|
||||
import 'package:siro_driver/constant/style.dart';
|
||||
import 'package:siro_driver/constant/table_names.dart';
|
||||
import 'package:siro_driver/main.dart';
|
||||
import 'package:siro_driver/print.dart';
|
||||
import 'package:siro_driver/views/widgets/elevated_btn.dart';
|
||||
|
||||
import '../../constant/box_name.dart';
|
||||
@@ -487,8 +488,10 @@ class ScanDocumentsByApi extends GetxController {
|
||||
isLoading = true;
|
||||
update();
|
||||
|
||||
final String token = box.read(BoxName.jwt)?.toString().split(AppInformation.addd)[0] ?? '';
|
||||
final String fingerPrint = box.read(BoxName.deviceFingerprint)?.toString() ?? '';
|
||||
final String token =
|
||||
box.read(BoxName.jwt)?.toString().split(AppInformation.addd)[0] ?? '';
|
||||
final String fingerPrint =
|
||||
box.read(BoxName.deviceFingerprint)?.toString() ?? '';
|
||||
final String driverID = box.read(BoxName.driverID).toString();
|
||||
final String link = AppLink.uploadImagePortrate;
|
||||
|
||||
@@ -500,11 +503,13 @@ class ScanDocumentsByApi extends GetxController {
|
||||
attempt++;
|
||||
final client = http.Client();
|
||||
try {
|
||||
Log.print('[UPLOAD_LOGGER] 🚀 [uploadImagePortrate] Attempt $attempt/$maxRetries started. Link: $link, Image Size: ${imagePortrait.length} bytes');
|
||||
|
||||
Log.print(
|
||||
'[UPLOAD_LOGGER] 🚀 [uploadImagePortrate] Attempt $attempt/$maxRetries started. Link: $link, Image Size: ${imagePortrait.length} bytes');
|
||||
|
||||
var request = http.MultipartRequest('POST', Uri.parse(link));
|
||||
request.files.add(
|
||||
http.MultipartFile.fromBytes('image', imagePortrait, filename: '$driverID.jpg'),
|
||||
http.MultipartFile.fromBytes('image', imagePortrait,
|
||||
filename: '$driverID.jpg'),
|
||||
);
|
||||
|
||||
request.headers.addAll({
|
||||
@@ -514,28 +519,35 @@ class ScanDocumentsByApi extends GetxController {
|
||||
request.fields['driverID'] = driverID;
|
||||
|
||||
final startTime = DateTime.now();
|
||||
var streamedResponse = await client.send(request).timeout(const Duration(seconds: 120));
|
||||
var streamedResponse =
|
||||
await client.send(request).timeout(const Duration(seconds: 120));
|
||||
var res = await http.Response.fromStream(streamedResponse);
|
||||
final duration = DateTime.now().difference(startTime);
|
||||
|
||||
Log.print('[UPLOAD_LOGGER] 📥 [uploadImagePortrate] Attempt $attempt response received in ${duration.inSeconds}s. Status Code: ${res.statusCode}');
|
||||
Log.print('[UPLOAD_LOGGER] 📥 [uploadImagePortrate] Response Body: ${res.body}');
|
||||
Log.print(
|
||||
'[UPLOAD_LOGGER] 📥 [uploadImagePortrate] Attempt $attempt response received in ${duration.inSeconds}s. Status Code: ${res.statusCode}');
|
||||
Log.print(
|
||||
'[UPLOAD_LOGGER] 📥 [uploadImagePortrate] Response Body: ${res.body}');
|
||||
|
||||
if (res.statusCode == 200) {
|
||||
responseString = res.body;
|
||||
break; // Success
|
||||
} else {
|
||||
throw Exception('Failed to upload portrait: ${res.statusCode} - ${res.body}');
|
||||
throw Exception(
|
||||
'Failed to upload portrait: ${res.statusCode} - ${res.body}');
|
||||
}
|
||||
} catch (e, st) {
|
||||
Log.print('[UPLOAD_LOGGER] ⚠️ [uploadImagePortrate] Attempt $attempt failed. Error: $e', stackTrace: st);
|
||||
Log.print(
|
||||
'[UPLOAD_LOGGER] ⚠️ [uploadImagePortrate] Attempt $attempt failed. Error: $e',
|
||||
stackTrace: st);
|
||||
if (attempt >= maxRetries) {
|
||||
isLoading = false;
|
||||
update();
|
||||
rethrow;
|
||||
}
|
||||
final waitSeconds = attempt * 2;
|
||||
Log.print('[UPLOAD_LOGGER] ⏳ Waiting $waitSeconds seconds before retrying...');
|
||||
Log.print(
|
||||
'[UPLOAD_LOGGER] ⏳ Waiting $waitSeconds seconds before retrying...');
|
||||
await Future.delayed(Duration(seconds: waitSeconds));
|
||||
} finally {
|
||||
client.close();
|
||||
|
||||
@@ -38,23 +38,36 @@ class AppInitializer {
|
||||
List<Map<String, dynamic>> links = [];
|
||||
|
||||
Future<void> initializeApp() async {
|
||||
if (box.read(BoxName.jwt) == null) {
|
||||
String? secureJwt = await storage.read(key: BoxName.jwt);
|
||||
if (secureJwt != null) {
|
||||
box.write(BoxName.jwt, secureJwt);
|
||||
}
|
||||
}
|
||||
|
||||
if (box.read(BoxName.jwt) == null) {
|
||||
await LoginDriverController().getJWT();
|
||||
} else {
|
||||
String token = r(box.read(BoxName.jwt)).toString().split(AppInformation.addd)[0];
|
||||
String token =
|
||||
r(box.read(BoxName.jwt)).toString().split(AppInformation.addd)[0];
|
||||
bool isTokenValid = false;
|
||||
try {
|
||||
final parts = token.split('.');
|
||||
if (parts.length == 3) {
|
||||
String payload = parts[1];
|
||||
switch (payload.length % 4) {
|
||||
case 2: payload += '=='; break;
|
||||
case 3: payload += '='; break;
|
||||
case 2:
|
||||
payload += '==';
|
||||
break;
|
||||
case 3:
|
||||
payload += '=';
|
||||
break;
|
||||
}
|
||||
final decoded = jsonDecode(utf8.decode(base64Url.decode(payload)));
|
||||
final exp = decoded['exp'];
|
||||
if (exp != null) {
|
||||
isTokenValid = DateTime.now().millisecondsSinceEpoch < (exp * 1000 - 30000);
|
||||
isTokenValid =
|
||||
DateTime.now().millisecondsSinceEpoch < (exp * 1000 - 30000);
|
||||
}
|
||||
}
|
||||
} catch (_) {}
|
||||
|
||||
Reference in New Issue
Block a user