Local storage support
This commit is contained in:
1 parent
64a60e07ef
commit
00b5a1c785
2 files changed
+18
-18
No files matched your search
+6
-12
@@ -136,34 +136,28 @@ function loadAdvancedAlgosPlatform() {
|
||||
}
|
||||
|
||||
function callServer(pContentToSend, pPath, callBackFunction) {
|
||||
|
||||
let xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function () {
|
||||
if (this.readyState === 4 && this.status === 200) {
|
||||
|
||||
callBackFunction(xhttp.responseText);
|
||||
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, xhttp.responseText);
|
||||
return;
|
||||
} else if (this.readyState === 4 && this.status === 404) {
|
||||
callBackFunction({ result: "Fail", message: xhttp.responseText.trim(), code: xhttp.responseText.trim() });
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if (pContentToSend === undefined) {
|
||||
|
||||
xhttp.open("GET", pPath, true);
|
||||
xhttp.send();
|
||||
|
||||
} else {
|
||||
|
||||
try {
|
||||
|
||||
let blob = new Blob([pContentToSend], { type: 'text/plain' });
|
||||
|
||||
xhttp.open("POST", pPath, true);
|
||||
xhttp.send(blob);
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[ERROR] callServer -> err.message = " & err.message); }
|
||||
|
||||
callBackFunction({ result: "Fail", message: err.message })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -266,6 +266,11 @@ function onBrowserRequest(request, response) {
|
||||
}
|
||||
break
|
||||
|
||||
case 'Storage':
|
||||
{
|
||||
respondWithFile(process.env.STORAGE_PATH + '/' + request.url.substring(9), response)
|
||||
}
|
||||
break
|
||||
default:
|
||||
{
|
||||
homePage()
|
||||
@@ -339,18 +344,19 @@ function respondWithFile(fileName, response) {
|
||||
if (CONSOLE_LOG === true) { console.log('[INFO] server -> respondWithFile -> onFileRead -> Entering function.') }
|
||||
|
||||
try {
|
||||
let htmlResponse = file.toString()
|
||||
|
||||
response.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate') // HTTP 1.1.
|
||||
response.setHeader('Pragma', 'no-cache') // HTTP 1.0.
|
||||
response.setHeader('Expires', '0') // Proxies.
|
||||
response.setHeader('Access-Control-Allow-Origin', '*') // Allows to access data from other domains.
|
||||
|
||||
// response.writeHead(200, { 'Content-Type': 'text/html' });
|
||||
response.write(htmlResponse)
|
||||
if (!err) {
|
||||
// response.writeHead(200, { 'Content-Type': 'text/html' });
|
||||
response.write(file.toString())
|
||||
} else {
|
||||
response.writeHead(404, { 'Content-Type': 'text/html' });
|
||||
response.write('The specified key does not exist.')
|
||||
}
|
||||
response.end('\n')
|
||||
// console.log("File Sent: " + fileName);
|
||||
//
|
||||
} catch (err) {
|
||||
console.log('[ERROR] server -> respondWithFile -> onFileRead -> File Not Found: ' + fileName + ' or Error = ' + err.stack)
|
||||
returnEmptyArray()
|
||||
|
||||
Reference in new issue
Block a user