Using HISE to request server issues
-
I use Strapi as my server backend. I have a version field in the product collection type in the backend. I want to request the data from the backend through HISE to implement a check update function, but there is an error I can't solve. Can anyone help me? I will be very grateful!
This is the Console.print of HISE! UpdateChecker.js (47): Found '{' when expecting ';' {SW50ZXJmYWNlfFVwZGF0ZUNoZWNrZXIuanN8MTQ5Nnw0N3wxNA==}
Here is the complete code:
namespace UpdateChecker { const var UpdateButton = Content.getComponent("UpdateButton"); const var localVersion = "1.0.0"; const var apiUrl = "http://localhost:1337/api/products"; const var apiToken = ""; // ================== Version Comparison ================== function compareVersions(latest, current) { var latestParts = latest.split(".").map(function(v) { return parseInt(v); }); var currentParts = current.split(".").map(function(v) { return parseInt(v); }); for (i = 0; i < Math.max(latestParts.length, currentParts.length); i++) { var l = i < latestParts.length ? latestParts[i] : 0; var c = i < currentParts.length ? currentParts[i] : 0; if (l > c) return true; if (l < c) return false; } return false; } // ================== alert ================== function showUpdateAlert(message) { var btn = MessageOverlay.showYesNoWindow("CheckVersion", message); btn.setButtonText("Yes", "Download"); btn.setButtonText("No", "Close"); btn.onResult = function(result) { if (result) Engine.openWebsite("https://your-download-url.com"); }; } // ================== request ================== function requestCallback(request) { if (request.getStatus() == 200) { try { var response = JSON.parse(request.getResponseText()); if (response.data && response.data.length > 0) { var latest = response.data[0].attributes.version; if (compareVersions(latest, localVersion)) { showUpdateAlert("New version found" + latest); } else { showUpdateAlert("Currently the latest version"); } } } catch (e){ Console.print("JSON parsing error:" + e.toString()); } }else{ Console.print("Request failed, status code:" + request.getStatus()); } } // ================== Check update main function ================== function checkUpdate() { var fullUrl = apiUrl + "?sort[0]=version:desc&pagination[pageSize]=1"; var request = new WebRequest(fullUrl); if (apiToken != "") { request.setHeader("Authorization", "Bearer " + apiToken); } request.setRequestType("GET"); request.setContentType("application/json"); request.setCallback(requestCallback); request.performRequest(); } // ================== Button callback ================== inline function onUpdateButtonControl(component, value) { if (value) { Console.print("Starting to check for updates..."); checkUpdate(); } } // ================== initialization ================== UpdateButton.setControlCallback(onUpdateButtonControl); }
-
@CatABC Which is line 47?
-
Is this from ChatGPT?
-
@CatABC this is not HISE code ^^ looks like gpt gibberish
-
@Christoph-Hart Yes, I asked GPT for help
I have no idea how to implement this feature
-
try
-
@CatABC I really have no other choice. I now use webview to create a check update function through HTML+JS.
-
@CatABC said in Using HISE to request server issues:
I have no idea how to implement this feature
Then don't ;)
You don't want to put your server or users at risk.
-
@d-healey
Well, this seems to be a dangerous approach.Thanks for the reminder