mirror of
https://github.com/jwinterm/tubbymemes.git
synced 2026-10-17 05:21:28 +02:00
get avax chain sync working
This commit is contained in:
@@ -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')
|
||||
+14
-2
@@ -47,13 +47,25 @@ def sync_avax():
|
||||
db.session.commit()
|
||||
print(f'[+] Created user {user_exists.handle}')
|
||||
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(
|
||||
title=res['name'],
|
||||
file_name=filename,
|
||||
description=res['description'],
|
||||
user_id=user_exists.id,
|
||||
meta_ipfs_hash=deets[5],
|
||||
meme_ipfs_hash=res['image'].split('ipfs://')[1],
|
||||
minted=True
|
||||
meme_ipfs_hash=meme_ipfs_hash,
|
||||
minted=True,
|
||||
synced=True
|
||||
)
|
||||
db.session.add(meme)
|
||||
db.session.commit()
|
||||
|
||||
@@ -103,6 +103,7 @@ class Meme(db.Model):
|
||||
description = db.Column(db.String(400), nullable=True)
|
||||
minted = 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 = db.relationship('User', back_populates='memes')
|
||||
|
||||
|
||||
+10
-6
@@ -26,8 +26,11 @@ def index():
|
||||
|
||||
@bp.route('/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():
|
||||
flash('You are not a moderator', 'warning')
|
||||
flash('You are not a moderator.', 'warning')
|
||||
return redirect(url_for('meme.index'))
|
||||
memes = Meme.query.filter(
|
||||
Meme.approved != True
|
||||
@@ -133,11 +136,12 @@ def approve(meme_id, action):
|
||||
existing_meme_ipfs = Meme.query.filter(
|
||||
Meme.meme_ipfs_hash == res[1]
|
||||
).first()
|
||||
if existing_meta_ipfs or existing_meme_ipfs:
|
||||
flash('Cannot use an existing IPFS hash for either metadata or memes.', 'warning') # noqa
|
||||
return redirect(url_for('meme.show', meme_id=meme.id))
|
||||
meme.meta_ipfs_hash = res[0]
|
||||
meme.meme_ipfs_hash = res[1]
|
||||
if meme.synced is False:
|
||||
if existing_meta_ipfs or existing_meme_ipfs:
|
||||
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))
|
||||
meme.meta_ipfs_hash = res[0]
|
||||
meme.meme_ipfs_hash = res[1]
|
||||
meme.approved = True
|
||||
db.session.commit()
|
||||
flash('Approved meme and published new meme to local IPFS server.', 'success')
|
||||
|
||||
Reference in New Issue
Block a user