Browse Source

lots of fixes, added upload count

master
Kevin Froman 2 years ago
parent
commit
b6ff035131
  1. 1
      index.html
  2. 5
      js/hush-hush.js
  3. 8
      js/message-creator.js
  4. 7
      js/onionr-blocks.js
  5. 3
      js/tordetect.js

1
index.html

@ -90,6 +90,7 @@
<div class="control">
<a class="button is-primary" id="createMessageBtn">Create Post</a>
<span id="creatingMessage" class="is-hidden"><span id="creatingCount">0</span> post(s) generating</span>
<span class="is-hidden"> - <span id="uploadingCount">0</span> post(s) uploading </span>
</div>
</div>
</section>

5
js/hush-hush.js

@ -141,7 +141,7 @@ async function findMessages(){
setTimeout(function(){findMessages()}, findMessageIntervalTime)
return
}
lastLookup = Math.floor((Date.now() / 1000)) - (findMessageIntervalTime / 1000) - 600
lastLookup = Math.floor((Date.now() / 1000)) - (findMessageIntervalTime / 1000) - 1200
messages.forEach(block => {
if (!block) { return}
block = reconstructHash(block)
@ -155,6 +155,9 @@ async function findMessages(){
document.getElementById('memUsage').innerText = getReadableFileSizeString(current + ((basicTextEncoder.encode(data)).length + block.length))
}
try{
if (typeof d === "undefined"){
return
}
var metadata = JSON.parse(d.split("\n")[0])
// Make sure the block is an actual post so nodes can't send us stuff unrelated to dapp
if (JSON.parse(metadata['meta'])['type'] !== postTopic){

8
js/message-creator.js

@ -42,6 +42,7 @@ document.getElementById("createMessageBtn").onclick = async function(){
}
async function doUpload(data){
document.getElementById("uploadingCount").parentNode.classList.remove('is-hidden')
if (! publicNodes.length){
setTimeout(function(){
doUpload(data)
@ -70,6 +71,12 @@ async function doUpload(data){
})
clearTimeout(uploadTimeout)
if (upload.ok){
let cur = parseInt(document.getElementById("uploadingCount").innerText)
document.getElementById("uploadingCount").innerText = parseInt(document.getElementById("uploadingCount").innerText) - 1
if (cur - 1 <= 0){
document.getElementById("uploadingCount").parentNode.classList.add('is-hidden')
}
return
}
doUpload(data)
@ -81,5 +88,6 @@ powWorker.addEventListener('message', function(e) {
document.getElementById("creatingMessage").classList.add("is-hidden")
}
console.debug("Generated block: " + doHashHex(e.data))
document.getElementById("uploadingCount").innerText = parseInt(document.getElementById("uploadingCount").innerText) + 1
doUpload(e.data)
}, false)

7
js/onionr-blocks.js

@ -23,9 +23,16 @@ function reconstructHash(hash){
function verifyBlock(raw, hash){
var encoder = new TextEncoder("utf-8")
hash = reconstructHash(hash)
const blockSize = encoder.encode(raw).length;
if (doHashHex(encoder.encode(raw)) != hash){
throw new Error("Hash does not match")
}
if (blockSize > 10000){
throw new Error("Block is too large")
}
else if(blockSize < 10){
throw new Error("Block size is too small")
}
}
function verifyTime(time){

3
js/tordetect.js

@ -1,4 +1,7 @@
let torDetect = function(){
if (document.location.origin.endsWith('.onion')){
return
}
let el = document.createElement('img')
el.onerror = function(){
document.getElementsByClassName('noTor')[0].classList.remove('is-hidden')

Loading…
Cancel
Save