Skip to content

Commit a17b11d

Browse files
committed
Base commit
1 parent 77d3df6 commit a17b11d

File tree

10 files changed

+324
-2
lines changed

10 files changed

+324
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,6 @@ venv.bak/
102102

103103
# mypy
104104
.mypy_cache/
105+
106+
# Emacs
107+
*~

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
# FileHosting
2-
A simple file hosting service
1+
# PyFileHosting
2+
3+
A simple file hosting service based on Python (Flask). Programmed for fun.
4+
All hail the Pizza God.

main.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from flask import Flask, render_template, request, url_for
2+
from random import sample
3+
import string
4+
from werkzeug.utils import secure_filename
5+
6+
app = Flask(__name__)
7+
app.config["UPLOAD_FOLDER"] = "/home/soham/Documents/Projects/Python-Projects/PyFileHosting/uploads"
8+
app.config['MAX_CONTENT_LENGTH'] = 100 * 1024 * 1024 # Max 100 MB.
9+
ALLOWED_EXTENSIONS = [
10+
'js', 'css', 'html', 'json', 'txt', 'mp4', 'avi', 'flv', 'mov', 'wmv'
11+
'png', 'jpg', 'jpeg', 'gif', 'tiff', 'bmp', 'mp3', 'wav', 'flac', 'aac',
12+
'ogg', 'alac', 'zip', '7z', 'rar', 'whatever']
13+
14+
15+
@app.route('/', methods=['GET', 'POST'])
16+
def index():
17+
return render_template('index.html', allowed_ext=", ".join(ALLOWED_EXTENSIONS))
18+
19+
20+
@app.route('/upload', methods=['POST'])
21+
def upload():
22+
fileob = request.files["file"]
23+
fext = secure_filename(fileob.filename).split('.')[-1]
24+
if fext.lower() not in ALLOWED_EXTENSIONS:
25+
return "Error: Filename extension not allowed."
26+
filename = "{}.{}".format(''.join(sample(string.ascii_letters + string.digits, 6)), fext)
27+
save_path = "{}/{}".format(app.config["UPLOAD_FOLDER"], filename)
28+
fileob.save(save_path)
29+
return '/files/' + filename

main.py~

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from flask import Flask, render_template, request, url_for
2+
from werkzeug.utils import secure_filename
3+
4+
app = Flask(__name__)
5+
app.config["UPLOAD_FOLDER"] = "/home/soham/Documents/Projects/Python-Projects/PyFileHosting/uploads"
6+
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
7+
8+
9+
@app.route('/', methods=['GET', 'POST'])
10+
def index():
11+
return render_template('index.html')
12+
13+
14+
@app.route('/upload', methods=['POST'])
15+
def upload():
16+
fileob = request.files["uploadedfile"]
17+
filename = secure_filename(fileob.filename)
18+
save_path = "{}/{}".format(app.config["UPLOAD_FOLDER"], filename)
19+
fileob.save(save_path)
20+
return '/uploads/' + filename

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
flask
2+
uwsgi

run

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
export FLASK_APP="main.py"
3+
"$@"

