work on making mail more efficient, added --private-ke argument imp to run script

master
Kevin Froman 2020-09-19 08:25:10 +00:00
parent 646a7c0b80
commit 3199f93d4b
4 changed files with 43 additions and 4 deletions

View File

@ -75,7 +75,7 @@ parser.add_argument(
type=int, default=1)
parser.add_argument(
'--private-key', help='Use existing private key',
type=int, default=1)
type=str, default=0)
parser.add_argument(
'--animated-background', help='Animated background on webui index. Just for looks.',
type=int, default=0)
@ -86,14 +86,22 @@ args = parser.parse_args()
p = Popen([sub_script, 'version'], stdout=DEVNULL)
p.wait()
from filepaths import config_file
from filepaths import config_file, keys_file
from coredb import blockmetadb
import onionrcrypto
with open(config_file, 'r') as cf:
config = ujson.loads(cf.read())
if args.private_key:
priv = args.private_key
pub = onionrcrypto.cryptoutils.get_pub_key_from_priv(priv)
with open(keys_file, "a") as f:
f.write(',' + pub.decode() + ',' + priv)
config['general']['public_key'] = pub
if not args.onboarding:
config['onboarding']['done'] = True
if not args.random_localhost_ip:
@ -110,7 +118,7 @@ config['general']['display_header'] = False
config['general']['security_level'] = args.security_level
with open(config_file, 'w') as cf:
cf.write(ujson.dumps(config))
cf.write(ujson.dumps(config, reject_bytes=False))
if args.open_ui:
p = Popen([sub_script, 'start'], stdout=DEVNULL)

View File

@ -10,9 +10,11 @@ from flask import Response, request, redirect, Blueprint, abort
from flask import send_from_directory
import deadsimplekv as simplekv
from httpapi.sse.wrapper import SSEWrapper
from onionrusers import contactmanager
from onionrutils import stringvalidators
from utils import reconstructhash, identifyhome
from utils.bettersleep import better_sleep as sleep
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
import loadinbox
@ -35,6 +37,7 @@ flask_blueprint = Blueprint('mail', __name__)
kv = simplekv.DeadSimpleKV(identifyhome.identify_home() + '/mailcache.dat')
root = os.path.dirname(os.path.realpath(__file__))
sse_wrapper = SSEWrapper()
@flask_blueprint.route('/mail/<path:path>', endpoint='mailstatic')
def load_mail(path):
@ -68,6 +71,16 @@ def mail_delete(block):
def list_inbox():
return ','.join(loadinbox.load_inbox())
@flask_blueprint.route('/mail/streaminbox')
def stream_inbox():
def _stream():
while True:
yield "data: " + ','.join(loadinbox.load_inbox()) + "\n\n"
sleep(1)
return sse_wrapper.handle_sse_request(_stream)
@flask_blueprint.route('/mail/getsentbox')
def list_sentbox():
kv.refresh()

View File

@ -15,6 +15,7 @@
<link rel="stylesheet" href="/mail/mail.css">
<script defer src="/shared/node_modules/pnotify/dist/iife/PNotify.js"></script>
<script defer src="/shared/node_modules/pnotify/dist/iife/PNotifyButtons.js"></script>
<script defer src="/shared/eventsource.js"></script>
<script defer src="/shared/main/apicheck.js"></script>
<script defer src="/shared/misc.js"></script>
<script defer src="/mail/sethumanreadable.js"></script>

View File

@ -382,6 +382,9 @@ function refreshPms(callNext){
if (! window.inboxActive){
return
}
if (document.hidden){
return
}
fetch('/mail/getinbox', {
headers: {
"token": webpass
@ -448,3 +451,17 @@ document.addEventListener("visibilitychange", function() {
refreshPms()
}
})
/*
let mailStream = function(){
var streamSource = new EventSourcePolyfill('/mail/streaminbox', {
headers: {
"token": webpass
}
})
streamSource.onmessage = function(e){
console.debug(e.data)
}
}
mailStream()
*/