mirror of
https://github.com/9001/copyparty.git
synced 2025-08-18 09:22:31 -06:00
toggle upload widgets in spa
This commit is contained in:
parent
2a6dd7b512
commit
b14b86990f
|
@ -77,6 +77,8 @@ class HttpCli(object):
|
||||||
self.loud_reply(str(ex), status=ex.code)
|
self.loud_reply(str(ex), status=ex.code)
|
||||||
return self.keepalive
|
return self.keepalive
|
||||||
|
|
||||||
|
# time.sleep(0.4)
|
||||||
|
|
||||||
# normalize incoming headers to lowercase;
|
# normalize incoming headers to lowercase;
|
||||||
# outgoing headers however are Correct-Case
|
# outgoing headers however are Correct-Case
|
||||||
for header_line in headerlines[1:]:
|
for header_line in headerlines[1:]:
|
||||||
|
@ -1267,9 +1269,16 @@ class HttpCli(object):
|
||||||
|
|
||||||
srv_info = "</span> /// <span>".join(srv_info)
|
srv_info = "</span> /// <span>".join(srv_info)
|
||||||
|
|
||||||
|
perms = []
|
||||||
|
if self.readable:
|
||||||
|
perms.append("read")
|
||||||
|
if self.writable:
|
||||||
|
perms.append("write")
|
||||||
|
|
||||||
if is_ls:
|
if is_ls:
|
||||||
[x.pop(k) for k in ["name", "dt"] for y in [dirs, files] for x in y]
|
[x.pop(k) for k in ["name", "dt"] for y in [dirs, files] for x in y]
|
||||||
ret = json.dumps({"dirs": dirs, "files": files, "srvinf": srv_info})
|
ret = {"dirs": dirs, "files": files, "srvinf": srv_info, "perms": perms}
|
||||||
|
ret = json.dumps(ret)
|
||||||
self.reply(ret.encode("utf-8", "replace"), mime="application/json")
|
self.reply(ret.encode("utf-8", "replace"), mime="application/json")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -1289,10 +1298,9 @@ class HttpCli(object):
|
||||||
vdir=quotep(self.vpath),
|
vdir=quotep(self.vpath),
|
||||||
vpnodes=vpnodes,
|
vpnodes=vpnodes,
|
||||||
files=dirs,
|
files=dirs,
|
||||||
can_upload=self.writable,
|
|
||||||
can_read=self.readable,
|
|
||||||
have_up2k_idx=self.args.e2d,
|
|
||||||
ts=ts,
|
ts=ts,
|
||||||
|
perms=json.dumps(perms),
|
||||||
|
have_up2k_idx=self.args.e2d,
|
||||||
prologue=logues[0],
|
prologue=logues[0],
|
||||||
epilogue=logues[1],
|
epilogue=logues[1],
|
||||||
title=html_escape(self.vpath),
|
title=html_escape(self.vpath),
|
||||||
|
|
|
@ -730,6 +730,11 @@ class Up2k(object):
|
||||||
if etag == prev.get(k, None):
|
if etag == prev.get(k, None):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.mkdir(os.path.join(k, ".hist"))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
path2 = "{}.{}".format(path, os.getpid())
|
path2 = "{}.{}".format(path, os.getpid())
|
||||||
j = json.dumps(reg, indent=2, sort_keys=True).encode("utf-8")
|
j = json.dumps(reg, indent=2, sort_keys=True).encode("utf-8")
|
||||||
with gzip.GzipFile(path2, "wb") as f:
|
with gzip.GzipFile(path2, "wb") as f:
|
||||||
|
|
|
@ -336,7 +336,6 @@ a,
|
||||||
box-shadow: 0 0 1em #222 inset;
|
box-shadow: 0 0 1em #222 inset;
|
||||||
}
|
}
|
||||||
#ops {
|
#ops {
|
||||||
display: none;
|
|
||||||
background: #333;
|
background: #333;
|
||||||
margin: 1.7em 1.5em 0 1.5em;
|
margin: 1.7em 1.5em 0 1.5em;
|
||||||
padding: .3em .6em;
|
padding: .3em .6em;
|
||||||
|
@ -426,6 +425,7 @@ input[type="checkbox"]:checked+label {
|
||||||
padding: .3em .5em;
|
padding: .3em .5em;
|
||||||
font-size: 1.5em;
|
font-size: 1.5em;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
min-width: 12em;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
#treefiles #files tbody {
|
#treefiles #files tbody {
|
||||||
|
@ -434,9 +434,6 @@ input[type="checkbox"]:checked+label {
|
||||||
#treefiles #files thead th:nth-child(1) {
|
#treefiles #files thead th:nth-child(1) {
|
||||||
border-radius: .7em 0 0 0;
|
border-radius: .7em 0 0 0;
|
||||||
}
|
}
|
||||||
#tree li {
|
|
||||||
list-style: none;
|
|
||||||
}
|
|
||||||
#tree ul,
|
#tree ul,
|
||||||
#tree li {
|
#tree li {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
@ -447,6 +444,8 @@ input[type="checkbox"]:checked+label {
|
||||||
}
|
}
|
||||||
#tree li {
|
#tree li {
|
||||||
margin-left: 1em;
|
margin-left: 1em;
|
||||||
|
list-style: none;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
#tree a.hl {
|
#tree a.hl {
|
||||||
color: #400;
|
color: #400;
|
||||||
|
@ -454,9 +453,6 @@ input[type="checkbox"]:checked+label {
|
||||||
border-radius: .3em;
|
border-radius: .3em;
|
||||||
text-shadow: none;
|
text-shadow: none;
|
||||||
}
|
}
|
||||||
#tree li {
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
#tree a {
|
#tree a {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
@ -497,4 +493,6 @@ input[type="checkbox"]:checked+label {
|
||||||
padding: 0 1.2em 0 0;
|
padding: 0 1.2em 0 0;
|
||||||
font-size: 4em;
|
font-size: 4em;
|
||||||
animation: spin 1s linear infinite;
|
animation: spin 1s linear infinite;
|
||||||
|
position: absolute;
|
||||||
|
z-index: 9;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,36 +7,29 @@
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=0.8">
|
<meta name="viewport" content="width=device-width, initial-scale=0.8">
|
||||||
<link rel="stylesheet" type="text/css" media="screen" href="/.cpr/browser.css{{ ts }}">
|
<link rel="stylesheet" type="text/css" media="screen" href="/.cpr/browser.css{{ ts }}">
|
||||||
{%- if can_upload %}
|
|
||||||
<link rel="stylesheet" type="text/css" media="screen" href="/.cpr/upload.css{{ ts }}">
|
<link rel="stylesheet" type="text/css" media="screen" href="/.cpr/upload.css{{ ts }}">
|
||||||
{%- endif %}
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="ops">
|
<div id="ops">
|
||||||
<a href="#" data-dest="">---</a>
|
<a href="#" data-dest="">---</a>
|
||||||
{%- if can_read %}
|
<a href="#" data-perm="read" data-dest="search">🔎</a>
|
||||||
<a href="#" data-dest="search">🔎</a>
|
{%- if have_up2k_idx %}
|
||||||
{%- endif %}
|
|
||||||
{%- if can_upload %}
|
|
||||||
<a href="#" data-dest="up2k">🚀</a>
|
<a href="#" data-dest="up2k">🚀</a>
|
||||||
<a href="#" data-dest="bup">🎈</a>
|
{%- else %}
|
||||||
<a href="#" data-dest="mkdir">📂</a>
|
<a href="#" data-perm="write" data-dest="up2k">🚀</a>
|
||||||
<a href="#" data-dest="new_md">📝</a>
|
|
||||||
<a href="#" data-dest="msg">📟</a>
|
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
<a href="#" data-perm="write" data-dest="bup">🎈</a>
|
||||||
|
<a href="#" data-perm="write" data-dest="mkdir">📂</a>
|
||||||
|
<a href="#" data-perm="write" data-dest="new_md">📝</a>
|
||||||
|
<a href="#" data-perm="write" data-dest="msg">📟</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{%- if can_read %}
|
|
||||||
<div id="op_search" class="opview">
|
<div id="op_search" class="opview">
|
||||||
<table id="srch_form"></table>
|
<table id="srch_form"></table>
|
||||||
<div id="srch_q"></div>
|
<div id="srch_q"></div>
|
||||||
</div>
|
</div>
|
||||||
{%- endif %}
|
|
||||||
|
|
||||||
{%- if can_upload %}
|
|
||||||
{%- include 'upload.html' %}
|
{%- include 'upload.html' %}
|
||||||
{%- endif %}
|
|
||||||
|
|
||||||
<h1 id="path">
|
<h1 id="path">
|
||||||
<a href="#" id="entree">🌲</a>
|
<a href="#" id="entree">🌲</a>
|
||||||
|
@ -45,7 +38,6 @@
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
{%- if can_read %}
|
|
||||||
{%- if prologue %}
|
{%- if prologue %}
|
||||||
<div id="pro" class="logue">{{ prologue }}</div>
|
<div id="pro" class="logue">{{ prologue }}</div>
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
@ -54,9 +46,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td id="tree">
|
<td id="tree">
|
||||||
<a href="#" id="detree">🍞...</a>
|
<a href="#" id="detree">🍞...</a>
|
||||||
<ul id="treeul">
|
<ul id="treeul"></ul>
|
||||||
<div class="dumb_loader_thing">🌲</div>
|
|
||||||
</ul>
|
|
||||||
</td>
|
</td>
|
||||||
<td id="treefiles"></td>
|
<td id="treefiles"></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -84,7 +74,6 @@
|
||||||
{%- if epilogue %}
|
{%- if epilogue %}
|
||||||
<div id="epi" class="logue">{{ epilogue }}</div>
|
<div id="epi" class="logue">{{ epilogue }}</div>
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- endif %}
|
|
||||||
|
|
||||||
<h2><a href="?h">control-panel</a></h2>
|
<h2><a href="?h">control-panel</a></h2>
|
||||||
|
|
||||||
|
@ -103,14 +92,11 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="/.cpr/util.js{{ ts }}"></script>
|
<script src="/.cpr/util.js{{ ts }}"></script>
|
||||||
|
|
||||||
{%- if can_read %}
|
|
||||||
<script src="/.cpr/browser.js{{ ts }}"></script>
|
<script src="/.cpr/browser.js{{ ts }}"></script>
|
||||||
{%- endif %}
|
|
||||||
|
|
||||||
{%- if can_upload %}
|
|
||||||
<script src="/.cpr/up2k.js{{ ts }}"></script>
|
<script src="/.cpr/up2k.js{{ ts }}"></script>
|
||||||
{%- endif %}
|
<script>
|
||||||
|
apply_perms({{ perms }});
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -732,6 +732,7 @@ function autoplay_blocked() {
|
||||||
xhr.open('GET', dst + '?tree=' + top, true);
|
xhr.open('GET', dst + '?tree=' + top, true);
|
||||||
xhr.onreadystatechange = recvtree;
|
xhr.onreadystatechange = recvtree;
|
||||||
xhr.send();
|
xhr.send();
|
||||||
|
enspin('#tree');
|
||||||
}
|
}
|
||||||
|
|
||||||
function recvtree() {
|
function recvtree() {
|
||||||
|
@ -776,6 +777,7 @@ function autoplay_blocked() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
document.querySelector('#treeul>li>a+a').textContent = '[root]';
|
document.querySelector('#treeul>li>a+a').textContent = '[root]';
|
||||||
|
despin('#tree');
|
||||||
reload_tree();
|
reload_tree();
|
||||||
|
|
||||||
var q = '#tree';
|
var q = '#tree';
|
||||||
|
@ -817,6 +819,7 @@ function autoplay_blocked() {
|
||||||
xhr.onreadystatechange = recvls;
|
xhr.onreadystatechange = recvls;
|
||||||
xhr.send();
|
xhr.send();
|
||||||
get_tree('.', xhr.top);
|
get_tree('.', xhr.top);
|
||||||
|
enspin('#files');
|
||||||
}
|
}
|
||||||
|
|
||||||
function treegrow(e) {
|
function treegrow(e) {
|
||||||
|
@ -865,6 +868,8 @@ function autoplay_blocked() {
|
||||||
html = html.join('\n');
|
html = html.join('\n');
|
||||||
ebi('files').tBodies[0].innerHTML = html;
|
ebi('files').tBodies[0].innerHTML = html;
|
||||||
history.pushState(html, this.top, this.top);
|
history.pushState(html, this.top, this.top);
|
||||||
|
apply_perms(res.perms);
|
||||||
|
despin('#files');
|
||||||
|
|
||||||
var o = ebi('pro');
|
var o = ebi('pro');
|
||||||
if (o) o.parentNode.removeChild(o);
|
if (o) o.parentNode.removeChild(o);
|
||||||
|
@ -946,6 +951,51 @@ function autoplay_blocked() {
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
|
function enspin(sel) {
|
||||||
|
despin(sel);
|
||||||
|
var d = document.createElement('div');
|
||||||
|
d.setAttribute('class', 'dumb_loader_thing');
|
||||||
|
d.innerHTML = '🌲';
|
||||||
|
var tgt = document.querySelector(sel);
|
||||||
|
tgt.insertBefore(d, tgt.childNodes[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function despin(sel) {
|
||||||
|
var o = document.querySelectorAll(sel + '>.dumb_loader_thing');
|
||||||
|
for (var a = o.length - 1; a >= 0; a--)
|
||||||
|
o[a].parentNode.removeChild(o[a]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function apply_perms(perms) {
|
||||||
|
var o = document.querySelectorAll('#ops>a[data-perm]');
|
||||||
|
for (var a = 0; a < o.length; a++)
|
||||||
|
o[a].style.display = 'none';
|
||||||
|
|
||||||
|
for (var a = 0; a < perms.length; a++) {
|
||||||
|
o = document.querySelectorAll('#ops>a[data-perm="' + perms[a] + '"]');
|
||||||
|
for (var b = 0; b < o.length; b++)
|
||||||
|
o[b].style.display = 'inline';
|
||||||
|
}
|
||||||
|
|
||||||
|
var act = document.querySelector('#ops>a.act');
|
||||||
|
var areq = act.getAttribute('data-perm');
|
||||||
|
if (areq && !has(perms, areq))
|
||||||
|
goto();
|
||||||
|
|
||||||
|
var have_write = has(perms, "write");
|
||||||
|
var tds = document.querySelectorAll('#u2conf td');
|
||||||
|
for (var a = 0; a < tds.length; a++) {
|
||||||
|
tds[a].style.display =
|
||||||
|
(have_write || tds[a].getAttribute('data-perm') == 'read') ?
|
||||||
|
'table-cell' : 'none';
|
||||||
|
}
|
||||||
|
if (!have_write)
|
||||||
|
up2k.set_fsearch();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function reload_browser(not_mp) {
|
function reload_browser(not_mp) {
|
||||||
makeSortable(ebi('files'));
|
makeSortable(ebi('files'));
|
||||||
|
|
||||||
|
|
|
@ -1049,6 +1049,11 @@ function up2k_init(have_crypto) {
|
||||||
ebi('u2tab').setAttribute('class', fsearch ? 'srch' : '');
|
ebi('u2tab').setAttribute('class', fsearch ? 'srch' : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function set_fsearch() {
|
||||||
|
if (!fsearch)
|
||||||
|
tgl_fsearch();
|
||||||
|
}
|
||||||
|
|
||||||
function tgl_flag_en() {
|
function tgl_flag_en() {
|
||||||
flag_en = !flag_en;
|
flag_en = !flag_en;
|
||||||
bcfg_set('flag_en', flag_en);
|
bcfg_set('flag_en', flag_en);
|
||||||
|
@ -1099,5 +1104,9 @@ function up2k_init(have_crypto) {
|
||||||
|
|
||||||
bumpthread({ "target": 1 })
|
bumpthread({ "target": 1 })
|
||||||
|
|
||||||
return { "init_deps": init_deps }
|
return { "init_deps": init_deps, "set_fsearch": set_fsearch }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (document.querySelector('#op_up2k.act'))
|
||||||
|
goto_up2k();
|
||||||
|
|
|
@ -50,12 +50,12 @@
|
||||||
<label for="flag_en" alt="ensure only one tab is uploading at a time $N (other tabs must have this enabled too)">💤</label>
|
<label for="flag_en" alt="ensure only one tab is uploading at a time $N (other tabs must have this enabled too)">💤</label>
|
||||||
</td>
|
</td>
|
||||||
{%- if have_up2k_idx %}
|
{%- if have_up2k_idx %}
|
||||||
<td rowspan="2">
|
<td data-perm="read" rowspan="2">
|
||||||
<input type="checkbox" id="fsearch" />
|
<input type="checkbox" id="fsearch" />
|
||||||
<label for="fsearch" alt="don't actually upload, instead check if the files already $N exist on the server (will scan all folders you can read)">🔎</label>
|
<label for="fsearch" alt="don't actually upload, instead check if the files already $N exist on the server (will scan all folders you can read)">🔎</label>
|
||||||
</td>
|
</td>
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
<td rowspan="2" id="u2btn_cw"></td>
|
<td data-perm="read" rowspan="2" id="u2btn_cw"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
|
|
|
@ -172,7 +172,6 @@ function goto(dest) {
|
||||||
if (op !== null && op !== '.')
|
if (op !== null && op !== '.')
|
||||||
goto(op);
|
goto(op);
|
||||||
}
|
}
|
||||||
ebi('ops').style.display = 'block';
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
|
@ -224,3 +223,12 @@ function get_vpath() {
|
||||||
function unix2iso(ts) {
|
function unix2iso(ts) {
|
||||||
return new Date(ts * 1000).toISOString().replace("T", " ").slice(0, -5);
|
return new Date(ts * 1000).toISOString().replace("T", " ").slice(0, -5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function has(haystack, needle) {
|
||||||
|
for (var a = 0; a < haystack.length; a++)
|
||||||
|
if (haystack[a] == needle)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue