Compare commits

...

3 Commits

Author SHA1 Message Date
Derek c001137094
Add eventlet as a dependency
You're not going to want to do shareing of large files
with synchronous workers, timeouts galore
2018-08-24 13:24:26 -07:00
Derek 838637de55
Fix "SERVE_DIR" config 2018-08-24 13:22:44 -07:00
Derek aa0921aae6
Fix redirects when hosted under non-root 2018-08-24 13:22:08 -07:00
5 changed files with 58 additions and 11 deletions

View File

@ -12,6 +12,7 @@ bcrypt = "*"
flask-migrate = "*"
click = "*"
flask-limiter = "*"
eventlet = "*"
[dev-packages]

52
Pipfile.lock generated
View File

@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "0d5dbb20521ef4c84be501e1e8244c768893c4b70ecf958bf657e9825c212d09"
"sha256": "2e5352c6c0be1150d27c750324f7c132acf21f9bb4c9dcd04c8370c96761400a"
},
"pipfile-spec": 6,
"requires": {
@ -108,6 +108,21 @@
"index": "pypi",
"version": "==6.7"
},
"dnspython": {
"hashes": [
"sha256:40f563e1f7a7b80dc5a4e76ad75c23da53d62f1e15e6e517293b04e1f84ead7c",
"sha256:861e6e58faa730f9845aaaa9c6c832851fbf89382ac52915a51f89c71accdd31"
],
"version": "==1.15.0"
},
"eventlet": {
"hashes": [
"sha256:c584163e006e613707e224552fafc63e4e0aa31d7de0ab18b481ac0b385254c8",
"sha256:d9d31a3c8dbcedbcce5859a919956d934685b17323fc80e1077cb344a2ffa68d"
],
"index": "pypi",
"version": "==0.24.1"
},
"flask": {
"hashes": [
"sha256:2271c0070dbcb5275fad4a82e29f23ab92682dc45f9dfbc22c02ba9b9322ce48",
@ -146,6 +161,30 @@
"index": "pypi",
"version": "==2.3.2"
},
"greenlet": {
"hashes": [
"sha256:0411b5bf0de5ec11060925fd811ad49073fa19f995bcf408839eb619b59bb9f7",
"sha256:131f4ed14f0fd28d2a9fa50f79a57d5ed1c8f742d3ccac3d773fee09ef6fe217",
"sha256:13510d32f8db72a0b3e1720dbf8cba5c4eecdf07abc4cb631982f51256c453d1",
"sha256:31dc4d77ef04ab0460d024786f51466dbbc274fda7c8aad0885a6df5ff8d642e",
"sha256:35021d9fecea53b21e4defec0ff3ad69a8e2b75aca1ceddd444a5ba71216547e",
"sha256:426a8ef9e3b97c27e841648241c2862442c13c91ec4a48c4a72b262ccf30add9",
"sha256:58217698193fb94f3e6ff57eed0ae20381a8d06c2bc10151f76c06bb449a3a19",
"sha256:5f45adbbb69281845981bb4e0a4efb8a405f10f3cd6c349cb4a5db3357c6bf93",
"sha256:5fdb524767288f7ad161d2182f7ed6cafc0a283363728dcd04b9485f6411547c",
"sha256:71fbee1f7ef3fb42efa3761a8faefc796e7e425f528de536cfb4c9de03bde885",
"sha256:80bd314157851d06f7db7ca527082dbb0ee97afefb529cdcd59f7a5950927ba0",
"sha256:b843c9ef6aed54a2649887f55959da0031595ccfaf7e7a0ba7aa681ffeaa0aa1",
"sha256:c6a05ef8125503d2d282ccf1448e3599b8a6bd805c3cdee79760fa3da0ea090e",
"sha256:deeda2769a52db840efe5bf7bdf7cefa0ae17b43a844a3259d39fb9465c8b008",
"sha256:e66f8b09eec1afdcab947d3a1d65b87b25fde39e9172ae1bec562488335633b4",
"sha256:e8db93045414980dbada8908d49dbbc0aa134277da3ff613b3e548cb275bdd37",
"sha256:f1cc268a15ade58d9a0c04569fe6613e19b8b0345b64453064e2c3c6d79051af",
"sha256:fe3001b6a4f3f3582a865b9e5081cc548b973ec20320f297f5e2d46860e9c703",
"sha256:fe85bf7adb26eb47ad53a1bae5d35a28df16b2b93b89042a3a28746617a4738d"
],
"version": "==0.4.14"
},
"gunicorn": {
"hashes": [
"sha256:aa8e0b40b4157b36a5df5e599f45c9c76d6af43845ba3b3b0efe2c70473c2471",
@ -186,6 +225,13 @@
],
"version": "==1.0"
},
"monotonic": {
"hashes": [
"sha256:23953d55076df038541e648a53676fb24980f7a1be290cdda21300b3bc21dfb0",
"sha256:552a91f381532e33cbd07c6a2655a21908088962bb8fa7239ecbcc6ad1140cc7"
],
"version": "==1.5"
},
"pycparser": {
"hashes": [
"sha256:99a8ca03e29851d96616ad0404b4aad7d9ee16f25c9f9708a11faf2810f7b226"
@ -214,9 +260,9 @@
},
"sqlalchemy": {
"hashes": [
"sha256:72325e67fb85f6e9ad304c603d83626d1df684fdf0c7ab1f0352e71feeab69d8"
"sha256:ef6569ad403520ee13e180e1bfd6ed71a0254192a934ec1dbd3dbf48f4aa9524"
],
"version": "==1.2.10"
"version": "==1.2.11"
},
"werkzeug": {
"hashes": [

View File

@ -31,5 +31,5 @@ It's easy peasy my dude
+ For production
```bash
pipenv run gunicorn notpiracyiswear:app
pipenv run gunicorn notpiracyiswear:app -k 'eventlet'
```

View File

@ -49,7 +49,7 @@ def login():
user = User.query.filter_by(username=username).first()
if user is None:
flash("username / password all fucked up", 'error')
return redirect(request.path)
return redirect(request.script_root + request.path)
if user.check_password(password) == True:
success = login_user(user)
@ -58,11 +58,11 @@ def login():
return redirect(request.args.get('next') or url_for('index'))
else:
flash("oof ouch u banned my dude", 'error')
return redirect(request.path)
return redirect(request.script_root + request.path)
else:
flash("username / password all fucked up", 'error')
return redirect(request.path)
return redirect(request.script_root + request.path)
@app.route('/signup', methods=['GET', 'POST'])
@limiter.limit("5/minute;1/second", exempt_when=lambda : request.method == 'GET')
@ -118,7 +118,7 @@ def newreferal():
@login_required
def browse(path = None):
# Search for files in path
searchpath = os.path.join('files', path) if path is not None else 'files'
searchpath = os.path.join(app.config['SERVE_DIR'], path) if path is not None else app.config['SERVE_DIR']
# 404 if no such path exists
if not os.path.exists(searchpath):
@ -144,7 +144,7 @@ def browse(path = None):
@app.route('/files/<path:path>')
@login_required
def files(path):
return send_from_directory('files', path)
return send_from_directory(app.config['SERVE_DIR'], path)
@app.errorhandler(404)
def page_not_found(e):
@ -156,7 +156,7 @@ def internal_error(e):
@app.errorhandler(429)
def rate_limit(e):
return render_template('429.html', back=request.path), 429
return render_template('429.html', back=request.script_root + request.path), 429
if __name__ == "__main__":
app.run()

View File

@ -9,7 +9,7 @@ import click
@click.option('--secret', help="Secret key to use. A random hex string will be generated if not provided")
@click.option('--db', 'connection', help="Database connection string. Defaults to \"sqlite:///test.db\"")
def main(serve_dir, secret=None, connection=None):
config = {"serve_dir": serve_dir, "SECRET_KEY": secret or secrets.token_hex(), "SQLALCHEMY_DATABASE_URI": connection or 'sqlite:///test.db'}
config = {"SERVE_DIR": serve_dir, "SECRET_KEY": secret or secrets.token_hex(), "SQLALCHEMY_DATABASE_URI": connection or 'sqlite:///test.db'}
with open('config.json', 'w') as f:
json.dump(config, f, indent=2)