|
|
|
@ -1,5 +1,12 @@
|
|
|
|
|
from quart import Blueprint, render_template, request, redirect, url_for, flash
|
|
|
|
|
from flask_login import login_required
|
|
|
|
|
from secrets import token_urlsafe
|
|
|
|
|
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')
|
|
|
|
@ -12,4 +19,35 @@ async def index():
|
|
|
|
|
@bp.route('/upload', methods=['GET', 'POST'])
|
|
|
|
|
@login_required
|
|
|
|
|
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")
|