Server.callWithGET
-
So I've created a simple function that grabs a version number from a Json on my server, compares it to the plug-in current version, and if it's out of date informs the user there's an update available. However if the file doesn't exist on my server the update message displays anyway - so I need to check it exists first but I'm not sure how Server.callWithGET works for something like this (maybe I need to use a different function...)
Any ideas anyone?!
/// UPDATER const var Update_Panel = Content.getComponent("Update_Panel"); Update_Panel.showControl(0); const var VERSION = Engine.getVersion(); const var VV = { "HVERSION" : "version" }; function VersionCheck() { Server.setBaseURL("https://"); Server.callWithGET("awesomefile.json", VV, function(status, response) { if (response.HVERSION > VERSION) { Update_Panel.showControl(1); } else { Update_Panel.showControl(0); } }); } VersionCheck();
-
@DanH whats in response if the file is missing?
-
@DanH I'm not in front of my computer, but wouldn't it work if you use
if(response != "") // or if(response != undefined)
And then check the version number...?
-
-
@Matt_SF @Lindon not having any joy with those - perhaps I'm using them wrong? Currently the if(response != undefined) executes every time. The response is a 'file does not exist' error generated by the server...
function VersionCheck() { Server.setBaseURL("https://"); Server.callWithGET("coolfile.json", VV, function(status, response) { if(response != undefined) { Console.print("it's not there"); Update_Panel.showControl(0); Console.print(response); } else if (response.HVERSION > VERSION) { Update_Panel.showControl(1); } else { Update_Panel.showControl(0); } }); } VersionCheck();
-
@DanH What response do you return from your server?
-
@d-healey I just get data out of a file...
-
@DanH what if you use the status instead?
If the file doesn't exist you'll get a 404 code...
-
@Matt_SF well another issue is that if the user is not online then the update message also displays... That's an easier check to do though I think
-
Maybe I can just check that the file exists first though before executing any Server commands?
-
@Matt_SF ok so yes I get a 404 code in an html error message - how can I use that? I'm just thinking if my server goes down (which it did the other day) I don't want loads of people thinking there's an update available
-
ok found this in docs... will try!
if(status == Server.StatusOK)
-
@DanH you can check if the user is online with
Server.isOnline
Simply :
if(status == 404) { Console.print("it's not there"); Update_Panel.showControl(0); return; }
Just FYI, I form myself, am using a custom api route (wordpress) which outputs an object like this :
{ 'MajorVersion'=>'1', 'MinorVersion'=>'0', 'Patch'=>'0', 'isActivated'=> false };
The ``ìsActivated``` key allows me to control if I want the update info to be displayed in the plugin or not.
-
@Matt_SF Thanks! Using Server.isOnline currently, and
if(status == Server.StatusOK)
is working well... @Christoph-Hart what is this checking exactly?
-
Server.StatusOK
is just200
which is the official HTTP response code for "everything alright buddy, you're doing great, that's a fabulous request you've made here!"