Update Saqel Platform: 2026-09-09 00:24:41
This commit is contained in:
@@ -151,12 +151,13 @@ class VideoController
|
||||
}
|
||||
|
||||
try {
|
||||
$uploadResult = VideoService::handleDirectUpload($_FILES['video'], $courseId, $title);
|
||||
// Fast direct upload: save file locally and slice HLS instantly via stream copy (-c copy)
|
||||
$uploadResult = VideoService::handleDirectUpload($_FILES['video'], $courseId, $title, false);
|
||||
|
||||
// Insert lesson record with HLS references
|
||||
$lessonId = Database::insert(
|
||||
// Insert lesson record with HLS references and processing status
|
||||
$lessonId = (int)Database::insert(
|
||||
"INSERT INTO lessons (course_id, title, curriculum_key, sequence_order, storage_type, video_uuid, bunny_video_id, local_path, hls_url, thumbnail_url, duration_seconds, is_free_preview, encoding_status)
|
||||
VALUES (?, ?, ?, ?, 'api_upload', ?, '', ?, ?, ?, ?, 0, 'ready')",
|
||||
VALUES (?, ?, ?, ?, 'api_upload', ?, '', ?, ?, ?, ?, 0, 'processing')",
|
||||
[
|
||||
$courseId,
|
||||
$title,
|
||||
@@ -173,21 +174,48 @@ class VideoController
|
||||
Database::query('UPDATE video_upload_audits SET lesson_id = ? WHERE id = ?', [$lessonId, $auditId]);
|
||||
}
|
||||
|
||||
// Autonomous Zero-Touch AI Analysis & Socratic Checkpoint Generation (Silent Background Execution)
|
||||
$aiReport = AiVideoAnalyzerService::processLessonAutonomously($lessonId);
|
||||
|
||||
$response->status(201)->json([
|
||||
// Immediately send HTTP 201 response to Flutter client and close connection
|
||||
$responsePayload = [
|
||||
'status' => 'success',
|
||||
'message' => 'تم رفع الفيديو وتقطيعه بتقنية HLS وتوليد الفحص السقراطي الذكي تلقائياً بنجاح!',
|
||||
'message' => 'تم رفع الفيديو واعتماده مبدئياً بنجاح. تجري المزامنة السحابية والتحليل السقراطي في الخلفية.',
|
||||
'data' => array_merge($uploadResult, [
|
||||
'lesson_id' => $lessonId,
|
||||
'title' => $title,
|
||||
'course_id' => $courseId,
|
||||
'ai_analysis' => $aiReport
|
||||
,'preflight_report' => $preflight,
|
||||
'audit_id' => $auditId,
|
||||
'lesson_id' => $lessonId,
|
||||
'title' => $title,
|
||||
'course_id' => $courseId,
|
||||
'preflight_report' => $preflight,
|
||||
'audit_id' => $auditId,
|
||||
])
|
||||
]);
|
||||
];
|
||||
|
||||
$response->jsonAndFinish($responsePayload, 201);
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// ASYNCHRONOUS BACKGROUND WORKER (PHP-FPM continues running after client exit)
|
||||
// -------------------------------------------------------------------------
|
||||
@ignore_user_abort(true);
|
||||
@set_time_limit(600);
|
||||
|
||||
try {
|
||||
// 1. Sync MP4, HLS segments, and thumbnail to Cloudflare R2
|
||||
VideoService::syncLessonToR2(
|
||||
$lessonId,
|
||||
$courseId,
|
||||
$uploadResult['target_path'],
|
||||
$uploadResult['target_file_name'],
|
||||
$uploadResult['video_uuid'],
|
||||
$uploadResult['mime_type']
|
||||
);
|
||||
|
||||
// 2. Autonomous Zero-Touch AI Analysis & Socratic Checkpoint Generation
|
||||
AiVideoAnalyzerService::processLessonAutonomously($lessonId);
|
||||
|
||||
// 3. Mark encoding as ready
|
||||
Database::query("UPDATE lessons SET encoding_status = 'ready' WHERE id = ?", [$lessonId]);
|
||||
} catch (\Throwable $bgError) {
|
||||
error_log("Background sync/analysis error for lesson {$lessonId}: " . $bgError->getMessage());
|
||||
}
|
||||
|
||||
exit;
|
||||
} catch (\Throwable $e) {
|
||||
$response->status(500)->json([
|
||||
'status' => 'error',
|
||||
|
||||
Reference in New Issue
Block a user