feat: استيراد كود سيرو إلى تريبز (سيرو @ecfe7568) — بلا تعديل
قرار المالك 2026-07-27: باك إند سيرو PHP هو المعتمد، وتطبيقاته المجرّبة ميدانياً تحل محل إعادة البناء المؤرشفة. سيرو نفسه لم يُمسّ. الخريطة: backend · payment_server · loction_server · ride_server · passenger_server · docker · dashboard · stress_test → الجذر siro_rider → apps/rider siro_driver → apps/driver siro_admin → dashboards/admin siro_service → dashboards/service android_bot → apps/android_bot socialBot → apps/socialBot نُسخ المتعقَّب في git سيرو فقط عبر `git archive` (3,198 ملفاً / ~169 م.ب) لا `cp -r` — فاستُثنيت مخلفات البناء تلقائياً. بلا أي تعديل محتوى عمداً: كل ما يلي يصير فرقاً مقروءاً مقابل المصدر. لم يُستورد وسببه: siromove.com (الموقع التسويقي يبقى marketing/ في تريبز، سيرو فيه 8 ملفات) · docs و planning (تريبز له docs/ الخاص) · deploy.sh (ليس نشراً على سيرفر بل `git add . && git push origin --all` — فخّ في مستودع آخر) · transit_dashboard (بانتظار قرار مصير backend-transit و dashboards/transit-web). ⚠️ لا يبني بعد — ثلاثة نواقص متوقعة ومقصودة: 1. `.env` و `lib/env/env.g.dart` غير متعقَّبين في سيرو (أسرار لكل مستأجر): كل تطبيق فلاتر يحتاج .env خاصاً ثم توليد env.g.dart بـ build_runner. 2. إعدادات Firebase (9 ملفات google-services.json و GoogleService-Info.plist) يستبعدها .gitignore تريبز — ولكل مستأجر مشروع Firebase خاص أصلاً. 3. apps/driver في سيرو يشير إلى `../../Intaleq/packages/get` خارج المستودع → يجب ضمّ الحزم داخله أسوة بـ apps/rider. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
9909d9b4c1
commit
4d8414c96b
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
// ============================================================
|
||||
// uploadImagePortrate.php
|
||||
// رفع صورة الكابتن بأمان
|
||||
// ============================================================
|
||||
|
||||
require_once __DIR__ . '/connect.php'; // يفترض أنه يستدعي core/bootstrap.php
|
||||
|
||||
uploadLog("🚀 [uploadImagePortrate.php] Profile image upload script execution started.");
|
||||
|
||||
try {
|
||||
// Check if $_FILES has errors
|
||||
if (isset($_FILES['image'])) {
|
||||
uploadLog('$_FILES[\'image\'] metadata', 'INFO', [
|
||||
'name' => $_FILES['image']['name'] ?? 'unknown',
|
||||
'type' => $_FILES['image']['type'] ?? 'unknown',
|
||||
'size' => $_FILES['image']['size'] ?? 0,
|
||||
'upload_error_code' => $_FILES['image']['error'] ?? UPLOAD_ERR_OK
|
||||
]);
|
||||
} else {
|
||||
uploadLog("No 'image' file was sent in the request.", 'WARNING');
|
||||
}
|
||||
|
||||
// 1. Rate Limiting للرفع
|
||||
$limiter = new RateLimiter($redis);
|
||||
$limiter->enforce(RateLimiter::identifier($user_id ?? null), 'upload');
|
||||
|
||||
// Force driverID from JWT — never trust user-supplied driverID
|
||||
$driverID = $user_id;
|
||||
uploadLog("📥 Using JWT driverID: $driverID");
|
||||
|
||||
if (empty($driverID)) {
|
||||
uploadLog("❌ Driver ID from JWT is missing.", 'ERROR');
|
||||
jsonError('Authentication required.', 400);
|
||||
}
|
||||
|
||||
// 2. استخدام دالة الرفع الآمنة (MIME check, random name, 5MB limit)
|
||||
$target_dir = __DIR__ . "/portrate_captain_image/";
|
||||
$uploadResult = uploadImageSecure('image', $target_dir, $driverID);
|
||||
|
||||
if (!$uploadResult['success']) {
|
||||
uploadLog("❌ Image upload failed", 'ERROR', ['driverID' => $driverID, 'error' => $uploadResult['error']]);
|
||||
securityLog("❌ Image upload failed", ['driverID' => $driverID, 'error' => $uploadResult['error']]);
|
||||
jsonError($uploadResult['error'], 400);
|
||||
}
|
||||
|
||||
$new_filename = $uploadResult['filename'];
|
||||
uploadLog("✅ File moved successfully to: " . $uploadResult['path']);
|
||||
|
||||
// 3. تحديث قاعدة البيانات ديناميكياً
|
||||
// Derive base URL dynamically from the actual request
|
||||
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
|
||||
$host = getenv('APP_DOMAIN') ?: ($_SERVER['HTTP_HOST'] ?? 'api.siromove.com');
|
||||
$scriptDir = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/');
|
||||
$linkImage = "$protocol://$host$scriptDir/portrate_captain_image/" . $new_filename;
|
||||
|
||||
// تأكد من أن الاتصال قادم من connect.php أو اجلبه
|
||||
$con = Database::get('main');
|
||||
|
||||
// التحقق من وجود السائق في جدول الصور الشخصية
|
||||
$stmt = $con->prepare("SELECT COUNT(*) FROM imageProfileCaptain WHERE driverID = ?");
|
||||
$stmt->execute([$driverID]);
|
||||
$count = $stmt->fetchColumn();
|
||||
|
||||
if ($count > 0) {
|
||||
// تحديث
|
||||
$updateSQL = "UPDATE imageProfileCaptain SET image_name = ?, link = ? WHERE driverID = ?";
|
||||
$updateStmt = $con->prepare($updateSQL);
|
||||
$success = $updateStmt->execute([$new_filename, $linkImage, $driverID]);
|
||||
} else {
|
||||
// إدخال جديد
|
||||
$insertSQL = "INSERT INTO imageProfileCaptain (driverID, image_name, link) VALUES (?, ?, ?)";
|
||||
$insertStmt = $con->prepare($insertSQL);
|
||||
$success = $insertStmt->execute([$driverID, $new_filename, $linkImage]);
|
||||
}
|
||||
|
||||
if ($success) {
|
||||
uploadLog("✅ Record updated for driverID: $driverID, Link: $linkImage");
|
||||
jsonSuccess(['file_link' => $linkImage], 'Record updated successfully.');
|
||||
} else {
|
||||
uploadLog("❌ Failed to update DB record for driverID: $driverID", 'ERROR');
|
||||
jsonError('Failed to update record.', 500);
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
securityLog("💥 PDO ERROR in uploadImage", ['error' => $e->getMessage()]);
|
||||
jsonError('Database error.', 500);
|
||||
} catch (Exception $e) {
|
||||
securityLog("💥 GENERAL ERROR in uploadImage", ['error' => $e->getMessage()]);
|
||||
jsonError('Server error.', 500);
|
||||
}
|
||||
Reference in New Issue
Block a user