mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-01-23 18:49:34 +00:00
Merge branch 'Part-DB:master' into improve-parameter-parsing
This commit is contained in:
commit
3cf66df758
4 changed files with 173 additions and 146 deletions
|
|
@ -125,7 +125,7 @@ abstract class AbstractParameter extends AbstractNamedDBElement
|
|||
#[Assert\Type(['float', null])]
|
||||
#[Assert\LessThanOrEqual(propertyPath: 'value_typical', message: 'parameters.validator.min_lesser_typical')]
|
||||
#[Assert\LessThan(propertyPath: 'value_max', message: 'parameters.validator.min_lesser_max')]
|
||||
#[Groups(['full', 'parameter:read', 'parameter_write'])]
|
||||
#[Groups(['full', 'parameter:read', 'parameter:write'])]
|
||||
#[ORM\Column(type: Types::FLOAT, nullable: true)]
|
||||
protected ?float $value_min = null;
|
||||
|
||||
|
|
@ -142,7 +142,7 @@ abstract class AbstractParameter extends AbstractNamedDBElement
|
|||
*/
|
||||
#[Assert\Type(['float', null])]
|
||||
#[Assert\GreaterThanOrEqual(propertyPath: 'value_typical', message: 'parameters.validator.max_greater_typical')]
|
||||
#[Groups(['full'])]
|
||||
#[Groups(['full', 'parameter:read', 'parameter:write'])]
|
||||
#[ORM\Column(type: Types::FLOAT, nullable: true)]
|
||||
protected ?float $value_max = null;
|
||||
|
||||
|
|
|
|||
|
|
@ -90,6 +90,28 @@ class LCSCProvider implements InfoProviderInterface
|
|||
return $this->getPartDetail($product);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
* @return String
|
||||
*/
|
||||
private function getRealDatasheetUrl(?string $url): string
|
||||
{
|
||||
if (!empty($url) && preg_match("/^https:\/\/(datasheet\.lcsc\.com|www\.lcsc\.com\/datasheet)\/.*(C\d+)\.pdf$/", $url, $matches) > 0) {
|
||||
$response = $this->lcscClient->request('GET', $url, [
|
||||
'headers' => [
|
||||
'Referer' => 'https://www.lcsc.com/product-detail/_' . $matches[2] . '.html'
|
||||
],
|
||||
]);
|
||||
if (preg_match('/(pdfUrl): ?("[^"]+wmsc\.lcsc\.com[^"]+\.pdf")/', $response->getContent(), $matches) > 0) {
|
||||
//HACKY: The URL string contains escaped characters like \u002F, etc. To decode it, the JSON decoding is reused
|
||||
//See https://github.com/Part-DB/Part-DB-server/pull/582#issuecomment-2033125934
|
||||
$jsonObj = json_decode('{"' . $matches[1] . '": ' . $matches[2] . '}');
|
||||
$url = $jsonObj->pdfUrl;
|
||||
}
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $term
|
||||
* @return PartDetailDTO[]
|
||||
|
|
@ -273,7 +295,9 @@ class LCSCProvider implements InfoProviderInterface
|
|||
return [];
|
||||
}
|
||||
|
||||
return [new FileDTO($url, null)];
|
||||
$realUrl = $this->getRealDatasheetUrl($url);
|
||||
|
||||
return [new FileDTO($realUrl, null)];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue