starting of widget refactoring

This commit is contained in:
Ben Phelps 2022-09-25 19:43:47 +03:00
parent d6f6ea9dba
commit 562235f828
42 changed files with 337 additions and 301 deletions

View file

@ -1,5 +1,6 @@
import getServiceWidget from "utils/service-helpers";
import { formatApiCall } from "utils/api-helpers";
import widgets from "widgets/widgets";
export default async function npmProxyHandler(req, res) {
const { group, service, endpoint } = req.query;
@ -7,8 +8,12 @@ export default async function npmProxyHandler(req, res) {
if (group && service) {
const widget = await getServiceWidget(group, service);
if (!widgets?.[widget.type]?.api) {
return res.status(403).json({ error: "Service does not support API calls" });
}
if (widget) {
const url = new URL(formatApiCall(widget.type, { endpoint, ...widget }));
const url = new URL(formatApiCall(widgets[widget.type].api, { endpoint, ...widget }));
const loginUrl = `${widget.url}/api/tokens`;
const body = { identity: widget.username, secret: widget.password };