setup upload func

main
lza_menace 2 years ago
parent 9828b767b3
commit 24cfc1aa8c

@ -1,6 +1,8 @@
from web3.auto import w3 from web3.auto import w3
from eth_account.messages import encode_defunct from eth_account.messages import encode_defunct
from flipbook import config
def verify_signature(message, signature, public_address): def verify_signature(message, signature, public_address):
msg = encode_defunct(text=message) msg = encode_defunct(text=message)
@ -9,3 +11,7 @@ def verify_signature(message, signature, public_address):
return True return True
else: else:
return False return False
def allowed_file(filename):
return "." in filename and \
filename.rsplit(".", 1)[1].lower() in config.ALLOWED_EXTENSIONS

@ -1,5 +1,12 @@
from quart import Blueprint, render_template, request, redirect, url_for, flash from secrets import token_urlsafe
from flask_login import login_required from pathlib import Path
from quart import Blueprint, render_template, request, redirect, url_for, flash, send_from_directory
from flask_login import login_required, current_user
from werkzeug.utils import secure_filename
from flipbook.helpers import allowed_file
from flipbook import config
bp = Blueprint('manage', 'manage', url_prefix='/manage') bp = Blueprint('manage', 'manage', url_prefix='/manage')
@ -12,4 +19,35 @@ async def index():
@bp.route('/upload', methods=['GET', 'POST']) @bp.route('/upload', methods=['GET', 'POST'])
@login_required @login_required
async def upload(): async def upload():
return await render_template('upload.html') if request.method == "POST":
data = await request.get_data()
print(data)
post_title = request.form.get("title")
if "file" not in request.files:
await flash("You didn't upload a caliente meme, bro! You're fuckin up!", "is-danger")
return await redirect(request.url)
file = request.files["file"]
if file.filename == "":
await flash("You didn't upload a caliente meme, bro! You're fuckin up!", "is-danger")
return await redirect(request.url)
if post_title == "":
await flash("You didn't give your meme a spicy title, bro! You're fuckin up!", "is-danger")
return await redirect(request.url)
if file and allowed_file(file.filename):
filename = "{}-{}".format(
token_urlsafe(12),
secure_filename(file.filename)
)
file.save(Path(config.UPLOADS_PATH, filename))
upload = Upload(
token_id=0,
title=post_title,
image_name=filename,
text=request.form.get('text', ''),
wallet=current_user,
)
upload.save()
# upload.save_thumbnail()
await flash("Uploaded successfully!", "is-success")
return redirect(url_for("manage.index"))
return render_template("upload.html")

@ -5,6 +5,7 @@
<li><a href="/">Home</a></li> <li><a href="/">Home</a></li>
{% if current_user.is_authenticated %} {% if current_user.is_authenticated %}
<li><a href="{{ url_for('manage.index') }}" class="button">Manage</a></li> <li><a href="{{ url_for('manage.index') }}" class="button">Manage</a></li>
<li><a href="{{ url_for('manage.upload') }}" class="button">upload</a></li>
<li><a href="{{ url_for('meta.logout') }}" class="button">Logout</a></li> <li><a href="{{ url_for('meta.logout') }}" class="button">Logout</a></li>
{% else %} {% else %}
<li><a href="#" id="connectWallet" class="button">Connect</a></li> <li><a href="#" id="connectWallet" class="button">Connect</a></li>

Loading…
Cancel
Save