free upload & player
This commit is contained in:
1 parent
862683b36e
commit
d852913692
6 files changed
+254
-15
No files matched your search
@@ -3,6 +3,7 @@ from datetime import datetime
|
||||
import traceback
|
||||
|
||||
from sanic import response
|
||||
from sqlalchemy import and_
|
||||
from tonsdk.boc import begin_cell, begin_dict
|
||||
from tonsdk.utils import Address
|
||||
|
||||
@@ -18,6 +19,8 @@ from app.core.models.content.user_content import UserContent
|
||||
from app.core.models.node_storage import StoredContent
|
||||
from app.core.models._telegram import Wrapped_CBotChat
|
||||
from app.core._keyboards import get_inline_keyboard
|
||||
from app.core.models.promo import PromoAction
|
||||
from app.core.models.tasks import BlockchainTask
|
||||
|
||||
|
||||
def valid_royalty_params(royalty_params):
|
||||
@@ -101,6 +104,92 @@ async def s_api_v1_blockchain_send_new_content_message(request):
|
||||
)
|
||||
i += 1
|
||||
|
||||
promo_free_upload_available = (
|
||||
3 - (request.ctx.db_session.query(PromoAction).filter(
|
||||
PromoAction.user_internal_id == request.ctx.user.id,
|
||||
PromoAction.action_type == 'freeUpload',
|
||||
).count())
|
||||
)
|
||||
if request.ctx.db_session.query(BlockchainTask).filter(
|
||||
and_(
|
||||
BlockchainTask.user_id == request.ctx.user.id,
|
||||
BlockchainTask.status != 'done',
|
||||
)
|
||||
).first():
|
||||
make_log("Blockchain", f"User {request.ctx.user.id} already has a pending task", level='warning')
|
||||
promo_free_upload_available = 0
|
||||
|
||||
make_log("Blockchain", f"User {request.ctx.user.id} has {promo_free_upload_available} free uploads available", level='info')
|
||||
|
||||
if promo_free_upload_available > 0:
|
||||
promo_action = PromoAction(
|
||||
user_id = str(request.ctx.user.id),
|
||||
user_internal_id=request.ctx.user.id,
|
||||
action_type='freeUpload',
|
||||
action_ref=str(encrypted_content_cid.content_hash),
|
||||
created=datetime.now()
|
||||
)
|
||||
request.ctx.db_session.add(promo_action)
|
||||
|
||||
blockchain_task = BlockchainTask(
|
||||
destination=platform.address.to_string(1, 1, 1),
|
||||
payload=b64encode(
|
||||
begin_cell()
|
||||
.store_uint(0x5491d08c, 32)
|
||||
.store_uint(int.from_bytes(encrypted_content_cid.content_hash, "big", signed=False), 256)
|
||||
.store_address(Address(request.ctx.user.wallet_address(request.ctx.db_session)))
|
||||
.store_ref(
|
||||
begin_cell()
|
||||
.store_ref(
|
||||
begin_cell()
|
||||
.store_coins(int(0))
|
||||
.store_coins(int(0))
|
||||
.store_coins(int(request.json['price']))
|
||||
.end_cell()
|
||||
)
|
||||
.store_maybe_ref(royalties_dict.end_dict())
|
||||
.store_uint(0, 1)
|
||||
.end_cell()
|
||||
)
|
||||
.store_ref(
|
||||
begin_cell()
|
||||
.store_ref(
|
||||
begin_cell()
|
||||
.store_bytes(f"{PROJECT_HOST}/api/v1.5/storage/{metadata_content.cid.serialize_v2(include_accept_type=True)}".encode())
|
||||
.end_cell()
|
||||
)
|
||||
.store_ref(
|
||||
begin_cell()
|
||||
.store_ref(begin_cell().store_bytes(f"{encrypted_content_cid.serialize_v2()}".encode()).end_cell())
|
||||
.store_ref(begin_cell().store_bytes(f"{image_content_cid.serialize_v2() if image_content_cid else ''}".encode()).end_cell())
|
||||
.store_ref(begin_cell().store_bytes(f"{metadata_content.cid.serialize_v2()}".encode()).end_cell())
|
||||
.end_cell()
|
||||
)
|
||||
.end_cell()
|
||||
)
|
||||
.end_cell().to_boc(False)
|
||||
).decode(),
|
||||
epoch=None, seqno=None,
|
||||
created = datetime.now(),
|
||||
status='wait',
|
||||
user_id = request.ctx.user.id
|
||||
)
|
||||
request.ctx.db_session.add(blockchain_task)
|
||||
request.ctx.db_session.commit()
|
||||
|
||||
await request.ctx.user_uploader_wrapper.send_message(
|
||||
request.ctx.user.translated('p_uploadContentTxPromo').format(
|
||||
title=content_title,
|
||||
free_count=(promo_free_upload_available - 1)
|
||||
), message_type='hint', message_meta={
|
||||
'encrypted_content_hash': b58encode(encrypted_content_cid.content_hash).decode(),
|
||||
'hint_type': 'uploadContentTxRequested'
|
||||
}
|
||||
)
|
||||
return response.json({
|
||||
'promoUpload': True,
|
||||
})
|
||||
|
||||
await request.ctx.user_uploader_wrapper.send_message(
|
||||
request.ctx.user.translated('p_uploadContentTxRequested').format(
|
||||
title=content_title,
|
||||
@@ -117,6 +206,7 @@ async def s_api_v1_blockchain_send_new_content_message(request):
|
||||
begin_cell()
|
||||
.store_uint(0x5491d08c, 32)
|
||||
.store_uint(int.from_bytes(encrypted_content_cid.content_hash, "big", signed=False), 256)
|
||||
.store_uint(0, 2)
|
||||
.store_ref(
|
||||
begin_cell()
|
||||
.store_ref(
|
||||
|
||||
Reference in new issue
Block a user