Update Saqel Platform: 2026-08-28 18:08:03
This commit is contained in:
@@ -1,4 +1,17 @@
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
set_error_handler(function($errno, $errstr, $errfile, $errline) {
|
||||
echo "[PHP ERROR] $errstr in $errfile on line $errline
|
||||
";
|
||||
});
|
||||
|
||||
set_exception_handler(function($e) {
|
||||
echo "[PHP EXCEPTION] " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "
|
||||
";
|
||||
});
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
@@ -7,7 +20,7 @@ use App\Core\Env;
|
||||
|
||||
$taskId = $argv[1] ?? '';
|
||||
if (empty($taskId)) {
|
||||
die("Task ID required\n");
|
||||
echo "Task ID required\n"; return;
|
||||
}
|
||||
|
||||
$processingDir = __DIR__ . '/../storage/curriculum/processing';
|
||||
@@ -15,7 +28,7 @@ $stateFile = $processingDir . '/' . $taskId . '.json';
|
||||
$pdfFile = $processingDir . '/' . $taskId . '.pdf';
|
||||
|
||||
if (!file_exists($stateFile) || !file_exists($pdfFile)) {
|
||||
die("Files missing\n");
|
||||
echo "Files missing\n"; return;
|
||||
}
|
||||
|
||||
function updateState($stateFile, $status, $progress, $message, $extra = []) {
|
||||
@@ -27,6 +40,11 @@ function updateState($stateFile, $status, $progress, $message, $extra = []) {
|
||||
$state = array_merge($state, $extra);
|
||||
}
|
||||
file_put_contents($stateFile, json_encode($state, JSON_UNESCAPED_UNICODE));
|
||||
|
||||
// Log to file too
|
||||
$logFile = str_replace('.json', '.log', $stateFile);
|
||||
$timestamp = date('Y-m-d H:i:s');
|
||||
file_put_contents($logFile, "[$timestamp] [$status] [$progress%] $message\n", FILE_APPEND);
|
||||
}
|
||||
|
||||
$state = json_decode(file_get_contents($stateFile), true);
|
||||
@@ -38,7 +56,7 @@ $apiKeys = array_values(array_filter(array_map('trim', explode(',', $rawKeys))))
|
||||
|
||||
if (empty($apiKeys)) {
|
||||
updateState($stateFile, 'error', 0, '⚠️ لم يتم العثور على مفتاح الذكاء الاصطناعي (GEMINI_API_KEY) في ملف .env.');
|
||||
exit;
|
||||
return;
|
||||
}
|
||||
|
||||
// Round Robin Logic
|
||||
@@ -53,7 +71,7 @@ updateState($stateFile, 'uploading_to_ai', 15, "تم تفعيل Round Robin. ج
|
||||
|
||||
if (empty($geminiKey)) {
|
||||
updateState($stateFile, 'error', 0, '⚠️ لم يتم العثور على مفتاح الذكاء الاصطناعي (GEMINI_API_KEY) في ملف .env. النظام يحتاج إلى الـ AI لقراءة وتفريغ الكتب (بما فيها الكتب المصورة والرياضيات) بشكل حقيقي.');
|
||||
exit;
|
||||
return;
|
||||
}
|
||||
|
||||
updateState($stateFile, 'uploading_to_ai', 20, 'جاري رفع الكتاب إلى محرك الذكاء الاصطناعي (Gemini Vision) لقراءته بالكامل...');
|
||||
@@ -77,7 +95,7 @@ curl_close($ch);
|
||||
|
||||
if ($uploadCode !== 200) {
|
||||
updateState($stateFile, 'error', 0, 'فشل رفع الملف إلى الذكاء الاصطناعي. كود الخطأ: ' . $uploadCode . ' التفاصيل: ' . $uploadRes);
|
||||
exit;
|
||||
return;
|
||||
}
|
||||
|
||||
$uploadData = json_decode($uploadRes, true);
|
||||
@@ -86,7 +104,7 @@ $fileNameGemini = $uploadData['file']['name'] ?? '';
|
||||
|
||||
if (empty($fileUri)) {
|
||||
updateState($stateFile, 'error', 0, 'لم يتم الحصول على URI من الذكاء الاصطناعي.');
|
||||
exit;
|
||||
return;
|
||||
}
|
||||
|
||||
updateState($stateFile, 'analyzing', 40, 'الكتاب الآن في عقل الذكاء الاصطناعي... جاري المعالجة البصرية واستخراج المعادلات والنصوص...');
|
||||
@@ -109,7 +127,7 @@ for ($i = 0; $i < $maxRetries; $i++) {
|
||||
|
||||
if (!$isReady) {
|
||||
updateState($stateFile, 'error', 0, 'انتهى وقت الانتظار أثناء معالجة الذكاء الاصطناعي لملف الـ PDF.');
|
||||
exit;
|
||||
return;
|
||||
}
|
||||
|
||||
updateState($stateFile, 'analyzing', 60, 'جاري تفريغ المحتوى وتشكيل دروس المارك داون والمصادر الملحقة...');
|
||||
@@ -186,7 +204,7 @@ curl_close($ch);
|
||||
|
||||
if ($code !== 200 || empty($res)) {
|
||||
updateState($stateFile, 'error', 0, 'فشل توليد المحتوى من الذكاء الاصطناعي. قد يكون الملف ضخماً جداً أو الـ API Key غير صالح.');
|
||||
exit;
|
||||
return;
|
||||
}
|
||||
|
||||
$jsonResponse = json_decode($res, true);
|
||||
@@ -195,7 +213,7 @@ $parsedStructure = json_decode($text, true);
|
||||
|
||||
if (empty($parsedStructure) || empty($parsedStructure['units'])) {
|
||||
updateState($stateFile, 'error', 0, 'فشل الذكاء الاصطناعي في إرجاع بنية JSON صالحة.');
|
||||
exit;
|
||||
return;
|
||||
}
|
||||
|
||||
updateState($stateFile, 'generating', 80, 'الذكاء الاصطناعي انتهى من القراءة! جاري بناء الملفات وحفظها على السيرفر...');
|
||||
|
||||
Reference in New Issue
Block a user