static resources

This commit is contained in:
ed 2019-06-02 14:16:53 +00:00
parent b59deb8d8d
commit afa4216591
9 changed files with 82 additions and 15 deletions

1
.gitattributes vendored
View file

@ -1,3 +1,4 @@
* text eol=lf
*.png binary
*.gif binary

View file

@ -14,6 +14,7 @@ if PY2:
class EnvParams(object):
def __init__(self):
self.mod = os.path.dirname(os.path.realpath(__file__))
if sys.platform == "win32":
self.cfg = os.path.normpath(os.environ["APPDATA"] + "/copyparty")
elif sys.platform == "darwin":

View file

@ -4,6 +4,7 @@ from __future__ import print_function
import time
import hashlib
import mimetypes
from .__init__ import *
from .util import *
@ -84,9 +85,9 @@ class HttpCli(object):
return ret[:-4].decode("utf-8", "replace").split("\r\n")
def reply(self, body):
header = "HTTP/1.1 200 OK\r\nConnection: Keep-Alive\r\nContent-Type: text/html\r\nContent-Length: {0}\r\n\r\n".format(
len(body)
def reply(self, body, status="200 OK", mime="text/html"):
header = "HTTP/1.1 {}\r\nConnection: Keep-Alive\r\nContent-Type: {}\r\nContent-Length: {}\r\n\r\n".format(
status, mime, len(body)
).encode(
"utf-8"
)
@ -95,16 +96,43 @@ class HttpCli(object):
return body
def loud_reply(self, body):
def loud_reply(self, body, **kwargs):
self.log(body.rstrip())
self.reply(b"<pre>" + body.encode("utf-8"))
self.reply(b"<pre>" + body.encode("utf-8"), **kwargs)
def send_file(self, path):
sz = os.path.getsize(path)
mime = mimetypes.guess_type(path)[0]
header = "HTTP/1.1 200 OK\r\nConnection: Keep-Alive\r\nContent-Type: {}\r\nContent-Length: {}\r\n\r\n".format(
mime, sz
).encode(
"utf-8"
)
if self.ok:
self.s.send(header)
with open(path, "rb") as f:
while self.ok:
buf = f.read(4096)
if not buf:
break
self.s.send(buf)
def handle_get(self):
self.log("")
self.log("GET {0} {1}".format(self.addr[0], self.req))
self.reply(
b'<form method="post" enctype="multipart/form-data"><h5><input type="file" name="f" multiple><h5><input type="submit" value="start upload">'
)
static_path = os.path.join(E.mod, "web", self.req.split("?")[0][1:])
if os.path.isfile(static_path):
return self.send_file(static_path)
if self.req == "/":
return self.send_file(os.path.join(E.mod, "web/splash.html"))
return self.loud_reply("404 not found", status="404 Not Found")
def handle_post(self):
self.log("")

BIN
copyparty/web/copyparty.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 B

15
copyparty/web/splash.css Normal file
View file

@ -0,0 +1,15 @@
html, body, #wrap {
color: #333;
background: #f7f7f7;
font-family: sans-serif;
}
#wrap {
max-width: 40em;
margin: 2em auto;
padding: 0 1em 3em 1em;
}
h1 {
border-bottom: 1px solid #ccc;
margin: 2em 0 .4em 0;
padding: 0 0 .2em 0;
}

19
copyparty/web/splash.html Normal file
View file

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>copyparty</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=0.8">
<link rel="stylesheet" type="text/css" media="screen" href="/splash.css">
</head>
<body>
<div id="wrap">
<h1>hello world</h1>
</div>
<script src="/splash.js"></script>
</body>
</html>

1
copyparty/web/splash.js Normal file
View file

@ -0,0 +1 @@
document.getElementsByTagName('h1')[0].insertAdjacentHTML('afterend', '<img src="/copyparty.gif" />')

View file

@ -52,12 +52,13 @@ EOF
chmod 600 ~/.pypirc
sed -ri 's/qwer/username/;s/asdf/password/' ~/.pypirc
# setup build env
cd ~/dev/copyparty &&
virtualenv buildenv
. buildenv/bin/activate
pip install m2r
deactivate
# if PY2: create build env
cd ~/dev/copyparty && virtualenv buildenv
(. buildenv/bin/activate && pip install m2r)
# if PY3: create build env
cd ~/dev/copyparty && python3 -m venv buildenv
(. buildenv/bin/activate && pip install m2r wheel)
# test rst
pip install docutils

View file

@ -37,10 +37,11 @@ VERSION = None
data_files = [("share/doc/copyparty", ["README.rst", "README.md", "LICENSE"])]
manifest = ""
for dontcare, files in data_files:
# print(dontcare)
for fn in files:
manifest += "include {0}\n".format(fn)
manifest += "recursive-include copyparty/web *\n"
here = os.path.abspath(os.path.dirname(__file__))
with open(here + "/MANIFEST.in", "wb") as f: