Update Saqel Platform: 2026-08-29 22:05:41
This commit is contained in:
@@ -260,48 +260,60 @@ class CurriculumController
|
||||
return;
|
||||
}
|
||||
|
||||
$uploadDir = __DIR__ . '/../../public/uploads/curriculum_videos';
|
||||
if (!is_dir($uploadDir)) {
|
||||
mkdir($uploadDir, 0777, true);
|
||||
}
|
||||
|
||||
$videoTmp = $_FILES['video_file']['tmp_name'];
|
||||
$ext = strtolower(pathinfo($_FILES['video_file']['name'], PATHINFO_EXTENSION)) ?: 'mp4';
|
||||
|
||||
// Semantic, human-readable file naming (e.g. video_grade_10_math_10_unit_01_lesson_01.mp4)
|
||||
$cleanBase = preg_replace('/[^a-zA-Z0-9_-]+/', '_', str_replace(['.md', '/'], ['', '_'], $file));
|
||||
$cleanBase = trim($cleanBase, '_');
|
||||
$safeName = 'video_' . $cleanBase . '_' . time() . '.' . $ext;
|
||||
$destPath = $uploadDir . '/' . $safeName;
|
||||
|
||||
if (!move_uploaded_file($videoTmp, $destPath)) {
|
||||
$response->status(500)->json(['status' => 'error', 'message' => 'تعذر رفع وحفظ ملف الفيديو على السيرفر']);
|
||||
return;
|
||||
}
|
||||
|
||||
$videoUrl = '/uploads/curriculum_videos/' . $safeName;
|
||||
|
||||
// 1. Update Lesson AI assets in manifest.json & filesystem
|
||||
$currentAssets = CurriculumService::getLessonAiAssets($file);
|
||||
$currentAssets['ai_video_url'] = $videoUrl;
|
||||
CurriculumService::saveLessonAiAssets($file, $currentAssets);
|
||||
|
||||
// 2. Direct Sync to MySQL Database Table `lessons`
|
||||
try {
|
||||
$filename = basename($file, '.md');
|
||||
\App\Core\Database::query(
|
||||
"UPDATE lessons SET ai_video_url = ? WHERE title LIKE ? OR markdown_content LIKE ?",
|
||||
[$videoUrl, "%{$filename}%", "%{$file}%"]
|
||||
);
|
||||
} catch (\Throwable $dbEx) {
|
||||
error_log("Video DB sync note: " . $dbEx->getMessage());
|
||||
}
|
||||
$courseId = 0; // System course ID for curriculum AI videos
|
||||
$title = basename($file, '.md');
|
||||
|
||||
$response->json([
|
||||
'status' => 'success',
|
||||
'message' => 'تم رفع وتثبيت فيديو الشرح وربطه بالدرس وقاعدة البيانات بنجاح!',
|
||||
'video_url' => $videoUrl,
|
||||
'file_name' => $safeName
|
||||
]);
|
||||
// 1. Upload & Transcode to HLS & Push to R2 (handled by VideoService)
|
||||
$uploadResult = \App\Services\VideoService::handleDirectUpload($_FILES['video_file'], $courseId, $title);
|
||||
|
||||
$videoUrl = $uploadResult['r2_url'] ?? $uploadResult['hls_url'];
|
||||
|
||||
// 2. Insert into lessons table as AI generated version
|
||||
$lessonId = \App\Core\Database::insert(
|
||||
"INSERT INTO lessons (course_id, title, sequence_order, storage_type, video_uuid, bunny_video_id, local_path, hls_url, thumbnail_url, duration_seconds, is_free_preview, encoding_status, ai_video_url)
|
||||
VALUES (?, ?, 1, 'api_upload', ?, '', ?, ?, ?, ?, 0, 'ready', ?)",
|
||||
[
|
||||
$courseId,
|
||||
$title,
|
||||
$uploadResult['video_uuid'],
|
||||
$uploadResult['local_path'],
|
||||
$uploadResult['hls_url'],
|
||||
$uploadResult['thumbnail_url'],
|
||||
$uploadResult['duration'] ?? 0,
|
||||
$videoUrl
|
||||
]
|
||||
);
|
||||
|
||||
// 3. Trigger Autonomous Zero-Touch AI Analysis & Socratic Checkpoint Generation
|
||||
\App\Services\AiVideoAnalyzerService::processLessonAutonomously($lessonId);
|
||||
|
||||
// 4. Update Lesson AI assets in manifest.json & filesystem
|
||||
$currentAssets = CurriculumService::getLessonAiAssets($file);
|
||||
$currentAssets['ai_video_url'] = $videoUrl;
|
||||
CurriculumService::saveLessonAiAssets($file, $currentAssets);
|
||||
|
||||
// 5. Update any existing curriculum lesson rows with this video
|
||||
try {
|
||||
\App\Core\Database::query(
|
||||
"UPDATE lessons SET ai_video_url = ? WHERE title LIKE ? OR markdown_content LIKE ?",
|
||||
[$videoUrl, "%{$title}%", "%{$file}%"]
|
||||
);
|
||||
} catch (\Throwable $dbEx) {
|
||||
error_log("Video DB sync note: " . $dbEx->getMessage());
|
||||
}
|
||||
|
||||
$response->status(201)->json([
|
||||
'status' => 'success',
|
||||
'message' => 'تم رفع وتثبيت فيديو الشرح ومعالجته HLS وربطه بالذكاء الاصطناعي بنجاح!',
|
||||
'video_url' => $videoUrl,
|
||||
'data' => $uploadResult
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
$response->status(500)->json([
|
||||
'status' => 'error',
|
||||
'message' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user