Enhance KiCad API with stock quantity, datasheet URL, and HTTP caching#1232
Enhance KiCad API with stock quantity, datasheet URL, and HTTP caching#1232Sebbeben wants to merge 5 commits intoPart-DB:masterfrom
Conversation
- Add Stock field showing total available quantity across all part lots - Add Storage Location field when parts have stored locations - Resolve actual datasheet PDF from attachments (by type name, attachment name, or first PDF) instead of always linking to Part-DB page - Keep Part-DB page URL as separate "Part-DB URL" field - Add ETag and Cache-Control headers to all KiCad API endpoints - Support conditional requests (If-None-Match) returning 304 - Categories/part lists cached 5 min, part details cached 1 min
- Add comprehensive KiCadHelperTest with 14 test cases covering: - Stock quantity calculation (zero, single lot, multiple lots) - Stock exclusion of expired and unknown-quantity lots - Storage location display (present, absent, multiple) - Datasheet URL resolution by type name, attachment name, PDF extension - Datasheet fallback to Part-DB URL when no match - "Data sheet" (with space) name variant matching - Fix PDF extension detection for external attachments (getExtension() returns null for external-only attachments, now also parses URL path)
- Use empty Response instead of JsonResponse(null) for 304 Not Modified to avoid sending "null" as response body - Guard parse_url() result with is_string() since it can return false for malformed URLs - Move storage location tracking inside the availability check so expired and unknown-quantity lots don't contribute locations
The test was requesting /parts/1.json instead of /parts/2.json and had Part 1's expected data. Now tests Part 2 which inherits EDA info from its category and footprint, verifying the inheritance behavior.
Replace manual If-None-Match comparison with Response::setEtag() and Response::isNotModified(), which properly handles ETag quoting, weak vs strong comparison, and 304 response cleanup. Fixes PHPStan return type error and CI test failures.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1232 +/- ##
============================================
+ Coverage 54.72% 54.86% +0.14%
- Complexity 7918 7938 +20
============================================
Files 596 596
Lines 25468 25516 +48
============================================
+ Hits 13937 13999 +62
+ Misses 11531 11517 -14 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
From some quick look:
|
|
Thanks for the feedback! I've added a configurable system setting "Datasheet field links to PDF" ( I've opened a more comprehensive PR #1241 that includes this fix along with several other KiCad improvements (API v2 with volatile fields, batch EDA editing, configurable field export, BOM multi-footprint merging, etc.). Closing this PR in favor of #1241. |
Summary
Adds three improvements to the KiCad HTTP Library API ():
Also fixes a pre-existing bug in \ which was actually testing Part 1 instead of Part 2.
Related issues
New fields exposed
Test plan