fix encryption

This commit is contained in:
quenousimporte 2024-02-16 10:51:18 +01:00
parent 717b2a1bce
commit 77ddc4907f
1 changed files with 58 additions and 41 deletions

45
main.js
View File

@ -358,11 +358,7 @@ function pushitem(key, value)
pending[key] = true;
var name = metadata[key] ? metadata[key].title : key;
encryptstring(value)
.then(encrypted =>
{
return queryremote({action: "push", name: key, data: encrypted});
})
queryremote({action: "push", name: key, data: value})
.then( () =>
{
console.log("'" + name + "' pushed to server");
@ -1448,16 +1444,36 @@ function init()
});
}
function encryptdata(params)
{
if (params.data)
{
return encryptstring(params.data)
.then(encrypted =>
{
params.data = encrypted;
return Promise.resolve(params);
});
}
else
{
return Promise.resolve(params);
}
}
function queryremote(params)
{
return new Promise( (apply, failed) => {
params.password = settings.password;
return encryptdata(params)
.then(encparams =>
{
return new Promise ( (resolve, reject) =>
{
encparams.password = settings.password;
var paramlist = [];
for (var i in params)
for (var i in encparams)
{
paramlist.push(i + "=" + encodeURIComponent(params[i]));
paramlist.push(i + "=" + encodeURIComponent(encparams[i]));
}
var xhr = new XMLHttpRequest();
@ -1466,14 +1482,14 @@ function queryremote(params)
xhr.onerror = function()
{
failed("XMLHttpRequest error");
return reject("XMLHttpRequest error");
}
xhr.onload = function()
{
if (xhr.status !== 200)
{
failed("Http status " + xhr.status);
return reject("Http status " + xhr.status);
}
else
{
@ -1482,11 +1498,11 @@ function queryremote(params)
{
if (decrypted.startsWith("error: "))
{
failed(decrypted);
return reject(decrypted);
}
else
{
apply(decrypted);
return resolve(decrypted);
}
});
}
@ -1496,6 +1512,7 @@ function queryremote(params)
console.log("http request length: " + formatsize(paramstring.length));
xhr.send(paramstring);
});
});
}
function getlinesrange()