Rewrite LCSC datasheet URL

This commit is contained in:
vvekic 2024-12-08 14:48:16 +01:00
parent b3499e4ea5
commit ec35aade64

View file

@ -97,6 +97,9 @@ class LCSCProvider implements InfoProviderInterface
private function getRealDatasheetUrl(?string $url): string 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 ($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, [ $response = $this->lcscClient->request('GET', $url, [
'headers' => [ 'headers' => [
'Referer' => 'https://www.lcsc.com/product-detail/_' . $matches[2] . '.html' 'Referer' => 'https://www.lcsc.com/product-detail/_' . $matches[2] . '.html'