lots of fixes, added upload count
This commit is contained in:
parent
f0392ee517
commit
b6ff035131
@ -90,6 +90,7 @@
|
|||||||
<div class="control">
|
<div class="control">
|
||||||
<a class="button is-primary" id="createMessageBtn">Create Post</a>
|
<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 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>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
@ -141,7 +141,7 @@ async function findMessages(){
|
|||||||
setTimeout(function(){findMessages()}, findMessageIntervalTime)
|
setTimeout(function(){findMessages()}, findMessageIntervalTime)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lastLookup = Math.floor((Date.now() / 1000)) - (findMessageIntervalTime / 1000) - 600
|
lastLookup = Math.floor((Date.now() / 1000)) - (findMessageIntervalTime / 1000) - 1200
|
||||||
messages.forEach(block => {
|
messages.forEach(block => {
|
||||||
if (!block) { return}
|
if (!block) { return}
|
||||||
block = reconstructHash(block)
|
block = reconstructHash(block)
|
||||||
@ -155,6 +155,9 @@ async function findMessages(){
|
|||||||
document.getElementById('memUsage').innerText = getReadableFileSizeString(current + ((basicTextEncoder.encode(data)).length + block.length))
|
document.getElementById('memUsage').innerText = getReadableFileSizeString(current + ((basicTextEncoder.encode(data)).length + block.length))
|
||||||
}
|
}
|
||||||
try{
|
try{
|
||||||
|
if (typeof d === "undefined"){
|
||||||
|
return
|
||||||
|
}
|
||||||
var metadata = JSON.parse(d.split("\n")[0])
|
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
|
// 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){
|
if (JSON.parse(metadata['meta'])['type'] !== postTopic){
|
||||||
|
@ -42,6 +42,7 @@ document.getElementById("createMessageBtn").onclick = async function(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function doUpload(data){
|
async function doUpload(data){
|
||||||
|
document.getElementById("uploadingCount").parentNode.classList.remove('is-hidden')
|
||||||
if (! publicNodes.length){
|
if (! publicNodes.length){
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
doUpload(data)
|
doUpload(data)
|
||||||
@ -70,6 +71,12 @@ async function doUpload(data){
|
|||||||
})
|
})
|
||||||
clearTimeout(uploadTimeout)
|
clearTimeout(uploadTimeout)
|
||||||
if (upload.ok){
|
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
|
return
|
||||||
}
|
}
|
||||||
doUpload(data)
|
doUpload(data)
|
||||||
@ -81,5 +88,6 @@ powWorker.addEventListener('message', function(e) {
|
|||||||
document.getElementById("creatingMessage").classList.add("is-hidden")
|
document.getElementById("creatingMessage").classList.add("is-hidden")
|
||||||
}
|
}
|
||||||
console.debug("Generated block: " + doHashHex(e.data))
|
console.debug("Generated block: " + doHashHex(e.data))
|
||||||
|
document.getElementById("uploadingCount").innerText = parseInt(document.getElementById("uploadingCount").innerText) + 1
|
||||||
doUpload(e.data)
|
doUpload(e.data)
|
||||||
}, false)
|
}, false)
|
||||||
|
@ -23,9 +23,16 @@ function reconstructHash(hash){
|
|||||||
function verifyBlock(raw, hash){
|
function verifyBlock(raw, hash){
|
||||||
var encoder = new TextEncoder("utf-8")
|
var encoder = new TextEncoder("utf-8")
|
||||||
hash = reconstructHash(hash)
|
hash = reconstructHash(hash)
|
||||||
|
const blockSize = encoder.encode(raw).length;
|
||||||
if (doHashHex(encoder.encode(raw)) != hash){
|
if (doHashHex(encoder.encode(raw)) != hash){
|
||||||
throw new Error("Hash does not match")
|
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){
|
function verifyTime(time){
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
let torDetect = function(){
|
let torDetect = function(){
|
||||||
|
if (document.location.origin.endsWith('.onion')){
|
||||||
|
return
|
||||||
|
}
|
||||||
let el = document.createElement('img')
|
let el = document.createElement('img')
|
||||||
el.onerror = function(){
|
el.onerror = function(){
|
||||||
document.getElementsByClassName('noTor')[0].classList.remove('is-hidden')
|
document.getElementsByClassName('noTor')[0].classList.remove('is-hidden')
|
||||||
|
Loading…
Reference in New Issue
Block a user