Last active
September 22, 2023 19:10
-
-
Save scripting/bb9efb24b34d71380ba74a99deefd704 to your computer and use it in GitHub Desktop.
test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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