zip selection

This commit is contained in:
ed 2021-03-27 15:48:52 +01:00
parent ffbfcd7e00
commit 9e850fc3ab
6 changed files with 150 additions and 39 deletions

View file

@ -161,22 +161,16 @@ class VFS(object):
for x in vfs.walk(wrel, "", uname, scandir, lstat):
yield x
def zipgen(self, vrem, rems, uname, dots, scandir):
vtops = [["", [self, vrem]]]
if rems:
# list of subfolders to zip was provided,
# add all the ones uname is allowed to access
vtops = []
for rem in rems:
try:
d = rem if not vrem else vrem + "/" + rem
vn = self.get(d, uname, True, False)
vtops.append([rem, vn])
except:
pass
def zipgen(self, vrem, flt, uname, dots, scandir):
if flt:
flt = {k: True for k in flt}
for vpath, apath, files, rd, vd in self.walk("", vrem, uname, dots, scandir):
if flt:
files = [x for x in files if x[0] in flt]
rd = [x for x in rd if x[0] in flt]
vd = {x: y for x, y in vd.items() if x in flt}
for rel, (vn, rem) in vtops:
for vpath, apath, files, rd, vd in vn.walk(rel, rem, uname, dots, scandir):
# print(repr([vpath, apath, [x[0] for x in files]]))
fnames = [n[0] for n in files]
vpaths = [vpath + "/" + n for n in fnames] if vpath else fnames
@ -196,9 +190,7 @@ class VFS(object):
del vd[x]
# up2k filetring based on actual abspath
files = [
x for x in files if "{0}.hist{0}up2k.".format(os.sep) not in x[1]
]
files = [x for x in files if "{0}.hist{0}up2k.".format(os.sep) not in x[1]]
for f in [{"vp": v, "ap": a, "st": n[1]} for v, a, n in files]:
yield f

View file

@ -161,8 +161,8 @@ class HttpCli(object):
try:
# self.log("pebkac at httpcli.run #2: " + repr(ex))
self.keepalive = self._check_nonfatal(ex)
self.log("{}\033[0m: {}".format(str(ex), self.vpath), 3)
msg = "<pre>{}: {}\r\n".format(str(ex), self.vpath)
self.log("{}\033[0m, {}".format(str(ex), self.vpath), 3)
msg = "<pre>{}\r\nURL: {}\r\n".format(str(ex), self.vpath)
self.reply(msg.encode("utf-8", "replace"), status=ex.code)
return self.keepalive
except Pebkac:
@ -397,8 +397,29 @@ class HttpCli(object):
if act == "tput":
return self.handle_text_upload()
if act == "zip":
return self.handle_zip_post()
raise Pebkac(422, 'invalid action "{}"'.format(act))
def handle_zip_post(self):
for k in ["zip", "tar"]:
v = self.uparam.get(k)
if v is not None:
break
if not v:
raise Pebkac(422, "need zip or tar keyword")
vn, rem = self.auth.vfs.get(self.vpath, self.uname, True, False)
items = self.parser.require("files", 1024 * 1024)
if not items:
raise Pebkac(422, "need files list")
items = items.replace("\r", "").split("\n")
items = [x for x in items if items]
return self.tx_zip(k, v, vn, rem, items, self.args.ed)
def handle_post_json(self):
try:
remains = int(self.headers["content-length"])

View file

@ -87,7 +87,9 @@ class HttpConn(object):
err = "need at least 4 bytes in the first packet; got {}".format(
len(method)
)
if method:
self.log(err)
self.s.send(b"HTTP/1.1 400 Bad Request\r\n\r\n" + err.encode("utf-8"))
return

View file

@ -182,6 +182,11 @@ a, #files tbody div a:last-child {
color: #840;
text-shadow: 0 0 .3em #b80;
}
#files tbody tr.sel td {
background: #80b;
color: #fff;
border-color: #a3d;
}
#blocked {
position: fixed;
top: 0;
@ -268,6 +273,25 @@ a, #files tbody div a:last-child {
padding: .2em 0 0 .07em;
color: #fff;
}
#wtoggle>span {
display: none;
}
#wtoggle.sel {
width: 4.27em;
}
#wtoggle.sel>span {
display: inline-block;
line-height: 0;
}
#wtoggle.sel>span a {
font-size: .4em;
margin: -.3em 0;
position: relative;
display: inline-block;
}
#wtoggle.sel>span #selzip {
top: -.6em;
}
#barpos,
#barbuf {
position: absolute;

View file

@ -112,7 +112,14 @@
{%- endif %}
<div id="widget">
<div id="wtoggle"></div>
<div id="wtoggle">
<span>
<a href="#" id="selall">sel.<br />all</a>
<a href="#" id="selinv">sel.<br />inv.</a>
<a href="#" id="selzip">zip</a>
</span>
</div>
<div id="widgeti">
<div id="pctl"><a href="#" id="bprev"></a><a href="#" id="bplay"></a><a href="#" id="bnext"></a></div>
<canvas id="pvol" width="288" height="38"></canvas>

View file

@ -1595,6 +1595,8 @@ var arcfmt = (function () {
o.setAttribute("href", href.slice(0, ofs + 1) + arg);
o.textContent = fmt.split('_')[0];
}
ebi('selzip').textContent = fmt.split('_')[0];
ebi('selzip').setAttribute('fmt', arg);
}
function try_render() {
@ -1624,6 +1626,69 @@ var arcfmt = (function () {
})();
var msel = (function () {
function getsel() {
var names = [];
var links = document.querySelectorAll('#files tbody tr.sel td:nth-child(2) a');
for (var a = 0, aa = links.length; a < aa; a++)
names.push(links[a].getAttribute('href'));
return names;
}
function selui() {
var fun = getsel().length ? "add" : "remove";
ebi('wtoggle').classList[fun]('sel');
}
function seltgl(e) {
ev(e);
var tr = this.parentNode;
tr.classList.toggle('sel');
selui();
}
var trs = document.querySelectorAll('#files tbody tr');
ebi('selall').onclick = function (e) {
ev(e);
for (var a = 0, aa = trs.length; a < aa; a++)
trs[a].classList.add('sel');
selui();
};
ebi('selinv').onclick = function (e) {
ev(e);
for (var a = 0, aa = trs.length; a < aa; a++)
trs[a].classList.toggle('sel');
selui();
};
ebi('selzip').onclick = function (e) {
ev(e);
var names = getsel();
var arg = ebi('selzip').getAttribute('fmt');
var txt = names.join('\n');
var frm = document.createElement('form');
frm.setAttribute('action', '?' + arg);
frm.setAttribute('method', 'post');
frm.setAttribute('target', '_blank');
frm.setAttribute('enctype', 'multipart/form-data');
frm.innerHTML = '<input name="act" value="zip" />' +
'<textarea name="files" id="ziptxt"></textarea>';
frm.style.display = 'none';
var oldform = document.querySelector('#widgeti>form');
if (oldform)
oldform.parentNode.removeChild(oldform);
ebi('widgeti').appendChild(frm);
var obj = ebi('ziptxt');
obj.value = txt;
console.log(txt);
frm.submit();
};
var tds = document.querySelectorAll('#files tbody td+td+td');
for (var a = 0, aa = tds.length; a < aa; a++) {
tds[a].onclick = seltgl;
}
})();
function ev_row_tgl(e) {
ev(e);
filecols.toggle(this.parentElement.parentElement.getElementsByTagName('span')[0].textContent);