fixing server interaction in JS, simple pastes now work

This commit is contained in:
El RIDO 2019-05-11 10:39:42 +02:00
parent 5b3286df4d
commit 788ea67b49
No known key found for this signature in database
GPG key ID: 0F5C940A6BD81F92
3 changed files with 20 additions and 11 deletions

View file

@ -3710,11 +3710,10 @@ jQuery.PrivateBin = (function($, RawDeflate) {
*/
me.run = function()
{
$.ajax({
type: data ? 'POST' : 'GET',
let isPost = Object.keys(data).length > 0,
ajaxParams = {
type: isPost ? 'POST' : 'GET',
url: url,
data: data,
dataType: 'json',
headers: ajaxHeaders,
success: function(result) {
if (result.status === 0) {
@ -3725,8 +3724,17 @@ jQuery.PrivateBin = (function($, RawDeflate) {
fail(2, result);
}
}
})
.fail(function(jqXHR, textStatus, errorThrown) {
};
if (isPost) {
ajaxParams.data = data;
['adata', 'meta'].map(function (key) {
if (data.hasOwnProperty(key)) {
ajaxParams.data[key] = JSON.stringify(data[key]);
}
});
ajaxParams.dataType = 'json';
}
$.ajax(ajaxParams).fail(function(jqXHR, textStatus, errorThrown) {
console.error(textStatus, errorThrown);
fail(3, jqXHR);
});
@ -4186,7 +4194,7 @@ jQuery.PrivateBin = (function($, RawDeflate) {
{
const pastePlain = await decryptOrPromptPassword(
key, password,
paste.hasOwnProperty('ct') ? paste.ct : paste.data
paste.hasOwnProperty('ct') ? [paste.ct, paste.adata] : paste.data
);
if (pastePlain === false) {
if (password.length === 0) {
@ -4347,6 +4355,7 @@ jQuery.PrivateBin = (function($, RawDeflate) {
.catch((err) => {
// wait for the user to type in the password,
// then PasteDecrypter.run will be called again
console.log(decryptionPromises);
});
};