Update: 2026-06-25 02:55:24

This commit is contained in:
Hamza-Ayed
2026-06-25 02:55:24 +03:00
parent 98a8a2ae3d
commit 85e85fe4d3
11 changed files with 62 additions and 86 deletions

View File

@@ -97,6 +97,16 @@ class CRUD {
return box.read(BoxName.deviceFingerprint)?.toString() ?? '';
}
String _getJwt() {
try {
final jwt = box.read(BoxName.jwt);
if (jwt == null || jwt.toString().isEmpty) return '';
return r(jwt).toString().split(Env.addd)[0];
} catch (_) {
return '';
}
}
// ═══════════════════════════════════════════════════════════════
// _makeRequest — دالة مركزية لكل الطلبات
// ───────────────────────────────────────────────────────────────
@@ -207,14 +217,14 @@ class CRUD {
required String link,
Map<String, dynamic>? payload,
}) async {
String token = r(box.read(BoxName.jwt)).toString().split(Env.addd)[0];
String token = _getJwt();
// فحص صلاحية التوكن قبل الإرسال — تجنب طلب مضمون الرفض
if (!_isJwtValid(token) && !_isRefreshingJWT) {
_isRefreshingJWT = true;
try {
await Get.put(LoginDriverController()).getJWT();
token = r(box.read(BoxName.jwt)).toString().split(Env.addd)[0];
token = _getJwt();
} finally {
_isRefreshingJWT = false;
}
@@ -239,12 +249,12 @@ class CRUD {
}) async {
try {
// فحص صلاحية التوكن قبل الإرسال
String token = r(box.read(BoxName.jwt)).toString().split(Env.addd)[0];
String token = _getJwt();
if (!_isJwtValid(token) && !_isRefreshingJWT) {
_isRefreshingJWT = true;
try {
await Get.put(LoginDriverController()).getJWT();
token = r(box.read(BoxName.jwt)).toString().split(Env.addd)[0];
token = _getJwt();
} finally {
_isRefreshingJWT = false;
}
@@ -557,11 +567,11 @@ class CRUD {
// ── sendEmail — إصلاح: استخدام r() بدل X.r() القديم ─────────
Future<void> sendEmail(String link, Map<String, String>? payload) async {
// r() هي نفس دالة فك التشفير الثلاثي المختصرة
String token = r(box.read(BoxName.jwt)).toString().split(Env.addd)[0];
String token = _getJwt();
if (!_isJwtValid(token)) {
await LoginDriverController().getJWT();
token = r(box.read(BoxName.jwt)).toString().split(Env.addd)[0];
token = _getJwt();
}
final headers = {

View File

@@ -479,9 +479,10 @@ class AI extends GetxController {
bool isLoadingVehicleFrontSy = false;
bool isLoadingVehicleBackSy = false;
Future<void> sendToAI(String type, {required File imageFile}) async {
final _jwt = box.read(BoxName.jwt);
final String _token = _jwt != null ? r(_jwt).split(AppInformation.addd)[0] : '';
final headers = {
'Authorization':
'Bearer ${r(box.read(BoxName.jwt)).split(AppInformation.addd)[0]}',
'Authorization': 'Bearer $_token',
'X-HMAC-Auth': '${box.read(BoxName.hmac)}',
};
final driverID = box.read(BoxName.driverID) ?? 'eddfdfdgfd';

View File

@@ -311,7 +311,8 @@ class ImageController extends GetxController {
required String filename,
required String methodLabel,
}) async {
final String token = r(box.read(BoxName.jwt)).split(AppInformation.addd)[0];
final jwt = box.read(BoxName.jwt);
final String token = jwt != null ? r(jwt).split(AppInformation.addd)[0] : '';
final String fingerPrint = box.read(BoxName.deviceFingerprint)?.toString() ?? '';
final int fileSizeBytes = await file.length();