Skip to content

fyi: I integrated dropzonejs.com into droopy for nicer uploads #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions droopy
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ else:

import cgi
import os
import os.path
import posixpath
import macpath
import ntpath
Expand Down Expand Up @@ -212,6 +213,8 @@ class HTTPUploadHandler(httpserver.BaseHTTPRequestHandler):
auth = ''
certfile = None
divpicture = '<div class="box"><img src="/__droopy/picture"/></div>'
staticfolder = os.environ.get("DROOPY_STATIC",
os.path.join(os.path.dirname(os.path.realpath(__file__)), "static"))

def get_case_insensitive_header(self, hdrname, default):
"Python 2 and 3 differ in header capitalisation!"
Expand Down Expand Up @@ -300,6 +303,9 @@ class HTTPUploadHandler(httpserver.BaseHTTPRequestHandler):
if self.picture != None and self.path == '/__droopy/picture':
# send the picture
self.send_file(self.picture)
# serve static files
elif self.path.startswith('/static'):
self.send_file(os.path.join(self.staticfolder, self.path.lstrip('/static/')))
# TODO Verify that this is path-injection proof
elif name in self.published_files():
localpath = os.path.join(self.directory, name)
Expand Down Expand Up @@ -486,7 +492,7 @@ a {color: #4499cc; text-decoration: none;}
letter-spacing: -2px; line-height: 50px; color: #aaa;}
#sending {display: none; font-style: italic;}
#sending .text {padding-top: 10px; color: #bbb; font-size: 0.8em;}
#wrapform {height: 90px; padding-top:40px;}
#wrapform {padding-top:40px;}
#progress {display: inline; border-collapse: separate; empty-cells: show;
border-spacing: 24px 0; padding: 0; vertical-align: bottom;}
#progress td {height: 17px; width: 17px; background-color: #eee;
Expand Down Expand Up @@ -519,6 +525,7 @@ maintmpl = '''
<head>
<title>%(maintitle)s</title>
''' + style + '''
<link rel="stylesheet" href="/static/dropzone/dropzone.css">
<script language="JavaScript">
function swap() {
document.getElementById("form").style.display = "none";
Expand All @@ -539,15 +546,19 @@ function onunload() {
document.getElementById("form").style.display = "block";
document.getElementById("sending").style.display = "none";
}
</script></head>
</script>
</head>
<body>
%(linkurl)s
<div class="container">
<div id="wrapform">
<div id="form" class="box">
<form method="post" enctype="multipart/form-data" action="">
<form id="upload-form" method="post" enctype="multipart/form-data" action="" class="dropzone">
<!-- we only display the input elements if dropzone can't be used (no JS) -->
<div class="fallback">
<input name="upfile" type="file" multiple="yes">
<input value="%(submit)s" onclick="swap()" type="submit">
</div>
</form>
</div>
<div id="sending" class="box">
Expand All @@ -563,6 +574,16 @@ function onunload() {
''' + userinfo + '''
%(files)s
</div>
<script src="/static/dropzone/dropzone.js"></script>
<script>
Dropzone.autoDiscover = false;
var uploadDropzone = new Dropzone("#upload-form", {
url: "/",
paramName: "upfile",
// client-side filesize doesn’t make sense
maxFilesize: 10000000000000
});
</script>
</body>
</html>
'''
Expand Down
5 changes: 5 additions & 0 deletions man/droopy.1
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,10 @@ Save options in a configuration file.
Delete the configuration file and exit.
.SH EXAMPLE
droopy \-m "Hi, this is Bob. You can send me a file." \-p avatar.png
.SH ENVIRONMENT
.PP
\fI$DROOPY_STATIC\fR
.RS 4
Path to the static files (js/css).
.SH AUTHOR
Pierre Duquesne <[email protected]>
39 changes: 39 additions & 0 deletions static/dropzone/basic.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* The MIT License
* Copyright (c) 2012 Matias Meno <[email protected]>
*/
.dropzone, .dropzone * {
box-sizing: border-box; }

.dropzone {
position: relative; }
.dropzone .dz-preview {
position: relative;
display: inline-block;
width: 120px;
margin: 0.5em; }
.dropzone .dz-preview .dz-progress {
display: block;
height: 15px;
border: 1px solid #aaa; }
.dropzone .dz-preview .dz-progress .dz-upload {
display: block;
height: 100%;
width: 0;
background: green; }
.dropzone .dz-preview .dz-error-message {
color: red;
display: none; }
.dropzone .dz-preview.dz-error .dz-error-message, .dropzone .dz-preview.dz-error .dz-error-mark {
display: block; }
.dropzone .dz-preview.dz-success .dz-success-mark {
display: block; }
.dropzone .dz-preview .dz-error-mark, .dropzone .dz-preview .dz-success-mark {
position: absolute;
display: none;
left: 30px;
top: 30px;
width: 54px;
height: 58px;
left: 50%;
margin-left: -27px; }
Loading