You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
"use strict";
|
|
|
|
const assert = require("assert");
|
|
|
|
const assureResponse = require("../../shared/assure-response");
|
|
|
|
// TODO: Validate response formats with validatem instead
|
|
|
|
module.exports = function lcscScrapeCategory(state) {
|
|
let { session } = state;
|
|
|
|
return async function ({ data, createItem, deleteItem, updateData }) {
|
|
let response = await session.post(`https://wwwapi.lcsc.com/v1/products/list`, {
|
|
catalogIdList: [ data.catalogId ],
|
|
currentPage: data.pageNumber,
|
|
pageSize: 500,
|
|
paramNameValueMap: {}
|
|
});
|
|
|
|
assureResponse(response);
|
|
assert(response.statusCode === 200);
|
|
assert(response.body.productList.length > 0);
|
|
|
|
for (let item of response.body.productList) {
|
|
createItem({
|
|
// NOTE: item.productId seems like the database ID on the website, but item.productCode is the actual LCSC part number used internally for inventory management, so we use that for identification instead
|
|
id: `lcsc:product:${item.productCode}`,
|
|
tags: [ "lcsc:product" ],
|
|
data: item
|
|
});
|
|
}
|
|
|
|
// We don't keep around page items, because the amount of pages for a category can change, and so this isn't a stable identifier. They'll be recreated on the next category scrape anyway.
|
|
deleteItem();
|
|
};
|
|
};
|