mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-06-21 20:41:28 +02:00
Add fallback to png format when svg logo is not available
This commit is contained in:
parent
c693c840b2
commit
c4acd572f8
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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/';
|
||||
|
||||
}
|
||||
|
@ -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/';
|
||||
}
|
||||
|
@ -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)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user