New API: Server and FileSystem
-
@d-healey Actually I was just checking whether there are any merge conflicts, but I need to get the CLAs from all contributors before I can merge your branch. The real task will be merging the new SNEX code...
@ustk sure, I‘ll add it. I‘m a bit hesitant with the delete method because it‘s not undoable...
-
@Christoph-Hart said in New API: Server and FileSystem:
I need to get the CLAs from all contributors before I can merge your branch.
Just me, @ustk, and @Levitanus I think.
-
@Christoph-Hart I tested the server with no success...
This:
// Prepare the parameters local parameters = { "request": requestType, "email": emailLbl.get("text"), "serial_key": serialLbl.get("text"), "product_id": productId, "instance": instance }; // Make the call Server.callWithGET(SerialNumbersAPI, parameters, function(status, response) // SerialNumbersAPI is my sub... { Console.print(status); Console.print(trace(response)); });
Throws that
Interface:! Expected '{' or '[': "1" Interface: 500 Interface: { "error": "Expected '{' or '[': \"1\"" }
It shouldn't be because of the baseURL, subURL, or parameters because it worked before with my API...
-
Do you return a plain text? Because it expects JSON data
-
@Christoph-Hart What do you mean? the response is an object:
Server.callWithGET(SerialNumbersAPI, parameters, function(status, response) { Console.print(status); Console.print(response); });
Interface:! Expected '{' or '[': "1" Interface: 500 Interface: Object 0x423cc0
-
And:
Server.callWithGET(SerialNumbersAPI, parameters, function(status, response) { });
gives
Interface:! Expected '{' or '[': "1"
-
Well the error message is wrapped in an object, but your actual server response throws a JSON parsing error.
-
@Christoph-Hart Which means?
Are the parameters not good? it all strings -
@Christoph-Hart
Here's my habitual call
https://www.studio427audio.com/?wc-api=serial-numbers-api&request=check&...here's what I set
Server.setBaseURL("https://www.studio427audio.com"); const var SerialNumbersAPI = "?wc-api=serial-numbers-api"; // subURL
-
That's not the sub-URL these are the GET arguments. Your sub URL is empty if you call the domain directly (haven't checked whether this works though, in my experience I've always called a sub URL). The parameter object should be
const var p = { "wc-api": "serial-numbers-api", "request": "check" }; Server.setBaseURL("https://www.studio427audio.com"); Server.callWithGET("/", p, function(status, response) { });
But what does the server return? If it's just a plain old text, it won't work so you need to make sure your server returns a JSON file.
-
@Christoph-Hart I noticed in your example, the call adds a question mark at the end of the subURL.
I don't know if it's added or not to my url, but I know I shouldn't have one... -
@Christoph-Hart I see! testing...
-
This works here:
Content.makeFrontInterface(600, 500); const var p = { "wc-api": "serial-numbers-api", "request": "check" }; reg r; Server.setBaseURL("https://www.studio427audio.com"); Server.callWithGET("/", p, function(status, response) { r = response; });
If you check
r
in the script watch table, it contains -
@Christoph-Hart Yeah! Working! :)
I didn't know the api is par of GET arguments, though it was the sub...
It works like a charm! Thanks! -
Yes, the GET arguments will be embedded into the URL and POST data will be sent along with it. If your server supports it I'd recommend using POST data for sending authentification information as the other one is visible throughout the communication (which makes your SSL certificate pointless).
-
@Christoph-Hart Yes that's what I intended to do once the most simple part works :)
-
FYI, I just added the
deleteFileOrDirectory()
function... -
This is awesome! Have been waiting for these features. Bravo!!
-
@Christoph-Hart Did someone tinkered with the File APIs?
I tried getFolder and findFiles with no success.
I put a *.js on the Desktop and used the location wildcard but findFiles returns an empty array...FileSystem.getFolder("Desktop"); var fileList = FileSystem.findFiles("Desktop", "*.js", true)
My end goal is to dump an encrypted file (but I don't see a dump file method except for the ol'dumpJSON of course)
-
Use
FileSystem.Desktop
as argument.And your end goal is one line of code :)
FileSystem.getFolder(FileSystem.Desktop).getChildFile("license.dat").writeEncryptedObject({"key": "1234"}, "1haDUHNEK1($NR");