Merge branch 'v2' of github.com:Tygs/0bin into v2

This commit is contained in:
papee 2020-08-15 12:50:22 +02:00
commit 0c18aae662
5 changed files with 135 additions and 79 deletions

View File

@ -20,7 +20,7 @@ MENU = (
# Size limit of the paste content in bytes. Be careful, allowing a size too big can
# slow down the user's browser
MAX_SIZE = 1024 * 500
MAX_SIZE = 1024 * 600
# Display a tiny counter for pastes created.
DISPLAY_COUNTER = True
@ -31,6 +31,3 @@ REFRESH_COUNTER = 60 # in seconds
# total number of unique pastes can be calculated as 2^(6*PASTE_ID_LENGTH)
# for PASTE_ID_LENGTH=8, for example, it's 2^(6*8) = 281 474 976 710 656
PASTE_ID_LENGTH = 8
# The Bitcoin address displayed in the paste if the author didn't chose one
DEFAULT_BTC_TIP_ADDRESS = "bc1q4x6nwp56s9enmwtsa8um0gywpxdzeyrdluga04"

File diff suppressed because one or more lines are too long

View File

@ -226,6 +226,45 @@ var app = new Vue({
},
compressImage: function (base64) {
var canvas = document.createElement('canvas')
var img = document.createElement('img')
return new Promise(function (resolve, reject) {
img.onload = function () {
var width = img.width;
var height = img.height;
var biggest = width > height ? width : height;
var maxHeight = height;
var maxWidth = width;
if (width > height) {
if (width > maxWidth) {
height = Math.round((height *= maxWidth / width));
width = maxWidth;
}
} else {
if (height > maxHeight) {
width = Math.round((width *= maxHeight / height));
height = maxHeight;
}
}
canvas.width = width;
canvas.height = height;
var ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0, width, height);
resolve(canvas.toDataURL('image/jpeg', 0.7));
}
img.onerror = function (err) {
reject(err);
}
img.src = base64;
})
},
/**
On the create paste page:
On click on the send button, compress and encrypt data before
@ -258,88 +297,108 @@ var app = new Vue({
var key = zerobin.makeKey(256);
zerobin.encrypt(key, paste,
var promise = new Promise(function (resolve, reject) {
resolve(paste);
}); // noop to avoid branching
if (paste.indexOf('data:image') == 0) {
promise = app.compressImage(paste);
}
function () {
bar.set('Encoding to base64...', '45%')
},
function () {
bar.set('Compressing...', '65%')
},
function () {
bar.set('Encrypting...', '85%')
},
promise.then(function (base64) {
zerobin.encrypt(key, base64,
/* This block deals with sending the data, redirection or error handling */
function (content) {
function () {
bar.set('Encoding to base64...', '45%')
},
function () {
bar.set('Compressing...', '65%')
},
function () {
bar.set('Encrypting...', '85%')
},
bar.set('Sending...', '95%');
var data = {
content: content,
expiration: app.newPaste.expiration,
title: app.newPaste.title,
btcTipAddress: app.newPaste.btcTipAddress
};
var sizebytes = zerobin.count(JSON.stringify(data));
var oversized = sizebytes > zerobin.max_size; // 100kb - the others header information
var readableFsize = Math.round(sizebytes / 1024);
var readableMaxsize = Math.round(zerobin.max_size / 1024);
/* This block deals with sending the data, redirection or error handling */
function (content) {
if (oversized) {
app.isLoading = false
form.forEach(function (node) {
node.disabled = false;
});
zerobin.message('danger', ('The encrypted file was <strong class="file-size">' + readableFsize +
'</strong>KB. You have reached the maximum size limit of ' + readableMaxsize + 'KB.'),
'Warning!', true);
return;
}
bar.set('Sending...', '95%');
var data = {
content: content,
expiration: app.newPaste.expiration,
title: app.newPaste.title,
btcTipAddress: app.newPaste.btcTipAddress
};
var sizebytes = zerobin.count(JSON.stringify(data));
var oversized = sizebytes > zerobin.max_size; // 100kb - the others header information
var readableFsize = Math.round(sizebytes / 1024);
var readableMaxsize = Math.round(zerobin.max_size / 1024);
fetch('/paste/create', {
method: "POST",
body: new URLSearchParams(data)
}).then(function (response) {
if (response.ok) {
bar.set('Redirecting to new paste...', '100%');
if (oversized) {
app.isLoading = false
form.forEach(function (node) {
node.disabled = false;
});
response.json().then(function (data) {
if (data.status === 'error') {
zerobin.message('danger', data.message, 'Error');
zerobin.message('danger', ('The file was <strong class="file-size">' + readableFsize +
'</strong>KB after encryption. You have reached the maximum size limit of ' + readableMaxsize + 'KB.'),
'Warning!', true);
return;
}
fetch('/paste/create', {
method: "POST",
body: new URLSearchParams(data)
}).then(function (response) {
if (response.ok) {
bar.set('Redirecting to new paste...', '100%');
response.json().then(function (data) {
if (data.status === 'error') {
zerobin.message('danger', data.message, 'Error');
form.forEach(function (node) {
node.disabled = false;
});
app.isLoading = false;
} else {
if (app.support.localStorage) {
zerobin.storePaste('/paste/' + data.paste + "?owner_key=" + data.owner_key + '#' + key);
}
window.location = ('/paste/' + data.paste + '#' + key);
}
})
} else {
form.forEach(function (node) {
node.disabled = false;
node.disabled = false
});
app.isLoading = false;
} else {
if (app.support.localStorage) {
zerobin.storePaste('/paste/' + data.paste + "?owner_key=" + data.owner_key + '#' + key);
}
window.location = ('/paste/' + data.paste + '#' + key);
zerobin.message(
'danger',
'Paste could not be saved. Please try again later.',
'Error');
}
})
} else {
form.forEach(function (node) {
node.disabled = false
}).catch(function (error) {
form.forEach(function (node) {
node.disabled = false;
});
app.isLoading = false;
zerobin.message(
'danger',
'Paste could not be saved. Please try again later.',
'Error');
});
app.isLoading = false;
zerobin.message(
'danger',
'Paste could not be saved. Please try again later.',
'Error');
}
}).catch(function (error) {
form.forEach(function (node) {
node.disabled = false;
});
app.isLoading = false;
zerobin.message(
'danger',
'Paste could not be saved. Please try again later.',
'Error');
});
});
})
}),
function (err) {
debugger;
form.forEach(function (node) {
node.disabled = false;
});
app.isLoading = false;
zerobin.message('danger', 'Paste could not be encrypted. Aborting.',
'Error');
};
} catch (err) {
form.forEach(function (node) {
node.disabled = false;
@ -878,7 +937,7 @@ if (content && key) {
"The paste did not seem to be code, so it " +
"was not colorized. ",
'', false, undefined, {
message: "Force coloration",
message: "Click here to force coloration",
callback: app.handleForceColoration
});
}

File diff suppressed because one or more lines are too long

View File

@ -99,8 +99,8 @@
d="M12 2c5.514 0 10 4.486 10 10s-4.486 10-10 10-10-4.486-10-10 4.486-10 10-10zm0-2c-6.627 0-12 5.373-12 12s5.373 12 12 12 12-5.373 12-12-5.373-12-12-12zm0 18v-1.511h-.5v1.511h-1v-1.511h-2.484l.25-1.489h.539c.442 0 .695-.425.695-.854v-4.444c0-.416-.242-.702-.683-.702h-.817v-1.5h2.5v-1.5h1v1.5h.5v-1.5h1v1.526c2.158.073 3.012.891 3.257 1.812.29 1.09-.429 2.005-1.046 2.228.75.192 1.789.746 1.789 2.026 0 1.742-1.344 2.908-4 2.908v1.5h-1zm-.5-5.503v2.503c1.984 0 3.344-.188 3.344-1.258 0-1.148-1.469-1.245-3.344-1.245zm0-.997c1.105 0 2.789-.078 2.789-1.25 0-1-1.039-1.25-2.789-1.25v2.5z"
fill="#eee" /></svg></span>
<a class="btn btn-primary btc-tip-address"
href="bitcoin:{{ paste.btc_tip_address or settings.DEFAULT_BTC_TIP_ADDRESS }}">
{{ paste.btc_tip_address or settings.DEFAULT_BTC_TIP_ADDRESS}}
href="bitcoin:{{ paste.btc_tip_address or 'bc1q4x6nwp56s9enmwtsa8um0gywpxdzeyrdluga04' }}">
{{ paste.btc_tip_address or 'bc1q4x6nwp56s9enmwtsa8um0gywpxdzeyrdluga04'}}
</a>
<button v-if="support.clipboard" class="btn btn-secondary" @click.prevent="copyBTCAdressToClipboard()">
{% this.btcCopied ? "copied :)" : "copy" %}