add upload widget

This commit is contained in:
ed 2019-06-10 17:18:11 +00:00
parent d263b748aa
commit 1ea9b26a89
7 changed files with 54 additions and 17 deletions

2
.vscode/launch.json vendored
View file

@ -13,7 +13,7 @@
"0", "0",
"-nc", "-nc",
"4", "4",
"-nw", //"-nw",
"-a", "-a",
"ed:wark", "ed:wark",
"-v", "-v",

View file

@ -43,7 +43,7 @@
"editor.formatOnSave": true, "editor.formatOnSave": true,
"[html]": { "[html]": {
"editor.formatOnSave": false, "editor.formatOnSave": false,
} },
// //
// things you may wanna edit: // things you may wanna edit:
// //

View file

@ -68,4 +68,5 @@ pip install black bandit pylint flake8 # vscode tooling
roughly sorted by priority roughly sorted by priority
* last-modified header
* support pillow-simd * support pillow-simd

View file

@ -16,7 +16,7 @@ if not PY2:
unicode = str unicode = str
from urllib.parse import unquote_plus from urllib.parse import unquote_plus
else: else:
from urllib import unquote_plus from urllib import unquote_plus # pylint: disable=no-name-in-module
class HttpCli(object): class HttpCli(object):
@ -77,8 +77,8 @@ class HttpCli(object):
self.log(self.rvol) self.log(self.rvol)
self.log(self.wvol) self.log(self.wvol)
# split req into vpath + args # split req into vpath + uparam
args = {} uparam = {}
if "?" not in self.req: if "?" not in self.req:
if not self.req.endswith("/"): if not self.req.endswith("/"):
self.absolute_urls = True self.absolute_urls = True
@ -93,11 +93,11 @@ class HttpCli(object):
for k in arglist.split("&"): for k in arglist.split("&"):
if "=" in k: if "=" in k:
k, v = k.split("=", 1) k, v = k.split("=", 1)
args[k.lower()] = v.strip() uparam[k.lower()] = v.strip()
else: else:
args[k.lower()] = True uparam[k.lower()] = True
self.args = args self.uparam = uparam
self.vpath = unquote_plus(vpath) self.vpath = unquote_plus(vpath)
try: try:
@ -148,7 +148,7 @@ class HttpCli(object):
return self.tx_file(static_path) return self.tx_file(static_path)
# conditional redirect to single volumes # conditional redirect to single volumes
if self.vpath == "" and not self.args: if self.vpath == "" and not self.uparam:
nread = len(self.rvol) nread = len(self.rvol)
nwrite = len(self.wvol) nwrite = len(self.wvol)
if nread + nwrite == 1: if nread + nwrite == 1:
@ -160,16 +160,18 @@ class HttpCli(object):
self.absolute_urls = True self.absolute_urls = True
# go home if verboten # go home if verboten
readable, writable = self.conn.auth.vfs.can_access(self.vpath, self.uname) self.readable, self.writable = self.conn.auth.vfs.can_access(
if not readable and not writable: self.vpath, self.uname
)
if not self.readable and not self.writable:
self.log("inaccessible: {}".format(self.vpath)) self.log("inaccessible: {}".format(self.vpath))
self.args = {"h": True} self.uparam = {"h": True}
if "h" in self.args: if "h" in self.uparam:
self.vpath = None self.vpath = None
return self.tx_mounts() return self.tx_mounts()
if readable: if self.readable:
return self.tx_browser() return self.tx_browser()
else: else:
return self.tx_upper() return self.tx_upper()
@ -210,7 +212,8 @@ class HttpCli(object):
pwd = u"x" # nosec pwd = u"x" # nosec
h = ["Set-Cookie: cppwd={}; Path=/".format(pwd)] h = ["Set-Cookie: cppwd={}; Path=/".format(pwd)]
html = u'<h1>{}<h2><a href="/">ack'.format(msg) html = u'<h1>{}</h1><h2><a href="/">ack</a></h2>'.format(msg)
html += '<script>setTimeout(function(){window.location.replace("/");},500);</script>'
self.reply(html.encode("utf-8"), headers=h) self.reply(html.encode("utf-8"), headers=h)
def handle_plain_upload(self): def handle_plain_upload(self):
@ -299,7 +302,7 @@ class HttpCli(object):
def tx_upper(self): def tx_upper(self):
# return html for basic uploader; # return html for basic uploader;
# js rewrites to up2k unless args['b'] # js rewrites to up2k unless uparam['b']
self.loud_reply("TODO jupper {}".format(self.vpath)) self.loud_reply("TODO jupper {}".format(self.vpath))
def tx_browser(self): def tx_browser(self):
@ -345,5 +348,7 @@ class HttpCli(object):
files.append(item) files.append(item)
dirs.extend(files) dirs.extend(files)
html = self.conn.tpl_browser.render(vpnodes=vpnodes, files=dirs) html = self.conn.tpl_browser.render(
vpnodes=vpnodes, files=dirs, can_upload=self.writable
)
self.reply(html.encode("utf-8")) self.reply(html.encode("utf-8"))

View file

@ -249,3 +249,14 @@ a.play.act {
width: calc(100% - 10.5em); width: calc(100% - 10.5em);
background: rgba(0,0,0,0.2); background: rgba(0,0,0,0.2);
} }
#bup {
padding: .5em .5em .5em .3em;
margin-bottom: 1em;
background: #2d2d2d;
border-radius: 0 .5em .5em 0;
border-right: .3em solid #3a3a3a;
max-width: 40em;
}
#bup input {
margin: .5em;
}

View file

@ -16,6 +16,17 @@
{%- endfor %} {%- endfor %}
<span>{{ vpnodes[-1][1] }}</span> <span>{{ vpnodes[-1][1] }}</span>
</h1> </h1>
{%- if can_upload %}
<div id="bup">
<form method="post" enctype="multipart/form-data" accept-charset="utf-8">
<input type="hidden" name="act" value="bput" />
<input type="file" name="f" multiple><br />
<input type="submit" value="start upload">
</form>
</div>
{%- endif %}
<table id="files"> <table id="files">
<thead> <thead>
<tr> <tr>
@ -33,6 +44,9 @@
</tbody> </tbody>
</table> </table>
<h2><a href="?h">control-panel</a></h2>
<div id="widget"> <div id="widget">
<div id="wtoggle">=</div> <div id="wtoggle">=</div>
<div id="widgeti"> <div id="widgeti">

View file

@ -9,6 +9,12 @@ main
httpsrv httpsrv
... ...
##
## things which need the broker
moving uploaded files into place
creating a thumbnail
## ##
## thumbnails ## thumbnails