diff --git a/app/Services/LogoLib/AbstractLogoLib.php b/app/Services/LogoLib/AbstractLogoLib.php index dabae16b..288ad182 100644 --- a/app/Services/LogoLib/AbstractLogoLib.php +++ b/app/Services/LogoLib/AbstractLogoLib.php @@ -20,6 +20,11 @@ abstract class AbstractLogoLib implements LogoLibInterface */ protected string $libUrl = ''; + /** + * Base url of the icon collection + */ + protected string $format = 'svg'; + /** * Fetch a logo for the given service and save it as an icon * @@ -30,9 +35,14 @@ abstract class AbstractLogoLib implements LogoLibInterface { $logoFilename = $this->getLogo(strval($serviceName)); + if (!$logoFilename) { + // maybe the svg is not available, we try to get the png format + $this->format = 'png'; + $logoFilename = $this->getLogo(strval($serviceName)); + } + if ($logoFilename) { - // $iconFilename = IconService::getRandomName('svg'); - $iconFilename = \Illuminate\Support\Str::random(40) . '.svg'; + $iconFilename = \Illuminate\Support\Str::random(40) . '.' . $this->format; return $this->copyToIconStore($logoFilename, $iconFilename) ? $iconFilename : null; } else { @@ -49,7 +59,7 @@ abstract class AbstractLogoLib implements LogoLibInterface protected function getLogo(string $serviceName) { $referenceName = $this->sanitizeServiceName(strval($serviceName)); - $logoFilename = $referenceName . '.svg'; + $logoFilename = $referenceName . '.' . $this->format; $cachedFilename = $this->cachePrefix . $logoFilename; if ($referenceName && ! Storage::disk('logos')->exists($cachedFilename)) { @@ -64,7 +74,7 @@ abstract class AbstractLogoLib implements LogoLibInterface */ protected function logoUrl(string $logoFilename) : string { - return $this->libUrl . $logoFilename; + return $this->libUrl . $this->format . '/' . $logoFilename; } /** diff --git a/app/Services/LogoLib/DashboardiconsLogoLib.php b/app/Services/LogoLib/DashboardiconsLogoLib.php index 8b6231aa..c809be4d 100644 --- a/app/Services/LogoLib/DashboardiconsLogoLib.php +++ b/app/Services/LogoLib/DashboardiconsLogoLib.php @@ -4,7 +4,6 @@ namespace App\Services\LogoLib; use App\Services\LogoLib\AbstractLogoLib; use App\Services\LogoLib\LogoLibInterface; -use Illuminate\Support\Facades\Storage; class DashboardiconsLogoLib extends AbstractLogoLib implements LogoLibInterface { @@ -16,6 +15,6 @@ class DashboardiconsLogoLib extends AbstractLogoLib implements LogoLibInterface /** * Base url of the icon collection */ - protected string $libUrl = 'https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/svg/'; + protected string $libUrl = 'https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/'; } diff --git a/app/Services/LogoLib/SelfhLogoLib.php b/app/Services/LogoLib/SelfhLogoLib.php index 0e567e54..034600cf 100644 --- a/app/Services/LogoLib/SelfhLogoLib.php +++ b/app/Services/LogoLib/SelfhLogoLib.php @@ -4,7 +4,6 @@ namespace App\Services\LogoLib; use App\Services\LogoLib\AbstractLogoLib; use App\Services\LogoLib\LogoLibInterface; -use Illuminate\Support\Facades\Storage; class SelfhLogoLib extends AbstractLogoLib implements LogoLibInterface { @@ -16,5 +15,5 @@ class SelfhLogoLib extends AbstractLogoLib implements LogoLibInterface /** * Base url of the icon collection */ - protected string $libUrl = 'https://cdn.jsdelivr.net/gh/selfhst/icons/svg/'; + protected string $libUrl = 'https://cdn.jsdelivr.net/gh/selfhst/icons/'; } diff --git a/app/Services/LogoLib/TfaLogoLib.php b/app/Services/LogoLib/TfaLogoLib.php index b11d9f4a..f984da46 100644 --- a/app/Services/LogoLib/TfaLogoLib.php +++ b/app/Services/LogoLib/TfaLogoLib.php @@ -39,6 +39,25 @@ class TfaLogoLib extends AbstractLogoLib implements LogoLibInterface $this->setTfaCollection(); } + /** + * Fetch a logo for the given service and save it as an icon + * + * @param string|null $serviceName Name of the service to fetch a logo for + * @return string|null The icon filename or null if no logo has been found + */ + public function getIcon(?string $serviceName) : string|null + { + $logoFilename = $this->getLogo(strval($serviceName)); + + if ($logoFilename) { + $iconFilename = \Illuminate\Support\Str::random(40) . '.' . $this->format; + + return $this->copyToIconStore($logoFilename, $iconFilename) ? $iconFilename : null; + } else { + return null; + } + } + /** * Return the logo's filename for a given service * @@ -48,7 +67,7 @@ class TfaLogoLib extends AbstractLogoLib implements LogoLibInterface protected function getLogo(string $serviceName) { $referenceName = $this->tfas->get($this->sanitizeServiceName(strval($serviceName))); - $logoFilename = $referenceName . '.svg'; + $logoFilename = $referenceName . '.' . $this->format; $cachedFilename = $this->cachePrefix . $logoFilename; if ($referenceName && ! Storage::disk('logos')->exists($cachedFilename)) {