Added possibility to enable/disable the LCSC provider

This commit is contained in:
Jan Böhmer 2024-02-22 23:32:12 +01:00
parent d600cb4b9a
commit 95ef97fcc2
3 changed files with 15 additions and 4 deletions

7
.env
View file

@ -168,6 +168,13 @@ PROVIDER_MOUSER_SEARCH_LIMIT=50
# Used when searching for keywords in the language specified when you signed up for Search API. # Used when searching for keywords in the language specified when you signed up for Search API.
PROVIDER_MOUSER_SEARCH_WITH_SIGNUP_LANGUAGE='true' PROVIDER_MOUSER_SEARCH_WITH_SIGNUP_LANGUAGE='true'
# LCSC Provider:
# LCSC does not provide an offical API, so this used the API LCSC uses to render their webshop.
# LCSC did not intended the use of this API and it could break any time, so use it at your own risk.
# We dont require an API key for LCSC, just set this to 1 to enable LCSC support
PROVIDER_LCSC_ENABLED=0
################################################################################## ##################################################################################
# EDA integration related settings # EDA integration related settings
################################################################################## ##################################################################################

View file

@ -307,6 +307,10 @@ services:
$options: '%env(string:PROVIDER_MOUSER_SEARCH_OPTION)%' $options: '%env(string:PROVIDER_MOUSER_SEARCH_OPTION)%'
$search_limit: '%env(int:PROVIDER_MOUSER_SEARCH_LIMIT)%' $search_limit: '%env(int:PROVIDER_MOUSER_SEARCH_LIMIT)%'
App\Services\InfoProviderSystem\Providers\LCSCProvider:
arguments:
$enabled: '%env(bool:PROVIDER_LCSC_ENABLED)%'
#################################################################################################################### ####################################################################################################################
# API system # API system
#################################################################################################################### ####################################################################################################################

View file

@ -38,7 +38,7 @@ class LCSCProvider implements InfoProviderInterface
public const DISTRIBUTOR_NAME = 'LCSC'; public const DISTRIBUTOR_NAME = 'LCSC';
public function __construct(private readonly HttpClientInterface $lcscClient) public function __construct(private readonly HttpClientInterface $lcscClient, private bool $enabled = true)
{ {
} }
@ -47,9 +47,9 @@ class LCSCProvider implements InfoProviderInterface
{ {
return [ return [
'name' => 'LCSC', 'name' => 'LCSC',
'description' => 'This provider uses the LCSC API to search for parts.', 'description' => 'This provider uses the (unofficial) LCSC API to search for parts.',
'url' => 'https://www.lcsc.com/', 'url' => 'https://www.lcsc.com/',
'disabled_help' => 'This provider is enabled by default' 'disabled_help' => 'Set PROVIDER_LCSC_ENABLED to 1 (or true) in your environment variable config.'
]; ];
} }
@ -61,7 +61,7 @@ class LCSCProvider implements InfoProviderInterface
// This provider is always active // This provider is always active
public function isActive(): bool public function isActive(): bool
{ {
return true; return $this->enabled;
} }
/** /**