get avax chain sync working

main
lza_menace 3 years ago
parent 19738fccc5
commit 6170af215a

@ -0,0 +1,27 @@
"""add meme sync flag
Revision ID: f6f695a38339
Revises: f15cd9fa0f06
Create Date: 2021-12-31 11:05:28.153450
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'f6f695a38339'
down_revision = 'f15cd9fa0f06'
branch_labels = None
depends_on = None
def upgrade():
with op.batch_alter_table('memes', schema=None) as batch_op:
batch_op.add_column(sa.Column('synced', sa.Boolean(), nullable=True))
def downgrade():
with op.batch_alter_table('memes', schema=None) as batch_op:
batch_op.drop_column('synced')

@ -47,13 +47,25 @@ def sync_avax():
db.session.commit() db.session.commit()
print(f'[+] Created user {user_exists.handle}') print(f'[+] Created user {user_exists.handle}')
res = requests.get(f'{config.IPFS_SERVER}/ipfs/{deets[5]}', timeout=30).json() res = requests.get(f'{config.IPFS_SERVER}/ipfs/{deets[5]}', timeout=30).json()
if not 'image' in res:
print('No image IPFS hash, skipping')
continue
meme_ipfs_hash = res['image'].split('ipfs://')[1]
filename = token_urlsafe(24)
print(f'[+] Downloading image hash {meme_ipfs_hash} as {filename}')
r = requests.get(f'{config.IPFS_SERVER}/ipfs/{meme_ipfs_hash}', stream=True)
with open(f'{config.DATA_FOLDER}/uploads/{filename}', 'wb') as f:
for chunk in r.iter_content(chunk_size = 16*1024):
f.write(chunk)
meme = Meme( meme = Meme(
title=res['name'], title=res['name'],
file_name=filename,
description=res['description'], description=res['description'],
user_id=user_exists.id, user_id=user_exists.id,
meta_ipfs_hash=deets[5], meta_ipfs_hash=deets[5],
meme_ipfs_hash=res['image'].split('ipfs://')[1], meme_ipfs_hash=meme_ipfs_hash,
minted=True minted=True,
synced=True
) )
db.session.add(meme) db.session.add(meme)
db.session.commit() db.session.commit()

@ -103,6 +103,7 @@ class Meme(db.Model):
description = db.Column(db.String(400), nullable=True) description = db.Column(db.String(400), nullable=True)
minted = db.Column(db.Boolean, default=False) minted = db.Column(db.Boolean, default=False)
approved = db.Column(db.Boolean, default=False) approved = db.Column(db.Boolean, default=False)
synced = db.Column(db.Boolean, default=False)
user_id = db.Column(db.Integer, db.ForeignKey('users.id')) user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
user = db.relationship('User', back_populates='memes') user = db.relationship('User', back_populates='memes')

@ -26,8 +26,11 @@ def index():
@bp.route('/mod') @bp.route('/mod')
def mod(): def mod():
if not current_user.is_authenticated:
flash('You must be logged in and have MetaMask wallet connected.', 'warning')
return redirect(url_for('meme.index'))
if not current_user.is_moderator(): if not current_user.is_moderator():
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.approved != True Meme.approved != True
@ -133,8 +136,9 @@ def approve(meme_id, action):
existing_meme_ipfs = Meme.query.filter( existing_meme_ipfs = Meme.query.filter(
Meme.meme_ipfs_hash == res[1] Meme.meme_ipfs_hash == res[1]
).first() ).first()
if meme.synced is False:
if existing_meta_ipfs or existing_meme_ipfs: if existing_meta_ipfs or existing_meme_ipfs:
flash('Cannot use an existing IPFS hash for either metadata or memes.', 'warning') # noqa flash('Cannot use an existing IPFS hash for either metadata or memes on new posts.', 'warning') # noqa
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]

Loading…
Cancel
Save