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.
61 lines
1.4 KiB
JavaScript
61 lines
1.4 KiB
JavaScript
"use strict";
|
|
|
|
const assert = require("assert");
|
|
|
|
const assureResponse = require("../../shared/assure-response");
|
|
|
|
module.exports = function lcscFindCategories(state) {
|
|
const withCsrfToken = require("../with-csrf-token")(state);
|
|
|
|
let { session } = state;
|
|
|
|
return async function ({ createItem }) {
|
|
let response = await withCsrfToken((token) => {
|
|
return session.post("https://lcsc.com/products/categories", {
|
|
manufacturer: "",
|
|
in_stock: "false",
|
|
is_RoHS: "false"
|
|
}, {
|
|
headers: {
|
|
"accept": "application/json, text/javascript, */*; q=0.01",
|
|
"X-CSRF-TOKEN": token
|
|
}
|
|
});
|
|
});
|
|
|
|
assureResponse(response);
|
|
assert(response.body.data.data != null);
|
|
assert(response.body.code === 200);
|
|
|
|
function processCategoryEntries(categories) {
|
|
for (let category of categories) {
|
|
createItem({
|
|
id: `lcsc:category:${category.id}`,
|
|
tags: [ "lcsc:category" ],
|
|
data: {
|
|
... category,
|
|
pageNumber: 1
|
|
}
|
|
});
|
|
|
|
if (category.subs != null) {
|
|
processCategoryEntries(category.subs);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Listing is a {name: data} mapping of categories
|
|
processCategoryEntries(Object.values(response.body.data.data));
|
|
// for (let category of Object.values(response.body.data.data)) {
|
|
// createItem({
|
|
// id: `lcsc:category:${category.id}`,
|
|
// tags: [ "lcsc:category" ],
|
|
// data: {
|
|
// ... category,
|
|
// pageNumber: 1
|
|
// }
|
|
// });
|
|
// }
|
|
};
|
|
};
|