From ded987d9b5f00e0ae96d65c944dfc4a6260daf31 Mon Sep 17 00:00:00 2001 From: ed Date: Sun, 19 Jan 2020 14:30:48 +0100 Subject: [PATCH] impl write-only volumes + support py3.8 --- copyparty/__version__.py | 4 ++-- copyparty/httpcli.py | 26 ++++++++++---------------- copyparty/web/browser.css | 3 ++- copyparty/web/browser.html | 16 +++++++++++----- copyparty/web/up2k.js | 14 ++++++++++---- copyparty/web/upload.css | 9 ++++++--- 6 files changed, 41 insertions(+), 31 deletions(-) diff --git a/copyparty/__version__.py b/copyparty/__version__.py index 9192b076..bf6440a4 100644 --- a/copyparty/__version__.py +++ b/copyparty/__version__.py @@ -1,7 +1,7 @@ # coding: utf-8 -VERSION = (0, 2, 0) -BUILD_DT = (2019, 7, 8) +VERSION = (0, 2, 1) +BUILD_DT = (2020, 1, 19) S_VERSION = ".".join(map(str, VERSION)) S_BUILD_DT = "{0:04d}-{1:02d}-{2:02d}".format(*BUILD_DT) diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 22585a3f..6f22f48e 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -9,13 +9,15 @@ import json from datetime import datetime import calendar import mimetypes -import cgi from .__init__ import E, PY2 from .util import * # noqa # pylint: disable=unused-wildcard-import if not PY2: unicode = str + from html import escape as html_escape +else: + from cgi import escape as html_escape class HttpCli(object): @@ -192,11 +194,8 @@ class HttpCli(object): self.vpath = None return self.tx_mounts() - if self.readable: - return self.tx_browser() - else: - return self.tx_upper() - + return self.tx_browser() + def handle_post(self): self.log("POST " + self.req) @@ -445,7 +444,7 @@ class HttpCli(object): html = self.conn.tpl_msg.render( h2='return to /{}'.format( - quotep(self.vpath), cgi.escape(self.vpath, quote=True) + quotep(self.vpath), html_escape(self.vpath, quote=False) ), pre=msg, ) @@ -609,12 +608,6 @@ class HttpCli(object): self.reply(html.encode("utf-8")) return True - def tx_upper(self): - # return html for basic uploader; - # js rewrites to up2k unless uparam['b'] - self.loud_reply("TODO jupper {}".format(self.vpath)) - return True - def tx_browser(self): vpath = "" vpnodes = [["", "/"]] @@ -625,9 +618,9 @@ class HttpCli(object): else: vpath += "/" + node - vpnodes.append([quotep(vpath) + "/", cgi.escape(node)]) + vpnodes.append([quotep(vpath) + "/", html_escape(node, quote=False)]) - vn, rem = self.auth.vfs.get(self.vpath, self.uname, True, False) + vn, rem = self.auth.vfs.get(self.vpath, self.uname, self.readable, self.writable) abspath = vn.canonical(rem) if not os.path.exists(fsenc(abspath)): @@ -665,7 +658,7 @@ class HttpCli(object): dt = datetime.utcfromtimestamp(inf.st_mtime) dt = dt.strftime("%Y-%m-%d %H:%M:%S") - item = [margin, quotep(href), cgi.escape(fn, quote=True), sz, dt] + item = [margin, quotep(href), html_escape(fn, quote=False), sz, dt] if is_dir: dirs.append(item) else: @@ -687,6 +680,7 @@ class HttpCli(object): vpnodes=vpnodes, files=dirs, can_upload=self.writable, + can_read=self.readable, ts=ts, prologue=logues[0], epilogue=logues[1], diff --git a/copyparty/web/browser.css b/copyparty/web/browser.css index efd75007..007a5d2f 100644 --- a/copyparty/web/browser.css +++ b/copyparty/web/browser.css @@ -36,11 +36,12 @@ body { padding: .35em .5em .2em .5em; border-radius: 0 .3em .3em 0; box-shadow: .1em .1em .4em #222; - margin: 1em 0; + margin: 2em 0 1em 0; font-size: 1.4em; } #files { border-collapse: collapse; + margin-top: 1em; } #files tbody a { display: block; diff --git a/copyparty/web/browser.html b/copyparty/web/browser.html index 954c2426..9592ac50 100644 --- a/copyparty/web/browser.html +++ b/copyparty/web/browser.html @@ -13,16 +13,17 @@ - {%- if can_upload %} - {%- include 'upload.html' %} - {%- endif %} -

{%- for n in vpnodes %} {{ n[1] }} {%- endfor %}

+ {%- if can_upload %} + {%- include 'upload.html' %} + {%- endif %} + + {%- if can_read %} {%- if prologue %}
{{ prologue }}
{%- endif %} @@ -48,6 +49,7 @@ {%- if epilogue %}
{{ epilogue }}
{%- endif %} + {%- endif %}

control-panel

@@ -60,10 +62,14 @@ + + {%- if can_read %} + {%- endif %} + {%- if can_upload %} {%- endif %} - \ No newline at end of file + diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js index 87de6c9b..8add148a 100644 --- a/copyparty/web/up2k.js +++ b/copyparty/web/up2k.js @@ -105,8 +105,10 @@ function up2k_init(have_crypto) { shame = 'your browser is impressively ancient'; // upload ui hidden by default, clicking the header shows it - o('u2tgl').onclick = function (e) { - e.preventDefault(); + function toggle_upload_visible(ev) { + if (ev) + ev.preventDefault(); + o('u2tgl').style.display = 'none'; o('u2body').style.display = 'block'; @@ -120,6 +122,11 @@ function up2k_init(have_crypto) { o('u2foot').innerHTML = 'seems like ' + shame + ' so do that if you want more performance'; } }; + o('u2tgl').onclick = toggle_upload_visible; + + // show uploader if the user only has write-access + if (!o('files')) + toggle_upload_visible(); // shows or clears an error message in the basic uploader ui function setmsg(msg) { @@ -601,8 +608,7 @@ function up2k_init(have_crypto) { } t.t2 = new Date().getTime(); - if (t.n == 0) { - // TODO remove + if (t.n == 0 && window.location.hash == '#dbg') { var spd = (t.size / ((t.t2 - t.t1) / 1000.)) / (1024 * 1024.); alert('{0} ms, {1} MB/s\n'.format(t.t2 - t.t1, spd.toFixed(3)) + t.hash.join('\n')); } diff --git a/copyparty/web/upload.css b/copyparty/web/upload.css index 9ac27dbe..3ead19e2 100644 --- a/copyparty/web/upload.css +++ b/copyparty/web/upload.css @@ -1,7 +1,8 @@ #bup { padding: .5em .5em .5em .3em; + margin: 1em 0 2em 0; background: #2d2d2d; - border-radius: 0 0 1em 0; + border-radius: 0 1em 1em 0; border: 1px solid #3a3a3a; border-width: 0 .3em .3em 0; box-shadow: 0 0 1em #222 inset; @@ -12,7 +13,7 @@ } #up2k { display: none; - padding: 1.5em 1em 0 1em; + padding: 0 1em; } #u2form { position: absolute; @@ -31,6 +32,8 @@ #u2tgl { color: #fc5; font-size: 1.5em; + margin: .5em 0 1em 0; + display: block; } #u2body { display: none; @@ -150,4 +153,4 @@ top: 0; bottom: 0; background: #0a0; -} \ No newline at end of file +}