|
|
@ -19,7 +19,7 @@ bp = Blueprint('meme', 'meme')
|
|
|
|
@bp.route('/')
|
|
|
|
@bp.route('/')
|
|
|
|
def index():
|
|
|
|
def index():
|
|
|
|
memes = Meme.query.filter(
|
|
|
|
memes = Meme.query.filter(
|
|
|
|
Meme.meta_ipfs_hash != None
|
|
|
|
Meme.approved == True
|
|
|
|
).order_by(Meme.create_date.desc())
|
|
|
|
).order_by(Meme.create_date.desc())
|
|
|
|
w3 = Web3(Web3.HTTPProvider('http://127.0.0.1:9650'))
|
|
|
|
w3 = Web3(Web3.HTTPProvider('http://127.0.0.1:9650'))
|
|
|
|
contract_address = w3.toChecksumAddress(config.CONTRACT_ADDRESS)
|
|
|
|
contract_address = w3.toChecksumAddress(config.CONTRACT_ADDRESS)
|
|
|
@ -38,7 +38,7 @@ def mod():
|
|
|
|
flash('You are not a moderator', 'warning')
|
|
|
|
flash('You are not a moderator', 'warning')
|
|
|
|
return redirect(url_for('meme.index'))
|
|
|
|
return redirect(url_for('meme.index'))
|
|
|
|
memes = Meme.query.filter(
|
|
|
|
memes = Meme.query.filter(
|
|
|
|
Meme.meta_ipfs_hash == None
|
|
|
|
Meme.approved != True
|
|
|
|
).order_by(Meme.create_date.asc())
|
|
|
|
).order_by(Meme.create_date.asc())
|
|
|
|
return render_template('index.html', memes=memes)
|
|
|
|
return render_template('index.html', memes=memes)
|
|
|
|
|
|
|
|
|
|
|
@ -105,10 +105,10 @@ def show(meme_id):
|
|
|
|
meme = Meme.query.filter(Meme.id == meme_id).first()
|
|
|
|
meme = Meme.query.filter(Meme.id == meme_id).first()
|
|
|
|
if not meme:
|
|
|
|
if not meme:
|
|
|
|
return redirect('/')
|
|
|
|
return redirect('/')
|
|
|
|
if not meme.meta_ipfs_hash and not current_user.is_authenticated:
|
|
|
|
if not meme.approved and not current_user.is_authenticated:
|
|
|
|
flash('You need to be a moderator to view that meme.', 'warning')
|
|
|
|
flash('You need to be logged in to view that meme.', 'warning')
|
|
|
|
return redirect(url_for('meme.index'))
|
|
|
|
return redirect(url_for('meme.index'))
|
|
|
|
elif not meme.meta_ipfs_hash and not current_user.is_moderator():
|
|
|
|
elif not meme.approved and not current_user.is_moderator():
|
|
|
|
flash('You need to be a moderator to view that meme.', 'warning')
|
|
|
|
flash('You need to be a moderator to view that meme.', 'warning')
|
|
|
|
return redirect(url_for('meme.index'))
|
|
|
|
return redirect(url_for('meme.index'))
|
|
|
|
return render_template('meme.html', meme=meme)
|
|
|
|
return render_template('meme.html', meme=meme)
|
|
|
@ -126,8 +126,8 @@ def approve(meme_id, action):
|
|
|
|
if not meme:
|
|
|
|
if not meme:
|
|
|
|
flash('That meme does not exist.', 'warning')
|
|
|
|
flash('That meme does not exist.', 'warning')
|
|
|
|
return redirect(url_for('meme.index'))
|
|
|
|
return redirect(url_for('meme.index'))
|
|
|
|
if meme.meta_ipfs_hash != None:
|
|
|
|
if meme.approved is True:
|
|
|
|
flash('That meme already has been published to IPFS.', 'warning')
|
|
|
|
flash('That meme already has been approved.', 'warning')
|
|
|
|
return redirect(url_for('meme.show', meme_id=meme.id))
|
|
|
|
return redirect(url_for('meme.show', meme_id=meme.id))
|
|
|
|
if action == 'approve':
|
|
|
|
if action == 'approve':
|
|
|
|
res = upload_to_ipfs(meme.id)
|
|
|
|
res = upload_to_ipfs(meme.id)
|
|
|
@ -145,8 +145,9 @@ def approve(meme_id, action):
|
|
|
|
return redirect(url_for('meme.show', meme_id=meme.id))
|
|
|
|
return redirect(url_for('meme.show', meme_id=meme.id))
|
|
|
|
meme.meta_ipfs_hash = res[0]
|
|
|
|
meme.meta_ipfs_hash = res[0]
|
|
|
|
meme.meme_ipfs_hash = res[1]
|
|
|
|
meme.meme_ipfs_hash = res[1]
|
|
|
|
|
|
|
|
meme.approved = True
|
|
|
|
db.session.commit()
|
|
|
|
db.session.commit()
|
|
|
|
flash('Published new meme to IPFS.', 'success')
|
|
|
|
flash('Approved meme and published new meme to local IPFS server.', 'success')
|
|
|
|
elif action == 'deny':
|
|
|
|
elif action == 'deny':
|
|
|
|
# delete image
|
|
|
|
# delete image
|
|
|
|
# delete from database
|
|
|
|
# delete from database
|
|
|
|