mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 00:52:16 -06:00
static resources
This commit is contained in:
parent
b59deb8d8d
commit
afa4216591
1
.gitattributes
vendored
1
.gitattributes
vendored
|
@ -1,3 +1,4 @@
|
||||||
* text eol=lf
|
* text eol=lf
|
||||||
|
|
||||||
*.png binary
|
*.png binary
|
||||||
|
*.gif binary
|
||||||
|
|
|
@ -14,6 +14,7 @@ if PY2:
|
||||||
|
|
||||||
class EnvParams(object):
|
class EnvParams(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.mod = os.path.dirname(os.path.realpath(__file__))
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
self.cfg = os.path.normpath(os.environ["APPDATA"] + "/copyparty")
|
self.cfg = os.path.normpath(os.environ["APPDATA"] + "/copyparty")
|
||||||
elif sys.platform == "darwin":
|
elif sys.platform == "darwin":
|
||||||
|
|
|
@ -4,6 +4,7 @@ from __future__ import print_function
|
||||||
|
|
||||||
import time
|
import time
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import mimetypes
|
||||||
|
|
||||||
from .__init__ import *
|
from .__init__ import *
|
||||||
from .util import *
|
from .util import *
|
||||||
|
@ -84,9 +85,9 @@ class HttpCli(object):
|
||||||
|
|
||||||
return ret[:-4].decode("utf-8", "replace").split("\r\n")
|
return ret[:-4].decode("utf-8", "replace").split("\r\n")
|
||||||
|
|
||||||
def reply(self, body):
|
def reply(self, body, status="200 OK", mime="text/html"):
|
||||||
header = "HTTP/1.1 200 OK\r\nConnection: Keep-Alive\r\nContent-Type: text/html\r\nContent-Length: {0}\r\n\r\n".format(
|
header = "HTTP/1.1 {}\r\nConnection: Keep-Alive\r\nContent-Type: {}\r\nContent-Length: {}\r\n\r\n".format(
|
||||||
len(body)
|
status, mime, len(body)
|
||||||
).encode(
|
).encode(
|
||||||
"utf-8"
|
"utf-8"
|
||||||
)
|
)
|
||||||
|
@ -95,16 +96,43 @@ class HttpCli(object):
|
||||||
|
|
||||||
return body
|
return body
|
||||||
|
|
||||||
def loud_reply(self, body):
|
def loud_reply(self, body, **kwargs):
|
||||||
self.log(body.rstrip())
|
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):
|
def handle_get(self):
|
||||||
self.log("")
|
self.log("")
|
||||||
self.log("GET {0} {1}".format(self.addr[0], self.req))
|
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):
|
def handle_post(self):
|
||||||
self.log("")
|
self.log("")
|
||||||
|
|
BIN
copyparty/web/copyparty.gif
Normal file
BIN
copyparty/web/copyparty.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 126 B |
15
copyparty/web/splash.css
Normal file
15
copyparty/web/splash.css
Normal 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
19
copyparty/web/splash.html
Normal 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
1
copyparty/web/splash.js
Normal file
|
@ -0,0 +1 @@
|
||||||
|
document.getElementsByTagName('h1')[0].insertAdjacentHTML('afterend', '<img src="/copyparty.gif" />')
|
|
@ -52,12 +52,13 @@ EOF
|
||||||
chmod 600 ~/.pypirc
|
chmod 600 ~/.pypirc
|
||||||
sed -ri 's/qwer/username/;s/asdf/password/' ~/.pypirc
|
sed -ri 's/qwer/username/;s/asdf/password/' ~/.pypirc
|
||||||
|
|
||||||
# setup build env
|
# if PY2: create build env
|
||||||
cd ~/dev/copyparty &&
|
cd ~/dev/copyparty && virtualenv buildenv
|
||||||
virtualenv buildenv
|
(. buildenv/bin/activate && pip install m2r)
|
||||||
. buildenv/bin/activate
|
|
||||||
pip install m2r
|
# if PY3: create build env
|
||||||
deactivate
|
cd ~/dev/copyparty && python3 -m venv buildenv
|
||||||
|
(. buildenv/bin/activate && pip install m2r wheel)
|
||||||
|
|
||||||
# test rst
|
# test rst
|
||||||
pip install docutils
|
pip install docutils
|
||||||
|
|
3
setup.py
3
setup.py
|
@ -37,10 +37,11 @@ VERSION = None
|
||||||
data_files = [("share/doc/copyparty", ["README.rst", "README.md", "LICENSE"])]
|
data_files = [("share/doc/copyparty", ["README.rst", "README.md", "LICENSE"])]
|
||||||
manifest = ""
|
manifest = ""
|
||||||
for dontcare, files in data_files:
|
for dontcare, files in data_files:
|
||||||
# print(dontcare)
|
|
||||||
for fn in files:
|
for fn in files:
|
||||||
manifest += "include {0}\n".format(fn)
|
manifest += "include {0}\n".format(fn)
|
||||||
|
|
||||||
|
manifest += "recursive-include copyparty/web *\n"
|
||||||
|
|
||||||
here = os.path.abspath(os.path.dirname(__file__))
|
here = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
|
||||||
with open(here + "/MANIFEST.in", "wb") as f:
|
with open(here + "/MANIFEST.in", "wb") as f:
|
||||||
|
|
Loading…
Reference in a new issue