add up2k ui

This commit is contained in:
ed 2019-06-21 16:29:52 +00:00
parent de29747dd1
commit 1ac0b51c93
7 changed files with 257 additions and 39 deletions

View file

@ -28,13 +28,11 @@ class HttpConn(object):
self.log_func = log_func self.log_func = log_func
self.log_src = "{} \033[36m{}".format(addr[0], addr[1]).ljust(26) self.log_src = "{} \033[36m{}".format(addr[0], addr[1]).ljust(26)
self.tpl_mounts = self.load_tpl("splash.html") env = jinja2.Environment()
self.tpl_browser = self.load_tpl("browser.html") env.loader = jinja2.FileSystemLoader(os.path.join(E.mod, "web"))
self.tpl_msg = self.load_tpl("msg.html") self.tpl_mounts = env.get_template("splash.html")
self.tpl_browser = env.get_template("browser.html")
def load_tpl(self, fn): self.tpl_msg = env.get_template("msg.html")
with open(self.respath(fn), "rb") as f:
return jinja2.Template(f.read().decode("utf-8"))
def respath(self, res_name): def respath(self, res_name):
return os.path.join(E.mod, "web", res_name) return os.path.join(E.mod, "web", res_name)

View file

@ -54,51 +54,51 @@ a {
color: #fff; color: #fff;
background: #161616; background: #161616;
} }
thead a { #files thead a {
color: #999; color: #999;
font-weight: normal; font-weight: normal;
} }
tr:hover { #files tr:hover {
background: #1c1c1c; background: #1c1c1c;
} }
thead th { #files thead th {
padding: .5em 1.3em .3em 1.3em; padding: .5em 1.3em .3em 1.3em;
} }
thead th:last-child { #files thead th:last-child {
background: #444; background: #444;
border-radius: .7em 0 0 0; border-radius: .7em 0 0 0;
} }
thead th:first-child { #files thead th:first-child {
background: #222; background: #222;
} }
tbody, #files tbody,
thead th:nth-child(2) { #files thead th:nth-child(2) {
background: #222; background: #222;
border-radius: 0 .7em 0 0; border-radius: 0 .7em 0 0;
} }
td { #files td {
margin: 0; margin: 0;
padding: 0 .5em; padding: 0 .5em;
} }
tbody td:nth-child(3) { #files tbody td:nth-child(3) {
font-family: monospace; font-family: monospace;
font-size: 1.3em; font-size: 1.3em;
text-align: right; text-align: right;
padding-right: 1em; padding-right: 1em;
white-space: nowrap; white-space: nowrap;
} }
tbody td:first-child { #files tbody td:first-child {
padding-left: 1.5em; padding-left: 1.5em;
color: #888; color: #888;
} }
tbody tr:first-child td { #files tbody tr:first-child td {
padding-top: .9em; padding-top: .9em;
} }
tbody tr:last-child td { #files tbody tr:last-child td {
padding-bottom: 1.3em; padding-bottom: 1.3em;
border-bottom: .5em solid #444; border-bottom: .5em solid #444;
} }
thead th[style] { #files thead th[style] {
width: auto !important; width: auto !important;
} }
#path a { #path a {
@ -255,13 +255,3 @@ 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;
background: #2d2d2d;
border-radius: 0 0 1em 0;
border-right: .3em solid #3a3a3a;
max-width: 40em;
}
#bup input {
margin: .5em;
}

View file

@ -7,17 +7,14 @@
<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"> <link rel="stylesheet" type="text/css" media="screen" href="/.cpr/browser.css">
{%- if can_upload %}
<link rel="stylesheet" type="text/css" media="screen" href="/.cpr/upload.css">
{%- endif %}
</head> </head>
<body> <body>
{%- if can_upload %} {%- if can_upload %}
<div id="bup"> {%- include 'upload.html' %}
<form method="post" enctype="multipart/form-data" accept-charset="utf-8" action="/{{ vdir }}">
<input type="hidden" name="act" value="bput" />
<input type="file" name="f" multiple><br />
<input type="submit" value="start upload">
</form>
</div>
{%- endif %} {%- endif %}
<h1 id="path"> <h1 id="path">
@ -57,6 +54,9 @@
</div> </div>
</div> </div>
<script src="/.cpr/browser.js{{ ts }}"></script> <script src="/.cpr/browser.js{{ ts }}"></script>
{%- if can_upload %}
<script src="/.cpr/up2k.js{{ ts }}"></script>
{%- endif %}
</body> </body>
</html> </html>

View file

@ -381,7 +381,7 @@ var vbar = (function () {
Math.round(mul * 1000) / 1000); Math.round(mul * 1000) / 1000);
*/ */
mp.au.currentTime = Math.round(mp.au.duration * mul); mp.au.currentTime = mp.au.duration * mul;
if (mp.au === mp.au_native) if (mp.au === mp.au_native)
// hack: ogv.js breaks on .play() during playback // hack: ogv.js breaks on .play() during playback

55
copyparty/web/up2k.js Normal file
View file

