fix: Enable automatic teacher course binding on video upload and automated Cloudflare R2 object sync
This commit is contained in:
@@ -151,9 +151,27 @@ class VideoService
|
||||
// Attempt automated Server-Side HLS Transcoding
|
||||
$hlsResult = self::transcodeToHls($targetPath, $courseId, $videoUuid);
|
||||
|
||||
// Attempt automated sync to Cloudflare R2
|
||||
$r2Config = self::getR2Config();
|
||||
$r2VideoUrl = null;
|
||||
if (!empty($r2Config['access_key']) && !empty($r2Config['secret_key']) && !empty($r2Config['bucket'])) {
|
||||
$r2Key = "videos/{$courseId}/{$targetFileName}";
|
||||
$r2VideoUrl = self::uploadToR2($targetPath, $r2Key, $mime);
|
||||
|
||||
$thumbnailPath = dirname(__DIR__, 2) . '/storage/hls/' . $courseId . '/' . $videoUuid . '/thumbnail.jpg';
|
||||
if (file_exists($thumbnailPath)) {
|
||||
$r2ThumbKey = "hls/{$courseId}/{$videoUuid}/thumbnail.jpg";
|
||||
$r2ThumbUrl = self::uploadToR2($thumbnailPath, $r2ThumbKey, 'image/jpeg');
|
||||
if ($r2ThumbUrl) {
|
||||
$hlsResult['thumbnail_url'] = $r2ThumbUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'video_uuid' => $videoUuid,
|
||||
'local_path' => $relativePath,
|
||||
'r2_url' => $r2VideoUrl,
|
||||
'hls_url' => $hlsResult['hls_url'] ?? null,
|
||||
'thumbnail_url' => $hlsResult['thumbnail_url'] ?? null,
|
||||
'duration' => $hlsResult['duration_seconds'] ?? 0,
|
||||
|
||||
Reference in New Issue
Block a user