static/paste.js

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/index.html

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, height=device-height, user-scalable=no, initial-scale=1.0"/>
6+
<title>We 🖤 Pizzas</title>
7+
<meta name="description" content="We all love pizzas. This is a website dedicated to the Flying Pizza Monster."/>
8+
<link rel="canonical" href="https://we-love.pizza"/>
9+
<link href="https://fonts.googleapis.com/css?family=Quicksand" rel="stylesheet">
10+
<style>
11+
body {margin: 5% auto; background: #000000; color: #f80000; font-family: 'Quicksand', sans-serif; font-size: 16px; line-height: 1.8; max-width: 73%;}
12+
a {border-bottom: 1px solid #ddd; color: #fff; text-decoration: none;}
13+
a:hover {border-bottom: 0;}
14+
h1, h2, h3, h4 {text-align: center;}
15+
h1 {font-size: 3em;}
16+
hr {width: 50%; color: #bb0000;}
17+
.faq-container {padding: 15px 10px 50px 10px;}
18+
.faq-container p {color: #f2f2f2;}
19+
.upload-container {min-height: 60vh;}
20+
.drop-container {width: 100%;display:flex;justify-content:center;align-items:center;}
21+
.drop-area {display:flex;justify-content:center;align-items:center;width:300px;height:300px;border: 4px dashed #f80000;color: #ddd;padding: 50px; font-size: 2.8 em;text-transform: uppercase;margin: 50px;}
22+
.drop-area p{text-align: center;}
23+
#file-input::-webkit-file-upload-button{display: none;}
24+
#file-input {width: 100%;}
25+
#file-input::before {content: "Select a file";display:block;text-align:center;width:100%;text-transform:uppercase;padding-top:10px;padding-bottom:10px;background-color:#ddd;color:#000;font-size:1.2em;font-family:'Quicksand', sans-serif;}
26+
pre {color: #f2f2f2;background-color:#333;padding: 10px 20px;font-size:14px;font-family: "Lucida Console", Monaco, monospace;overflow-x: auto;white-space: pre-wrap;white-space: -moz-pre-wrap;white-space: -pre-wrap;word-wrap: break-word;}
27+
</style>
28+
</head>
29+
<body>
30+
<div class="upload-container">
31+
<h1>All Hail, The Flying Pizza Monster</h1>
32+
<h4>The Flying Pizza Monster has heard your prayers. You can now send your files and they'll be available for eternity*</h4>
33+
<div class="drop-container">
34+
<div class="drop-area">
35+
<form method="post" enctype="multipart/form-data" action="upload">
36+
<input type="file" value="Upload" name="file" id="file-input">
37+
<p>
38+
Or Drag-n-Drop your file here,<br>
39+
Or do Ctrl-V (Only for images).
40+
</p>
41+
</form>
42+
</div>
43+
</div>
44+
</div>
45+
<hr>
46+
<div class="faq-container">
47+
<h2>Q&A</h2>
48+
<p>
49+
<b>Q: What is this?</b><br>
50+
A: A file hosting platform, duh. Check below for supported formats. Oh, and 100 MB is the limit. In case someone abuses this file hosting service, they'll get IP blocked. And TBH, this site is not worth enough to use a DDoS, or proxies.
51+
</p>
52+
<p>
53+
<b>Q: Who made this?</b><br>
54+
A: A friend of the Flying Pizza Monster, <b>RandomGhost#0666</b>.
55+
</p>
56+
<p>
57+
<b>Q: Is there an API?</b><br>
58+
A: Yes:
59+
<pre>
60+
API PATH: {{request.base_url}}upload
61+
METHOD: POST
62+
POST DATA ->
63+
FILE=(The file to upload. Proper extension as given below and less than 100 MB.)
64+
CURL EXAMPLE: curl -F 'file=@/path/to/file.extension' '{{request.base_url}}upload'</pre>
65+
</p>
66+
<p>
67+
<b>Q: What kind of content does the Flying Pizza Monster hate?</b><br>
68+
A: Anything that violates the T&C of other file hosting services and/or violates the law.
69+
</p>
70+
<p>
71+
<b>Q: I found a file which might anger the Flying Pizza Monster.</b><br>
72+
A: Mail me @ <a href="mailto:randomghost@pm.me">randomghost@pm.me</a>. I will remove it before His Holiness sets his eyes on its uploader.
73+
</p>
74+
<p>
75+
<b>Supported Extensions:</b><br>
76+
{{ allowed_ext }}
77+
</p>
78+
</div>
79+
<hr>
80+
<h4 style="color: #fff;">By a random ghost. More specifically, <b><a href="">RandomGhost#0666</a></b>.</h4>
81+
</body>
82+
<script
83+
src="http://code.jquery.com/jquery-3.3.1.min.js"
84+
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
85+
crossorigin="anonymous"></script>
86+
<script type="text/javascript">
87+
var dragHandler = function(evt){
88+
evt.preventDefault();
89+
};
90+
var dropHandler = function(evt){
91+
evt.preventDefault();
92+
var files = evt.originalEvent.dataTransfer.files;
93+
uploadFile(files[0]);
94+
};
95+
96+
function uploadFile(file) {
97+
var formData = new FormData();
98+
formData.append("file", file);
99+
var req = {
100+
url: '/upload',
101+
method: "POST",
102+
processData: false,
103+
contentType: false,
104+
data: formData,
105+
success: function(result) {
106+
if (result.startsWith("Error")) alert(result);
107+
else window.open(result, '_self');
108+
}
109+
};
110+
var promise = $.ajax(req);
111+
}
112+
var dropHandlerSet = {
113+
dragover: dragHandler,
114+
drop: dropHandler
115+
};
116+
$(".drop-area").on(dropHandlerSet);
117+
$('input[type="file"]').change( function () {
118+
uploadFile(this.files[0]);
119+
});
120+
$(document).on('paste', function (evt) {
121+
uploadFile(evt.originalEvent.clipboardData.files[0]);
122+
});
123+
</script>
124+
</html>

0 commit comments

Comments
 (0)