impl write-only volumes + support py3.8

This commit is contained in:
ed 2020-01-19 14:30:48 +01:00
parent 85454e409a
commit ded987d9b5
6 changed files with 41 additions and 31 deletions

View file

@ -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)

View file

@ -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,10 +194,7 @@ 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='<a href="/{}">return to /{}</a>'.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],

View file

@ -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;

View file

@ -13,16 +13,17 @@
</head>
<body>
{%- if can_upload %}
{%- include 'upload.html' %}
{%- endif %}
<h1 id="path">
{%- for n in vpnodes %}
<a href="/{{ n[0] }}">{{ n[1] }}</a>
{%- endfor %}
</h1>
{%- if can_upload %}
{%- include 'upload.html' %}
{%- endif %}
{%- if can_read %}
{%- if prologue %}
<div id="pro" class="logue">{{ prologue }}</div>
{%- endif %}
@ -48,6 +49,7 @@
{%- if epilogue %}
<div id="epi" class="logue">{{ epilogue }}</div>
{%- endif %}
{%- endif %}
<h2><a href="?h">control-panel</a></h2>
@ -60,7 +62,11 @@
<canvas id="barbuf"></canvas>
</div>
</div>
{%- if can_read %}
<script src="/.cpr/browser.js{{ ts }}"></script>
{%- endif %}
{%- if can_upload %}
<script src="/.cpr/up2k.js{{ ts }}"></script>
{%- endif %}

View file

@ -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'));
}

View file

@ -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;