feat: add detailed logging and directory verification for YouTube cover image storage failures
This commit is contained in:
@@ -360,19 +360,48 @@ class YouTubeService
|
||||
$response = Http::timeout(30)->get($imageUrl);
|
||||
|
||||
if ($response->failed()) {
|
||||
Log::warning('YouTube cover image fetch HTTP request failed', [
|
||||
'video_id' => $videoId,
|
||||
'url' => $imageUrl,
|
||||
'status' => $response->status(),
|
||||
]);
|
||||
return null;
|
||||
}
|
||||
|
||||
$extension = $this->guessImageExtension($response->header('Content-Type'));
|
||||
$path = 'music-productions/covers/youtube-' . $videoId . '.' . $extension;
|
||||
|
||||
Storage::disk('public')->put($path, $response->body());
|
||||
$absolutePath = Storage::disk('public')->path($path);
|
||||
$directory = dirname($absolutePath);
|
||||
|
||||
if (!is_dir($directory)) {
|
||||
@mkdir($directory, 0775, true);
|
||||
}
|
||||
|
||||
if (is_dir($directory) && !is_writable($directory)) {
|
||||
Log::error('YouTube cover directory is not writable. Check folder ownership and permissions.', [
|
||||
'directory' => $directory,
|
||||
'owner' => function_exists('posix_getpwuid') ? posix_getpwuid(fileowner($directory))['name'] : fileowner($directory),
|
||||
'perms' => substr(sprintf('%o', fileperms($directory)), -4),
|
||||
]);
|
||||
}
|
||||
|
||||
$stored = Storage::disk('public')->put($path, $response->body());
|
||||
|
||||
if (!$stored) {
|
||||
Log::error('Failed to store YouTube cover image via storage disk.', [
|
||||
'path' => $path,
|
||||
'video_id' => $videoId,
|
||||
]);
|
||||
return null;
|
||||
}
|
||||
|
||||
return $path;
|
||||
} catch (\Throwable $exception) {
|
||||
Log::warning('YouTube cover download failed', [
|
||||
Log::error('YouTube cover download failed with exception', [
|
||||
'video_id' => $videoId,
|
||||
'message' => $exception->getMessage(),
|
||||
'trace' => $exception->getTraceAsString(),
|
||||
]);
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user