Correct pathing
This commit is contained in:
@@ -161,7 +161,7 @@ export default class HTTPInterfaceServer extends AbstractInterfaceServer<Config>
|
||||
|
||||
// Main function
|
||||
this.app.use("/aas/submodels/:smId/submodel-elements/*", (req, res) => {
|
||||
const idShortPathString = (req.params as any)[0];
|
||||
const idShortPathString = (req.params as any)[0] as string;
|
||||
if (idShortPathString.endsWith("/")) res.status(400).end();
|
||||
|
||||
const sm = getSM(req.params.smId);
|
||||
@@ -185,18 +185,20 @@ export default class HTTPInterfaceServer extends AbstractInterfaceServer<Config>
|
||||
const endingMatch = endingMatchSearch?.[0];
|
||||
|
||||
const idShortPath = endingMatch ? idShortPathString.replace(new RegExp(`${endingMatch}$`), "").split("/") : idShortPathString.split("/");
|
||||
// We test both options of path, the correct one (map.entry.list[0].property) and the BaSyx one (map/entry/list/listElement/property)
|
||||
const elem = idShortPath.length <= 1 ? Traverser.getElementByPath(this.aas, sm, idShortPath[0]) : Traverser.getElementByIdPath(this.aas, sm, idShortPath);
|
||||
|
||||
switch (endingMatch) {
|
||||
case undefined: {
|
||||
if (req.method !== "GET") return res.status(501).end();
|
||||
const prop = Traverser.getElementByIdPath(this.aas, sm, idShortPath);
|
||||
const prop = elem;
|
||||
if (prop === null || !AASCoreTypes.isProperty(prop)) return res.status(404).end();
|
||||
|
||||
return res.json(AASCoreJsonization.toJsonable(prop)).end();
|
||||
}
|
||||
case "/value":
|
||||
case "/value": {
|
||||
if (req.method !== "GET" && req.method !== "PUT") return res.status(501).end();
|
||||
const prop = Traverser.getElementByIdPath(this.aas, sm, idShortPath);
|
||||
const prop = elem;
|
||||
if (prop === null || !AASCoreTypes.isProperty(prop)) return res.status(404).end();
|
||||
|
||||
const request: Types.RequestTypes.Request = req.method === "GET" ? { type: "readProperty", target: prop } : { type: "writeProperty", target: prop, extraData: { value: req.body } };
|
||||
@@ -207,11 +209,12 @@ export default class HTTPInterfaceServer extends AbstractInterfaceServer<Config>
|
||||
|
||||
if (value === null) return res.status(500).end();
|
||||
return res.json(value).end();
|
||||
}
|
||||
case "/attachment":
|
||||
return res.status(501).end();
|
||||
case "/invoke": {
|
||||
if (req.method !== "POST") return res.status(405).end();
|
||||
const op = Traverser.getElementByIdPath(this.aas, sm, idShortPath);
|
||||
const op = elem;
|
||||
if (op === null || !AASCoreTypes.isOperation(op)) return res.status(404).end();
|
||||
|
||||
try {
|
||||
@@ -223,7 +226,7 @@ export default class HTTPInterfaceServer extends AbstractInterfaceServer<Config>
|
||||
}
|
||||
case "/invoke-async": {
|
||||
if (req.method !== "POST") return res.status(405).end();
|
||||
const op = Traverser.getElementByIdPath(this.aas, sm, idShortPath);
|
||||
const op = elem;
|
||||
if (op === null || !AASCoreTypes.isOperation(op)) return res.status(404).end();
|
||||
|
||||
const request: Types.RequestTypes.Request = { type: "invokeAction", target: op, extraData: { args: req.body, async: true } };
|
||||
|
||||
@@ -189,7 +189,7 @@ export default class MQTTConnector extends AbstractConnectionObject<mqtt.IClient
|
||||
public callActionSync(_target: AASCoreTypes.Operation, mapping: Types.RequestTypes.ConnectionConfiguration, args: Record<string, any>): any {
|
||||
this.assertConnected();
|
||||
|
||||
const form: Types.AIDTypes.InterfaceFormMQTTAction = mapping.forms[0];
|
||||
const form: Types.AIDTypes.InterfaceFormMQTTAction = mapping.forms[0] as Types.AIDTypes.InterfaceFormMQTTAction;
|
||||
const topic = MQTTConnector.getTopicFromForm(form);
|
||||
if (topic === undefined || !mapping.forms) throw new Error("Mapping invalid.");
|
||||
|
||||
@@ -215,7 +215,7 @@ export default class MQTTConnector extends AbstractConnectionObject<mqtt.IClient
|
||||
public callActionAsync(_target: AASCoreTypes.Operation, mapping: Types.RequestTypes.ConnectionConfiguration, args: Record<string, any>): string {
|
||||
this.assertConnected();
|
||||
|
||||
const form: Types.AIDTypes.InterfaceFormMQTTAction = mapping.forms[0];
|
||||
const form: Types.AIDTypes.InterfaceFormMQTTAction = mapping.forms[0] as Types.AIDTypes.InterfaceFormMQTTAction;
|
||||
const topic = MQTTConnector.getTopicFromForm(form);
|
||||
if (topic === undefined || !mapping.forms) throw new Error("Mapping invalid.");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user