Browse Source

Ugly hack for Markdown not working with unencrypted pastes

tags/v0.6.3.1^0
Kim Grytøyr 2 years ago
parent
commit
cb0b77366f
Signed by: kim <kim@grytoyr.io> GPG Key ID: 759EF8C94E0B45B7
2 changed files with 56 additions and 39 deletions
  1. +1
    -1
      src/lib/config.js
  2. +55
    -38
      src/public/javascripts/syntax.js

+ 1
- 1
src/lib/config.js View File

@@ -3,7 +3,7 @@ const fs = require('fs');
const yaml = require('js-yaml');

const env = process.env.NODE_ENV || 'development';
const VERSION = "v0.6.3";
const VERSION = "v0.6.3.1";

exports.getConfig = () => {
const configFolder = process.env.CONFIG_PATH || '../data/';


+ 55
- 38
src/public/javascripts/syntax.js View File

@@ -102,66 +102,83 @@ ready(() => {
}
if (toggleMarkdownLink) {
toggleMarkdownLink.addEventListener('click', toggleMarkdown);
console.log(parseQueryString());
if (parseQueryString().view === 'markdown') {
toggleMarkdown();
}
}

// Encryption stuff
if (window.location.hash) {
const openpgp = window.openpgp;
openpgp.initWorker({ path:'/javascripts/openpgp.worker.min.js' });

console.log("Decrypting text..");
let passphrase = '';
if (window.vault) {
passphrase = prompt("Enter passphrase for vault '" + window.vault + "':");
}

const data = document.getElementById('paste').innerHTML;
const password = window.location.hash.substr(1).split('#')[0];
const viewAs = window.location.hash.substr(1).split('#')[1];

try {
options = {
message: openpgp.message.readArmored(data),
password: password + passphrase,
};
}
catch (e) {
const errorDiv = document.getElementById('error');
errorDiv.innerHTML = 'Unable to decrypt message. The original content has probably been tampered with.';
errorDiv.style.display = 'block';
document.getElementById('decrypting').style.display = 'none';
return;
}
if (password != '') {
const openpgp = window.openpgp;
openpgp.initWorker({ path:'/javascripts/openpgp.worker.min.js' });

openpgp.decrypt(options).then(function(plaintext) {
const data = decodeURIComponent(escape(window.atob(plaintext.data)));
console.log("Decrypting text..");
let passphrase = '';
if (window.vault) {
passphrase = prompt("Enter passphrase for vault '" + window.vault + "':");
}

try {
options = {
message: openpgp.message.readArmored(data),
password: password + passphrase,
};
}
catch (e) {
const errorDiv = document.getElementById('error');
errorDiv.innerHTML = 'Unable to decrypt message. The original content has probably been tampered with.';
errorDiv.style.display = 'block';
document.getElementById('decrypting').style.display = 'none';
return;
}

openpgp.decrypt(options).then(function(plaintext) {
const data = decodeURIComponent(escape(window.atob(plaintext.data)));
const converter = new showdown.Converter();
converter.setFlavor('github');
document.getElementById('markdown').innerHTML = converter.makeHtml(data);
document.getElementById('paste').innerHTML = data;
const block = document.getElementById('paste');
hljs.highlightBlock(block);
hljs.lineNumbersBlock(block);
block.style.display = 'block';
document.getElementById('decrypting').style.display = 'none';

if (viewAs === 'markdown') {
toggleMarkdown();
}
}).catch(function(error) {
const errorDiv = document.getElementById('error');
errorDiv.innerHTML = 'Unable to decrypt message. You probably have the wrong decryption key or passphrase.';
errorDiv.style.display = 'block';
document.getElementById('decrypting').style.display = 'none';
});
} else {
const block = document.getElementById('paste');
const converter = new showdown.Converter();
converter.setFlavor('github');
document.getElementById('markdown').innerHTML = converter.makeHtml(data);
document.getElementById('paste').innerHTML = data;
const block = document.getElementById('paste');
hljs.highlightBlock(block);
hljs.lineNumbersBlock(block);
block.style.display = 'block';
document.getElementById('decrypting').style.display = 'none';

if (viewAs === 'markdown') {
toggleMarkdown();
}
}).catch(function(error) {
const errorDiv = document.getElementById('error');
errorDiv.innerHTML = 'Unable to decrypt message. You probably have the wrong decryption key or passphrase.';
errorDiv.style.display = 'block';
document.getElementById('decrypting').style.display = 'none';
});
}
} else {
const viewAs = window.location.hash.substr(1).split('#')[1];
const data = document.getElementById('paste').innerHTML;
const block = document.getElementById('paste');
const converter = new showdown.Converter();
converter.setFlavor('github');
document.getElementById('markdown').innerHTML = converter.makeHtml(data);
hljs.highlightBlock(block);
hljs.lineNumbersBlock(block);
block.style.display = 'block';
if (viewAs === 'markdown') {
toggleMarkdown();
}
}
});

Loading…
Cancel
Save