From 6ecd7453238dd3b18529d5e235dfa9a723c00f33 Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 6 Mar 2021 16:34:55 +0100 Subject: [PATCH] so much for sessionStorage --- copyparty/svchub.py | 1 - copyparty/up2k.py | 7 +++-- copyparty/web/browser.js | 56 ++++++++++++++++++++++++++-------------- copyparty/web/util.js | 14 +++++----- 4 files changed, 48 insertions(+), 30 deletions(-) diff --git a/copyparty/svchub.py b/copyparty/svchub.py index c31f2ee5..8983d423 100644 --- a/copyparty/svchub.py +++ b/copyparty/svchub.py @@ -9,7 +9,6 @@ from datetime import datetime, timedelta import calendar from .__init__ import PY2, WINDOWS, MACOS, VT100 -from .authsrv import AuthSrv from .tcpsrv import TcpSrv from .up2k import Up2k from .util import mp diff --git a/copyparty/up2k.py b/copyparty/up2k.py index 9c1f159b..86a90668 100644 --- a/copyparty/up2k.py +++ b/copyparty/up2k.py @@ -64,7 +64,7 @@ class Up2k(object): self.flags = {} self.cur = {} self.mtag = None - self.n_mtag_tags_added = 0 + self.n_mtag_tags_added = -1 self.mem_cur = None self.sqlite_ver = None @@ -461,7 +461,10 @@ class Up2k(object): # mp.pool.ThreadPool and concurrent.futures.ThreadPoolExecutor # both do crazy runahead so lets reinvent another wheel nw = os.cpu_count() if hasattr(os, "cpu_count") else 4 - self.log("using {}x {}".format(nw, self.mtag.backend)) + if self.n_mtag_tags_added == -1: + self.log("using {}x {}".format(nw, self.mtag.backend)) + self.n_mtag_tags_added = 0 + mpool = Queue(nw) for _ in range(nw): thr = threading.Thread(target=self._tag_thr, args=(mpool,)) diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index d36c9cdf..cdf25ff3 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -467,8 +467,7 @@ function play(tid, call_depth) { var o = ebi(oid); o.setAttribute('id', 'thx_js'); if (window.history && history.replaceState) { - var nurl = (document.location + '').split('#')[0] + '#' + oid; - hist_replace(ebi('files').innerHTML, nurl); + hist_replace((document.location + '').split('#')[0] + '#' + oid); } else { document.location.hash = oid; @@ -726,7 +725,6 @@ function autoplay_blocked() { // tree (function () { - var treedata = null; var dyn = bcfg_get('dyntree', true); var treesz = icfg_get('treesz', 16); treesz = Math.min(Math.max(treesz, 4), 50); @@ -746,13 +744,15 @@ function autoplay_blocked() { treefiles.appendChild(ebi('epi')); swrite('entreed', 'tree'); - get_tree("", get_vpath()); + get_tree("", get_vpath(), true); } - function get_tree(top, dst) { + function get_tree(top, dst, rst) { var xhr = new XMLHttpRequest(); xhr.top = top; xhr.dst = dst; + xhr.rst = rst; + xhr.ts = new Date().getTime(); xhr.open('GET', dst + '?tree=' + top, true); xhr.onreadystatechange = recvtree; xhr.send(); @@ -768,6 +768,13 @@ function autoplay_blocked() { return; } + var cur = ebi('treeul').getAttribute('ts'); + if (cur && parseInt(cur) > this.ts) { + console.log("reject tree"); + return; + } + ebi('treeul').setAttribute('ts', this.ts); + var top = this.top == '.' ? this.dst : this.top, name = top.split('/').slice(-2)[0], rtop = top.replace(/^\/+/, ""); @@ -781,7 +788,7 @@ function autoplay_blocked() { var html = parsetree(res, rtop); if (!this.top) { html = '
  • -[root]\n
  • '; } else { @@ -841,12 +848,20 @@ function autoplay_blocked() { treegrow.call(this.previousSibling, e); return; } + reqls(this.getAttribute('href'), true); + } + + function reqls(url, hpush) { var xhr = new XMLHttpRequest(); - xhr.top = this.getAttribute('href'); + xhr.top = url; + xhr.hpush = hpush; + xhr.ts = new Date().getTime(); xhr.open('GET', xhr.top + '?ls', true); xhr.onreadystatechange = recvls; xhr.send(); - get_tree('.', xhr.top); + if (hpush) + get_tree('.', xhr.top); + enspin('#files'); } @@ -874,6 +889,13 @@ function autoplay_blocked() { return; } + var cur = ebi('files').getAttribute('ts'); + if (cur && parseInt(cur) > this.ts) { + console.log("reject ls"); + return; + } + ebi('files').setAttribute('ts', this.ts); + try { var res = JSON.parse(this.responseText); } @@ -913,7 +935,9 @@ function autoplay_blocked() { html = html.join('\n'); ebi('files').innerHTML = html; - hist_push(html, this.top); + if (this.hpush) + hist_push(this.top); + apply_perms(res.perms); despin('#files'); @@ -994,19 +1018,13 @@ function autoplay_blocked() { entree(); window.onpopstate = function (e) { - console.log(e.url + ' ,, ' + ((e.state + '').slice(0, 64))); - var html = sessionStorage.getItem(e.state || 1); - if (!html) - return; - - ebi('files').innerHTML = html; - reload_tree(); - reload_browser(); + console.log("h-pop " + e.state); + get_tree("", e.state, true); + reqls(e.state); }; if (window.history && history.pushState) { - var u = get_vpath() + window.location.hash; - hist_replace(ebi('files').innerHTML, u); + hist_replace(get_vpath() + window.location.hash); } })(); diff --git a/copyparty/web/util.js b/copyparty/web/util.js index 719f608a..cff90ff5 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -335,14 +335,12 @@ function bcfg_upd_ui(name, val) { } -function hist_push(html, url) { - var key = new Date().getTime(); - sessionStorage.setItem(key, html); - history.pushState(key, url, url); +function hist_push(url) { + console.log("h-push " + url); + history.pushState(url, url, url); } -function hist_replace(html, url) { - var key = new Date().getTime(); - sessionStorage.setItem(key, html); - history.replaceState(key, url, url); +function hist_replace(url) { + console.log("h-repl " + url); + history.replaceState(url, url, url); }