From 2d2e8a3da785ec5c23bfcaf2187c6f13757a46b5 Mon Sep 17 00:00:00 2001 From: ed Date: Sun, 21 Feb 2021 01:31:49 +0000 Subject: [PATCH] less jank ?ls --- copyparty/httpcli.py | 54 ++++++++++++++++++++------------------ copyparty/web/browser.html | 2 +- copyparty/web/browser.js | 16 ++++++----- copyparty/web/up2k.js | 2 +- 4 files changed, 39 insertions(+), 35 deletions(-) diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 03e645c9..0f0b0d09 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -1179,12 +1179,14 @@ class HttpCli(object): if rem == ".hist": hidden = ["up2k."] + is_ls = "ls" in self.uparam + dirs = [] files = [] for fn in vfs_ls: base = "" href = fn - if self.absolute_urls and vpath: + if not is_ls and self.absolute_urls and vpath: base = "/" + vpath + "/" href = base + fn @@ -1221,30 +1223,20 @@ class HttpCli(object): except: ext = "%" - item = [margin, quotep(href), html_escape(fn), sz, ext, dt] + item = { + "lead": margin, + "href": quotep(href), + "name": fn, + "sz": sz, + "ext": ext, + "dt": dt, + "ts": inf.st_mtime, + } if is_dir: dirs.append(item) else: files.append(item) - logues = [None, None] - for n, fn in enumerate([".prologue.html", ".epilogue.html"]): - fn = os.path.join(abspath, fn) - if os.path.exists(fsenc(fn)): - with open(fsenc(fn), "rb") as f: - logues[n] = f.read().decode("utf-8") - - if False: - # this is a mistake - md = None - for fn in [x[2] for x in files]: - if fn.lower() == "readme.md": - fn = os.path.join(abspath, fn) - with open(fn, "rb") as f: - md = f.read().decode("utf-8") - - break - srv_info = [] try: @@ -1273,16 +1265,26 @@ class HttpCli(object): except: pass + srv_info = " /// ".join(srv_info) + + if is_ls: + [x.pop("name") for y in [dirs, files] for x in y] + ret = json.dumps({"dirs": dirs, "files": files, "srvinf": srv_info}) + self.reply(ret.encode("utf-8", "replace")) + return True + + logues = [None, None] + for n, fn in enumerate([".prologue.html", ".epilogue.html"]): + fn = os.path.join(abspath, fn) + if os.path.exists(fsenc(fn)): + with open(fsenc(fn), "rb") as f: + logues[n] = f.read().decode("utf-8") + ts = "" # ts = "?{}".format(time.time()) dirs.extend(files) - if "ls" in self.uparam: - ret = json.dumps(dirs) - self.reply(ret.encode("utf-8", "replace")) - return True - html = self.conn.tpl_browser.render( vdir=quotep(self.vpath), vpnodes=vpnodes, @@ -1294,7 +1296,7 @@ class HttpCli(object): prologue=logues[0], epilogue=logues[1], title=html_escape(self.vpath), - srv_info=" /// ".join(srv_info), + srv_info=srv_info, ) self.reply(html.encode("utf-8", "replace")) return True diff --git a/copyparty/web/browser.html b/copyparty/web/browser.html index ff995edb..c473306b 100644 --- a/copyparty/web/browser.html +++ b/copyparty/web/browser.html @@ -75,7 +75,7 @@ {%- for f in files %} -{{ f[0] }}{{ f[2] }}{{ f[3] }}{{ f[4] }}{{ f[5] }} +{{ f.lead }}{{ f.name|e }}{{ f.sz }}{{ f.ext }}{{ f.dt }} {%- endfor %} diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 32949f79..5a29db4f 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -834,16 +834,18 @@ function autoplay_blocked() { window.location = this.top; return; } + + ebi('srv_info').innerHTML = res.srvinf; + var nodes = res.dirs.concat(res.files); var top = this.top; var html = []; - for (var a = 0; a < res.length; a++) { - var ln = '' + res[a][0] + '' + res[a][2] + ''; + for (var a = 0; a < nodes.length; a++) { + var r = nodes[a], + ln = '' + r.lead + '' + esc(decodeURIComponent(r.href)) + ''; - for (var b = 3; b < res[a].length; b++) { - ln += '' + res[a][b] + ''; - } - html.push(ln + '') + ln = [ln, r.sz, r.ext, r.dt].join(''); + html.push(ln + ''); } html = html.join('\n'); ebi('files').tBodies[0].innerHTML = html; diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js index 74ecf38f..4dc57260 100644 --- a/copyparty/web/up2k.js +++ b/copyparty/web/up2k.js @@ -382,7 +382,7 @@ function up2k_init(have_crypto) { var tr = document.createElement('tr'); tr.innerHTML = 'hashing'.format(st.files.length); - tr.getElementsByTagName('td')[0].innerHTML = linksplit(esc(entry.purl + entry.name)).join(' '); + tr.getElementsByTagName('td')[0].innerHTML = fsearch ? entry.name : linksplit(esc(entry.purl + entry.name)).join(' '); ebi('u2tab').appendChild(tr); st.files.push(entry);