|
|
@ -15,40 +15,41 @@ bp = Blueprint('manage', 'manage', url_prefix='/manage')
|
|
|
|
@bp.route('')
|
|
|
|
@bp.route('')
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|
async def index():
|
|
|
|
async def index():
|
|
|
|
return await render_template('manage.html')
|
|
|
|
uploads = Upload.select().where(
|
|
|
|
|
|
|
|
Upload.wallet == current_user
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
return await render_template(
|
|
|
|
|
|
|
|
'manage.html',
|
|
|
|
|
|
|
|
uploads=uploads
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/upload', methods=['GET', 'POST'])
|
|
|
|
@bp.route('/upload', methods=['GET', 'POST'])
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|
async def upload():
|
|
|
|
async def upload():
|
|
|
|
if request.method == 'POST':
|
|
|
|
if request.method == 'POST':
|
|
|
|
data = await request.form
|
|
|
|
data = await request.form
|
|
|
|
file = await request.files
|
|
|
|
file = list((await request.files).items())[0][1]
|
|
|
|
post_title = data['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 == '':
|
|
|
|
if file.filename == '':
|
|
|
|
await flash('You didn\'t upload a caliente meme, bro! You\'re fuckin up!', 'is-danger')
|
|
|
|
await flash('Must upload an image.', 'is-danger')
|
|
|
|
return await redirect(request.url)
|
|
|
|
return redirect(request.url)
|
|
|
|
if post_title == '':
|
|
|
|
if data['title'] == '':
|
|
|
|
await flash('You didn\'t give your meme a spicy title, bro! You\'re fuckin up!', 'is-danger')
|
|
|
|
await flash('Must set a title', 'is-danger')
|
|
|
|
return await redirect(request.url)
|
|
|
|
return redirect(request.url)
|
|
|
|
if file and allowed_file(file.filename):
|
|
|
|
if file and allowed_file(file.filename):
|
|
|
|
filename = '{}-{}'.format(
|
|
|
|
filename = '{}-{}'.format(
|
|
|
|
token_urlsafe(12),
|
|
|
|
token_urlsafe(12),
|
|
|
|
secure_filename(file.filename)
|
|
|
|
secure_filename(file.filename)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
file.save(Path(config.UPLOADS_PATH, filename))
|
|
|
|
await file.save(Path(config.UPLOADS_PATH, filename))
|
|
|
|
upload = Upload(
|
|
|
|
upload = Upload(
|
|
|
|
token_id=0,
|
|
|
|
token_id=0,
|
|
|
|
title=post_title,
|
|
|
|
title=data['title'],
|
|
|
|
image_name=filename,
|
|
|
|
image_name=filename,
|
|
|
|
text=data['text'],
|
|
|
|
text=data['text'],
|
|
|
|
wallet=current_user,
|
|
|
|
wallet=current_user
|
|
|
|
)
|
|
|
|
)
|
|
|
|
upload.save()
|
|
|
|
upload.save()
|
|
|
|
# upload.save_thumbnail()
|
|
|
|
upload.save_thumbnail()
|
|
|
|
await flash('Uploaded successfully!', 'is-success')
|
|
|
|
await flash('Uploaded successfully!', 'is-success')
|
|
|
|
return redirect(url_for('manage.index'))
|
|
|
|
return redirect(url_for('manage.index'))
|
|
|
|
return render_template('upload.html')
|
|
|
|
return render_template('upload.html')
|