@ -0,0 +1,55 @@
// error handler for mobile devices
function hcroak(msg) {
document.body.innerHTML = msg;
window.onerror = undefined;
throw 'fatal_err';
}
function croak(msg) {
document.body.textContent = msg;
window.onerror = undefined;
throw msg;
}
function esc(txt) {
return txt.replace(/[&"<>]/g, function (c) {
return {
'&': '&amp;',
'"': '&quot;',
'<': '&lt;',
'>': '&gt;'
}[c];
});
}
window.onerror = function (msg, url, lineNo, columnNo, error) {
window.onerror = undefined;
var html = ['<h1>you hit a bug!</h1><p>please screenshot this error and send me a copy arigathanks gozaimuch (ed/irc.rizon.net or ed#2644)</p><p>',
esc(String(msg)), '</p><p>', esc(url + ' @' + lineNo + ':' + columnNo), '</p>'];
if (error) {
var find = ['desc', 'stack', 'trace'];
for (var a = 0; a < find.length; a++)
if (String(error[find[a]]) !== 'undefined')
html.push('<h2>' + find[a] + '</h2>' +
esc(String(error[find[a]])).replace(/\n/g, '<br />\n'));
}
document.body.style.fontSize = '0.8em';
hcroak(html.join('\n'));
};
function ebi(id) {
return document.getElementById(id);
}
ebi('up2k').style.display = 'block';
ebi('bup').style.display = 'none';
ebi('u2tgl').onclick = function (e) {
e.preventDefault();
ebi('u2tgl').style.display = 'none';
ebi('u2body').style.display = 'block';
}
ebi('u2nope').onclick = function (e) {
e.preventDefault();
ebi('up2k').style.display = 'none';
ebi('bup').style.display = 'block';
}

125
copyparty/web/upload.css Normal file
View file

@ -0,0 +1,125 @@
#bup {
padding: .5em .5em .5em .3em;
background: #2d2d2d;
border-radius: 0 0 1em 0;
border-right: .3em solid #3a3a3a;
max-width: 40em;
}
#bup input {
margin: .5em;
}
#up2k {
display: none;
}
#u2tgl {
display: block;
color: #fc5;
background: #444;
width: 14em;
font-size: 1.5em;
padding: 1em 1em .25em 1em;
border-bottom: 2px solid #2c2c2c;
border-radius: 0 0 .3em 0;
}
#u2body {
display: none;
}
#u2form {
width: 2px;
height: 2px;
overflow: hidden;
}
#u2btn {
color: #eee;
background: #555;
background: -moz-linear-gradient(top, #367 0%, #489 50%, #38788a 51%, #367 100%);
background: -webkit-linear-gradient(top, #367 0%, #489 50%, #38788a 51%, #367 100%);
background: linear-gradient(to bottom, #367 0%, #489 50%, #38788a 51%, #367 100%);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#489', endColorstr='#38788a', GradientType=0);
text-decoration: none;
line-height: 1.5em;
border: 1px solid #222;
border-radius: .4em;
text-align: center;
font-size: 2em;
margin: 1em auto;
padding: 1em 0;
width: 15em;
cursor: pointer;
box-shadow: .4em .4em 0 #111;
}
#u2tab {
margin: 3em auto;
width: calc(100% - 2em);
max-width: 100em;
}
#u2tab td {
border: 1px solid #ccc;
border-width: 0 0px 1px 0;
padding: .1em .3em;
}
#u2tab td:nth-child(2) {
width: 5em;
}
#u2tab td:nth-child(3) {
width: 40%;
}
#u2tab tr+tr:hover td {
background: #fea;
}
#u2conf {
margin: 1em auto;
width: 30em;
}
#u2conf * {
text-align: center;
line-height: 1em;
margin: 0;
padding: 0;
border: none;
outline: none;
}
#u2conf input {
width: 4em;
color: #fff;
background: #444;
border: 1px solid #777;
font-size: 1.2em;
padding: .15em 0;
}
#u2conf a {
color: #fff;
background: #c38;
text-decoration: none;
border-radius: .1em;
font-size: 1.5em;
padding: .1em 0;
margin: 0 -.25em;
width: 1.5em;
height: 1em;
display: inline-block;
position: relative;
line-height: 1em;
bottom: -.08em;
}
#u2conf input+a {
background: #d80;
}
.prog>div {
display: inline-block;
position: relative;
overflow: hidden;
margin: 0;
padding: 0;
height: 1.1em;
margin-bottom: -.15em;
box-shadow: -.1em -.1em .2em inset rgba(0,0,0,0.2);
}
.prog>div>div {
width: 0%;
position: absolute;
left: 0;
top: 0;
bottom: 0;
background: #0a0;
}

50
copyparty/web/upload.html Normal file
View file

@ -0,0 +1,50 @@
<div id="bup">
<form method="post" enctype="multipart/form-data" accept-charset="utf-8" action="/{{ vdir }}">
<input type="hidden" name="act" value="bput" />
<input type="file" name="f" multiple><br />
<input type="submit" value="start upload">
</form>
</div>
<div id="up2k">
<a href="#" id="u2tgl">upload</a>
<div id="u2body">
<form id="u2form" method="POST" enctype="multipart/form-data" onsubmit="return false;"></form>
<table id="u2conf">
<tr>
<td>parallel uploads</td>
<td>file split (megabyte)</td>
</tr>
<tr>
<td>
<a href="#" onclick="nthread_sub()">&ndash;</a>
<input id="nthread" value="2" />
<a href="#" onclick="nthread_add()">+</a>
</td>
<td>
<a href="#" onclick="chunksz_sub()">&ndash;</a>
<input id="chunksz" value="8" />
<a href="#" onclick="chunksz_add()">+</a>
</td>
</tr>
</table>
<div id="u2btn">
drop files here<br />
(or click me)
</div>
<table id="u2tab">
<tr>
<td>filename</td>
<td>status</td>
<td>progress</td>
</tr>
</table>
switch to the <a href="#" id="u2nope">basic uploader</a>
</div>
</div>