HISE Logo Forum
    • Categories
    • Register
    • Login

    Using HISE to request server issues

    Scheduled Pinned Locked Moved General Questions
    9 Posts 4 Posters 126 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • CatABCC
      CatABC
      last edited by

      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);
      }
      

      //I am a new student at HISE._
      //Windows11 & MacOS Ventura 13.6.7_

      d.healeyD oskarshO 2 Replies Last reply Reply Quote 0
      • d.healeyD
        d.healey @CatABC
        last edited by

        @CatABC Which is line 47?

        Libre Wave - Freedom respecting instruments and effects
        My Patreon - HISE tutorials
        YouTube Channel - Public HISE tutorials

        Christoph HartC CatABCC 2 Replies Last reply Reply Quote 0
        • Christoph HartC
          Christoph Hart @d.healey
          last edited by

          Is this from ChatGPT?

          CatABCC 1 Reply Last reply Reply Quote 0
          • oskarshO
            oskarsh @CatABC
            last edited by

            @CatABC this is not HISE code ^^ looks like gpt gibberish

            1 Reply Last reply Reply Quote 0
            • CatABCC
              CatABC @Christoph Hart
              last edited by

              @Christoph-Hart Yes, I asked GPT for help😌 I have no idea how to implement this feature

              //I am a new student at HISE._
              //Windows11 & MacOS Ventura 13.6.7_

              d.healeyD 1 Reply Last reply Reply Quote 0
              • CatABCC
                CatABC @d.healey
                last edited by

                @d-healey

                try
                

                //I am a new student at HISE._
                //Windows11 & MacOS Ventura 13.6.7_

                CatABCC 1 Reply Last reply Reply Quote 0
                • CatABCC
                  CatABC @CatABC
                  last edited by

                  @CatABC I really have no other choice. I now use webview to create a check update function through HTML+JS.😲

                  //I am a new student at HISE._
                  //Windows11 & MacOS Ventura 13.6.7_

                  1 Reply Last reply Reply Quote 0
                  • d.healeyD
                    d.healey @CatABC
                    last edited by

                    @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.

                    Libre Wave - Freedom respecting instruments and effects
                    My Patreon - HISE tutorials
                    YouTube Channel - Public HISE tutorials

                    CatABCC 1 Reply Last reply Reply Quote 0
                    • CatABCC
                      CatABC @d.healey
                      last edited by

                      @d-healey 😮 Well, this seems to be a dangerous approach.Thanks for the reminder

                      //I am a new student at HISE._
                      //Windows11 & MacOS Ventura 13.6.7_

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post

                      34

                      Online

                      1.7k

                      Users

                      11.8k

                      Topics

                      102.7k

                      Posts