Skip to content

Commit

Permalink
Rewrite LCSC datasheet URL (#795)
Browse files Browse the repository at this point in the history
  • Loading branch information
vvekic authored Dec 10, 2024
1 parent 8faa325 commit 0f92a69
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Services/InfoProviderSystem/Providers/LCSCProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ private function queryDetail(string $id): PartDetailDTO
private function getRealDatasheetUrl(?string $url): string
{
if ($url !== null && trim($url) !== '' && preg_match("/^https:\/\/(datasheet\.lcsc\.com|www\.lcsc\.com\/datasheet)\/.*(C\d+)\.pdf$/", $url, $matches) > 0) {
if (preg_match("/^https:\/\/datasheet\.lcsc\.com\/lcsc\/(.*\.pdf)$/", $url, $rewriteMatches) > 0) {
$url = 'https://www.lcsc.com/datasheet/lcsc_datasheet_' . $rewriteMatches[1];
}
$response = $this->lcscClient->request('GET', $url, [
'headers' => [
'Referer' => 'https://www.lcsc.com/product-detail/_' . $matches[2] . '.html'
Expand Down

3 comments on commit 0f92a69

@dm5tt
Copy link

@dm5tt dm5tt commented on 0f92a69 Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hand injected this change into the latest Docker and searched for C7422093. Still getting a 500.

Image

@mrixs
Copy link

@mrixs mrixs commented on 0f92a69 Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dm5tt Changes fixed issue for me. Have you reset caches?
php bin/console cache:clear

@dm5tt
Copy link

@dm5tt dm5tt commented on 0f92a69 Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. tried it. Did I miss something?

Log:

`"} {"token":{"authenticated":true,"roles":["ROLE_USER"],"user_identifier":"admin"},"url":"/en/tools/info_providers/search","ip":"192.168.1.197","http_method":"POST","server":"192.168.1.3","referrer":"http://192.168.1.3:8080/en/tools/info_providers/search"}
[2024-12-10T20:39:51.117102+00:00] cache.INFO: Lock acquired, now computing item "search_lcsc_test" {"key":"search_lcsc_test"} {"token":{"authenticated":true,"roles":["ROLE_USER"],"user_identifier":"admin"},"url":"/en/tools/info_providers/search","ip":"192.168.1.197","http_method":"POST","server":"192.168.1.3","referrer":"http://192.168.1.3:8080/en/tools/info_providers/search"}
[2024-12-10T20:39:51.117262+00:00] http_client.INFO: Request: "GET https://wmsc.lcsc.com/ftps/wm/search/global?keyword=test" [] {"token":{"authenticated":true,"roles":["ROLE_USER"],"user_identifier":"admin"},"url":"/en/tools/info_providers/search","ip":"192.168.1.197","http_method":"POST","server":"192.168.1.3","referrer":"http://192.168.1.3:8080/en/tools/info_providers/search"}
[2024-12-10T20:39:51.379648+00:00] http_client.INFO: Response: "200 https://wmsc.lcsc.com/ftps/wm/search/global?keyword=test" [] {"token":{"authenticated":true,"roles":["ROLE_USER"],"user_identifier":"admin"},"url":"/en/tools/info_providers/search","ip":"192.168.1.197","http_method":"POST","server":"192.168.1.3","referrer":"http://192.168.1.3:8080/en/tools/info_providers/search"}
[2024-12-10T20:39:51.382078+00:00] http_client.INFO: Request: "GET https://datasheet.lcsc.com/lcsc/2312110928_Vishay-Intertech-TEST2600_C3210888.pdf" [] {"token":{"authenticated":true,"roles":["ROLE_USER"],"user_identifier":"admin"},"url":"/en/tools/info_providers/search","ip":"192.168.1.197","http_method":"POST","server":"192.168.1.3","referrer":"http://192.168.1.3:8080/en/tools/info_providers/search"}
[2024-12-10T20:39:51.545029+00:00] http_client.INFO: Response: "502 https://datasheet.lcsc.com/lcsc/2312110928_Vishay-Intertech-TEST2600_C3210888.pdf" [] {"token":{"authenticated":true,"roles":["ROLE_USER"],"user_identifier":"admin"},"url":"/en/tools/info_providers/search","ip":"192.168.1.197","http_method":"POST","server":"192.168.1.3","referrer":"http://192.168.1.3:8080/en/tools/info_providers/search"}
[2024-12-10T20:39:51.546204+00:00] request.CRITICAL: Uncaught PHP Exception Symfony\Component\HttpClient\Exception\ServerException: "HTTP/2 502  returned for "https://datasheet.lcsc.com/lcsc/2312110928_Vishay-Intertech-TEST2600_C3210888.pdf"." at CommonResponseTrait.php line 169 {"exception":"[object] (Symfony\\Component\\HttpClient\\Exception\\ServerException(code: 502): HTTP/2 502  returned for \"https://datasheet.lcsc.com/lcsc/2312110928_Vishay-Intertech-TEST2600_C3210888.pdf\". at /var/www/html/vendor/symfony/http-client/Response/CommonResponseTrait.php:169)
[stacktrace]
#0 /var/www/html/vendor/symfony/http-client/Response/CommonResponseTrait.php(47): Symfony\\Component\\HttpClient\\Response\\CurlResponse->checkStatusCode()
#1 /var/www/html/vendor/symfony/http-client/Response/CurlResponse.php(229): Symfony\\Component\\HttpClient\\Response\\CurlResponse->doGetContent()
#2 /var/www/html/src/Services/InfoProviderSystem/Providers/LCSCProvider.php(105): Symfony\\Component\\HttpClient\\Response\\CurlResponse->getContent()
#3 /var/www/html/src/Services/InfoProviderSystem/Providers/LCSCProvider.php(298): App\\Services\\InfoProviderSystem\\Providers\\LCSCProvider->getRealDatasheetUrl()
#4 /var/www/html/src/Services/InfoProviderSystem/Providers/LCSCProvider.php(212): App\\Services\\InfoProviderSystem\\Providers\\LCSCProvider->getProductDatasheets()
#5 /var/www/html/src/Services/InfoProviderSystem/Providers/LCSCProvider.php(147): App\\Services\\InfoProviderSystem\\Providers\\LCSCProvider->getPartDetail()
#6 /var/www/html/src/Services/InfoProviderSystem/Providers/LCSCProvider.php(336): App\\Services\\InfoProviderSystem\\Providers\\LCSCProvider->queryByTerm()
#7 /var/www/html/src/Services/InfoProviderSystem/PartInfoRetriever.php(82): App\\Services\\InfoProviderSystem\\Providers\\LCSCProvider->searchByKeyword()
#8 /var/www/html/vendor/symfony/cache/LockRegistry.php(111): App\\Services\\InfoProviderSystem\\PartInfoRetriever->App\\Services\\InfoProviderSystem\\{closure}()
#9 /var/www/html/vendor/symfony/cache/Traits/ContractsTrait.php(102): Symfony\\Component\\Cache\\LockRegistry::compute()
#10 /var/www/html/vendor/symfony/cache-contracts/CacheTrait.php(64): Symfony\\Component\\Cache\\Adapter\\AbstractAdapter->Symfony\\Component\\Cache\\Traits\\{closure}()
#11 /var/www/html/vendor/symfony/cache/Traits/ContractsTrait.php(85): Symfony\\Component\\Cache\\Adapter\\AbstractAdapter->contractsGet()
#12 /var/www/html/vendor/symfony/cache-contracts/CacheTrait.php(30): Symfony\\Component\\Cache\\Adapter\\AbstractAdapter->doGet()
#13 /var/www/html/src/Services/InfoProviderSystem/PartInfoRetriever.php(78): Symfony\\Component\\Cache\\Adapter\\AbstractAdapter->get()
#14 /var/www/html/src/Services/InfoProviderSystem/PartInfoRetriever.php(64): App\\Services\\InfoProviderSystem\\PartInfoRetriever->searchInProvider()
#15 /var/www/html/src/Controller/InfoProviderController.php(83): App\\Services\\InfoProviderSystem\\PartInfoRetriever->searchByKeyword()
#16 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(181): App\\Controller\\InfoProviderController->search()
#17 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw()
#18 /var/www/html/vendor/symfony/http-kernel/Kernel.php(197): Symfony\\Component\\HttpKernel\\HttpKernel->handle()
#19 /var/www/html/vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php(35): Symfony\\Component\\HttpKernel\\Kernel->handle()
#20 /var/www/html/vendor/autoload_runtime.php(29): Symfony\\Component\\Runtime\\Runner\\Symfony\\HttpKernelRunner->run()
#21 /var/www/html/public/index.php(5): require_once('...')
#22 {main}

Please sign in to comment.