fix(streams): adding a stream without an icon failed

StreamService::process() runs the stream icon through
ImageUtils::downloadImage() when "download images" is on, and an empty icon
arrives there as null. The `string` type the cs-fix pass (758a9cab) put on
the parameter made that a TypeError, so saving a new stream with no icon
answered an empty page and created nothing. Series, movies, episodes, radios
and created channels hand it optional covers and backdrops the same way.

downloadImage() now takes null and hands back whatever it cannot download
unchanged, null included. Found by the new E2E stream test.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016WDhDajBPziJwjWZcXnh6R
This commit is contained in:
root
2026-09-16 14:38:17 +00:00
co-authored by Claude Opus 5
parent fd13c94032
commit ee2f586a44
2 changed files with 17 additions and 5 deletions
+6 -5
View File
@@ -122,12 +122,13 @@ class ImageUtils {
* Stores jpg/jpeg/png images and returns an internal `s:<serverId>:` reference;
* returns the original URL unchanged when not downloadable.
*
* @param string $rImage Remote image URL.
* @param int|null $rType Optional stream type (unused placeholder).
* @return string Internal `s:` reference, or the original URL.
* @param string|null $rImage Remote image URL; callers pass optional columns
* (an icon, a backdrop), so it may be null.
* @param int|null $rType Optional stream type (unused placeholder).
* @return string|null Internal `s:` reference, or $rImage unchanged.
*/
public static function downloadImage(string $rImage, ?int $rType = null) {
if ($rImage !== '' && substr(strtolower($rImage), 0, 4) == 'http') {
public static function downloadImage(?string $rImage, ?int $rType = null) {
if ((string) $rImage !== '' && substr(strtolower($rImage), 0, 4) == 'http') {
$rPathInfo = pathinfo(parse_url($rImage, PHP_URL_PATH) ?: $rImage);
$rExt = strtolower($rPathInfo['extension'] ?? '');
if (!$rExt) {
+11
View File
@@ -32,4 +32,15 @@ final class ImageUtilsTest extends TestCase {
$this->assertFalse(ImageUtils::isAbsoluteUrl('/relative/a.png'));
$this->assertFalse(ImageUtils::isAbsoluteUrl('a.png'));
}
/**
* Callers hand over optional columns (a stream without an icon, a movie
* without a backdrop). What cannot be downloaded comes back unchanged —
* null included; it used to end the save with a TypeError.
*/
public function testDownloadImageReturnsWhatItCannotDownload() {
$this->assertNull(ImageUtils::downloadImage(null, 1));
$this->assertSame('', ImageUtils::downloadImage(''));
$this->assertSame('/images/local.png', ImageUtils::downloadImage('/images/local.png', 2));
}
}