From 59d9dfe40d0a6c8c49fc9cd2d617c5825b012425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Cmit=20Tun=C3=A7?= Date: Mon, 1 Jun 2026 08:15:49 +0300 Subject: [PATCH] feat: add detailed logging and directory verification for YouTube cover image storage failures --- app/Services/YouTubeService.php | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/app/Services/YouTubeService.php b/app/Services/YouTubeService.php index 1fb5cb6..dd0f31b 100644 --- a/app/Services/YouTubeService.php +++ b/app/Services/YouTubeService.php @@ -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;