-
Notifications
You must be signed in to change notification settings - Fork 71
add APIs for getting toolbox items #271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import manifest from '../../manifest.js'; | ||
|
|
||
| /** | ||
| * @brief Get categories list as an array of strings. | ||
| */ | ||
| function getCategories() { | ||
| let categories = []; | ||
|
|
||
| for (let i = 0; i < manifest.length; i++) { | ||
| const entry = manifest[i]; | ||
| categories.push(entry.category); | ||
| } | ||
|
|
||
| return categories; | ||
| } | ||
|
|
||
| export default function handler(req, res) { | ||
| if (req.method !== "GET") { | ||
| res.setHeader("Allow", ["GET"]); | ||
| res.status(405).end(`Method ${req.method} Not Allowed`); | ||
| return; | ||
| } | ||
|
|
||
| res.status(200).json(getCategories()); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import manifest from '../../manifest.js'; | ||
|
|
||
| function getCategoryToItemsMap() { | ||
| let map = {}; | ||
|
|
||
| for (let i = 0; i < manifest.length; i++) { | ||
| const entry = manifest[i]; | ||
| map[entry.category] = entry.items; | ||
| } | ||
|
|
||
| return map; | ||
| } | ||
|
|
||
| export default function handler(req, res) { | ||
| if (req.method !== "GET") { | ||
| res.setHeader("Allow", ["GET"]); | ||
| res.status(405).end(`Method ${req.method} Not Allowed`); | ||
| return; | ||
| } | ||
|
|
||
| let categoryName = req.query.category; | ||
|
|
||
| // // if no category chosen, send all categories | ||
| // if (categoryName === undefined) { | ||
| // res.status(200).json({ categories: manifest }); | ||
| // return; | ||
| // } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider removing it if you don't need it.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i kept it in case anyone wants it later. however if you want to remove it that's okay.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove this before review
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay. i removed it |
||
|
|
||
| const map = getCategoryToItemsMap(); | ||
|
|
||
| if (!map.hasOwnProperty(categoryName)) { | ||
| res.status(400).end(`400 Bad Request\nInvalid category name "${categoryName}".`); | ||
| return; | ||
| } | ||
|
|
||
| const items = map[categoryName]; | ||
| res.status(200).json(items); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.