Skip to content

Instantly share code, notes, and snippets.

@scripting
Last active September 22, 2023 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scripting/bb9efb24b34d71380ba74a99deefd704 to your computer and use it in GitHub Desktop.
Save scripting/bb9efb24b34d71380ba74a99deefd704 to your computer and use it in GitHub Desktop.
test
function testUserDatafiles (ctsecs=0) { //9/19/23 by DW
const fname = "test.json", whenstart = new Date ();
var theTestData = {
theArray: new Array ()
}
for (var i = 1; i <= 15; i++) {
theTestData.theArray.push (getRandomSnarkySlogan ());
}
console.log ("testUserDatafiles");
console.log ("theTestData == " + jsonStringify (theTestData));
uploadUserDataFile (fname, jsonStringify (theTestData), "application/json", true, function (err, data) {
if (err) {
console.log ("testUserDatafiles: err.message == " + err.message);
}
else {
console.log ("testUserDatafiles: data saved without error.");
console.log ("Waiting " + ctsecs + " seconds before checking.");
setTimeout (function () {
console.log (ctsecs + " seconds have elapsed");
getUserDataFile (fname, true, true, function (err, data) {
if (err) {
console.log ("testUserDatafiles: err.message == " + err.message);
}
else {
console.trace ();
console.log ("---");
console.log (new Error().stack);
let savedTestdata, flGoodSave = true;
try {
savedTestdata = JSON.parse (data.filedata);
}
catch (err) {
console.log ("testUserDatafiles: err.message == " + err.message);
}
console.log ("savedTestdata == " + jsonStringify (savedTestdata));
for (var i = 0; i <= 14; i++) {
if (savedTestdata.theArray [i] != theTestData.theArray [i]) {
console.log ("testUserDatafiles: the data doesn't match. i == " + i + ", original data == " + theTestData.theArray [i] + ", what we got back == " + savedTestdata.theArray [i]);
flGoodSave = false;
break;
}
}
if (flGoodSave) {
console.log ("testUserDatafiles: everything checks out.");
}
}
});
}, ctsecs * 1000);
}
});
}
function uploadUserDataFile (relpath, filedata, type, flPrivate, callback) { //replacement for twUploadFile -- 12/23/22 by DW
const whenstart = new Date ();
var params = {
relpath, type
}
if (flPrivate) {
params.flprivate = true;
}
serverpost ("publishfile", params, true, filedata, function (err, data) {
if (!err) {
console.log ("uploadUserDataFile: relpath == " + relpath + ", " + secondsSince (whenstart) + " secs."); //8/20/23 by DW
}
if (callback !== undefined) {
callback (err, data);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment