fix upload: parse nested message.url, backup retries=1, connect.php auth
This commit is contained in:
@@ -5,10 +5,7 @@
|
|||||||
// يخزّنها في مجلدات حسب الدولة: auth/uploads/{country}/
|
// يخزّنها في مجلدات حسب الدولة: auth/uploads/{country}/
|
||||||
// ============================================================
|
// ============================================================
|
||||||
|
|
||||||
// ملاحظة: نستخدم bootstrap.php مباشرة (بدون connect.php) لأن JWT
|
require_once __DIR__ . '/../../connect.php';
|
||||||
// registration (token_type: registration) لا يملك صلاحية connect.php
|
|
||||||
require_once __DIR__ . '/../../core/bootstrap.php';
|
|
||||||
$con = Database::get('main');
|
|
||||||
|
|
||||||
uploadLog("🚀 [uploadImage.php] Document upload started.");
|
uploadLog("🚀 [uploadImage.php] Document upload started.");
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ class JwtService
|
|||||||
'loginFromGooglePassenger', 'loginUsingCredentialsWithoutGooglePassenger',
|
'loginFromGooglePassenger', 'loginUsingCredentialsWithoutGooglePassenger',
|
||||||
'register', 'sendOtpMessageDriver', 'getTokensPassenger',
|
'register', 'sendOtpMessageDriver', 'getTokensPassenger',
|
||||||
'send_otp', 'verify_otp', 'errorApp', 'register_driver',
|
'send_otp', 'verify_otp', 'errorApp', 'register_driver',
|
||||||
|
'uploadImage', 'register_driver_and_car',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function __construct(?Redis $redis = null)
|
public function __construct(?Redis $redis = null)
|
||||||
|
|||||||
@@ -359,11 +359,11 @@ class RegistrationController extends GetxController {
|
|||||||
String link, {
|
String link, {
|
||||||
String? backupLink,
|
String? backupLink,
|
||||||
}) async {
|
}) async {
|
||||||
const int maxRetries = 3;
|
|
||||||
|
|
||||||
final List<String> urlsToTry = [link, if (backupLink != null && backupLink.trim().isNotEmpty) backupLink];
|
final List<String> urlsToTry = [link, if (backupLink != null && backupLink.trim().isNotEmpty) backupLink];
|
||||||
|
|
||||||
for (final currentUrl in urlsToTry) {
|
for (int i = 0; i < urlsToTry.length; i++) {
|
||||||
|
final currentUrl = urlsToTry[i];
|
||||||
|
final maxRetries = (i == 0) ? 3 : 1; // 3 attempts for primary, 1 for backup
|
||||||
for (int attempt = 1; attempt <= maxRetries; attempt++) {
|
for (int attempt = 1; attempt <= maxRetries; attempt++) {
|
||||||
try {
|
try {
|
||||||
final uri = Uri.parse(currentUrl);
|
final uri = Uri.parse(currentUrl);
|
||||||
@@ -399,7 +399,15 @@ class RegistrationController extends GetxController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final body = jsonDecode(res.body);
|
final body = jsonDecode(res.body);
|
||||||
final String? url = body['url'] ??
|
String? url;
|
||||||
|
// بعض السيرفرات تعيد الرابط داخل message
|
||||||
|
if (body['message'] is Map) {
|
||||||
|
url = body['message']['url'] ??
|
||||||
|
body['message']['file_link'] ??
|
||||||
|
body['message']['image_url'];
|
||||||
|
}
|
||||||
|
// وإلا حاول من الجذر
|
||||||
|
url ??= body['url'] ??
|
||||||
body['file_link'] ??
|
body['file_link'] ??
|
||||||
body['image_url'] ??
|
body['image_url'] ??
|
||||||
(body['data'] is Map ? body['data']['url'] : null);
|
(body['data'] is Map ? body['data']['url'] : null);
|
||||||
|
|||||||
Reference in New Issue
Block a user