Skip to content

Commit

Permalink
Better API message decoding for GET and fixes to monksh_component in …
Browse files Browse the repository at this point in the history
…the frontend.
  • Loading branch information
TekMonksGitHub committed Feb 10, 2024
1 parent a08a9ba commit d8d2c9a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
7 changes: 4 additions & 3 deletions backend/server/lib/apiregistry_extensions/urlquerydecoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
* Query data decoder
*/

const querystring = require('querystring');
const utils = require(CONSTANTS.LIBDIR+"/utils.js");

function decodeIncomingData(apiregentry, url, data, headers, _servObject) {
if (!utils.parseBoolean(apiregentry.query.get)) return data; // not query based

headers["content-type"] = "application/json"; // we always convert query to JSON string

const urlParsed = new URL(url);
return JSON.stringify(querystring.parse(urlParsed.search!=""?urlParsed.search.substring(1):""));
const searchParams = new URL(url).searchParams;
const parseIfObject = objToTry => {let ret; try {ret = JSON.parse(objToTry); return ret;} catch(err){return objToTry.toString()}};
const jsonParams = {}; for (const [key, value] of searchParams) jsonParams[key] = parseIfObject(value);
return JSON.stringify(jsonParams);
}

module.exports = {decodeIncomingData}
2 changes: 1 addition & 1 deletion build_number
Original file line number Diff line number Diff line change
@@ -1 +1 @@
778
779
5 changes: 4 additions & 1 deletion frontend/framework/js/monkshu_component.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ function register(name, htmlTemplate, module) {
module.getDataByContainedElement = element => module.getData(module.getHostElementID(element));

module.getHostElementByID = id => id && module.elements && module.elements[id] ? module.elements[id] : module.element;
module.getHostElementByContainedElement = module.getHostElement = element => module.trueWebComponentMode ? element.getRootNode().host : element.closest(name);
module.getHostElementByContainedElement = module.getHostElement = element => {
if (element.tagName.toLowerCase() == name.toLowerCase()) return element; // it is the host already
else return module.trueWebComponentMode ? element.getRootNode().host : element.closest(name);
}
module.getHostElementID = element => module.getHostElement(element).id;

module.getShadowRootByHost = host => module.getShadowRootByHostId(host.id);
Expand Down

0 comments on commit d8d2c9a

Please sign in to comment.