Update Saqel Platform: 2026-09-02 00:55:56
This commit is contained in:
@@ -158,6 +158,17 @@ class VideoService
|
||||
$r2Key = "videos/{$courseId}/{$targetFileName}";
|
||||
$r2VideoUrl = self::uploadToR2($targetPath, $r2Key, $mime);
|
||||
|
||||
// The player must receive a complete HLS package, not only the source MP4.
|
||||
// Upload the playlist and every segment using the same relative layout so
|
||||
// relative segment references in index.m3u8 continue to resolve on R2.
|
||||
if (!empty($hlsResult['hls_url'])) {
|
||||
$hlsDir = dirname(__DIR__, 2) . '/storage/hls/' . $courseId . '/' . $videoUuid;
|
||||
$r2HlsPlaylist = self::uploadHlsDirectoryToR2($hlsDir, $courseId, $videoUuid);
|
||||
if ($r2HlsPlaylist) {
|
||||
$hlsResult['hls_url'] = $r2HlsPlaylist;
|
||||
}
|
||||
}
|
||||
|
||||
$thumbnailPath = dirname(__DIR__, 2) . '/storage/hls/' . $courseId . '/' . $videoUuid . '/thumbnail.jpg';
|
||||
if (file_exists($thumbnailPath)) {
|
||||
$r2ThumbKey = "hls/{$courseId}/{$videoUuid}/thumbnail.jpg";
|
||||
@@ -393,6 +404,8 @@ class VideoService
|
||||
{
|
||||
$config = self::getBunnyConfig();
|
||||
if (empty($config['api_key'])) {
|
||||
throw new \RuntimeException('Bunny Stream غير مهيأ: أضف مفاتيح الوصول قبل إنشاء فيديو سحابي.');
|
||||
/*
|
||||
$mockGuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
|
||||
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
|
||||
mt_rand(0, 0xffff),
|
||||
@@ -409,6 +422,7 @@ class VideoService
|
||||
'direct_embed' => "https://{$config['embed_host']}/embed/{$config['library_id']}/{$mockGuid}",
|
||||
'hls_playlist' => "https://{$config['pull_zone_host']}/{$mockGuid}/playlist.m3u8"
|
||||
];
|
||||
*/
|
||||
}
|
||||
|
||||
$url = "https://video.bunnycdn.com/library/{$config['library_id']}/videos";
|
||||
@@ -581,10 +595,33 @@ class VideoService
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if ($httpCode >= 200 && $httpCode < 300) {
|
||||
if ($httpCode >= 200 && $httpCode < 300 && !empty($config['public_url'])) {
|
||||
return rtrim($config['public_url'], '/') . '/' . ltrim($r2Key, '/');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Upload a complete HLS directory and return the public playlist URL. */
|
||||
private static function uploadHlsDirectoryToR2(string $directory, int $courseId, string $videoUuid): ?string
|
||||
{
|
||||
if (!is_dir($directory)) return null;
|
||||
|
||||
$playlistUrl = null;
|
||||
foreach (glob($directory . '/*') ?: [] as $filePath) {
|
||||
if (!is_file($filePath)) continue;
|
||||
$extension = strtolower(pathinfo($filePath, PATHINFO_EXTENSION));
|
||||
$contentType = match ($extension) {
|
||||
'm3u8' => 'application/vnd.apple.mpegurl',
|
||||
'ts' => 'video/mp2t',
|
||||
'jpg', 'jpeg' => 'image/jpeg',
|
||||
default => 'application/octet-stream',
|
||||
};
|
||||
$key = "hls/{$courseId}/{$videoUuid}/" . basename($filePath);
|
||||
$url = self::uploadToR2($filePath, $key, $contentType);
|
||||
if ($extension === 'm3u8' && $url) $playlistUrl = $url;
|
||||
}
|
||||
|
||||
return $playlistUrl;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user