referral sales
This commit is contained in:
parent
7baac11834
commit
7448023642
|
|
@ -14,6 +14,7 @@ from app.core.logger import make_log
|
|||
from app.core._utils.resolve_content import resolve_content
|
||||
from app.core.content.utils import create_metadata_for_item
|
||||
from app.core._crypto.content import create_encrypted_content
|
||||
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
|
||||
|
|
@ -120,8 +121,8 @@ async def s_api_v1_blockchain_send_new_content_message(request):
|
|||
begin_cell()
|
||||
.store_ref(
|
||||
begin_cell()
|
||||
.store_coins(int(30000000))
|
||||
.store_coins(int(30000000))
|
||||
.store_coins(int(0))
|
||||
.store_coins(int(0))
|
||||
.store_coins(int(request.json['price']))
|
||||
.end_cell()
|
||||
)
|
||||
|
|
@ -163,14 +164,23 @@ async def s_api_v1_blockchain_send_purchase_content_message(request):
|
|||
assert field_key in request.json, f"No {field_key} provided"
|
||||
assert field_value(request.json[field_key]), f"Invalid {field_key} provided"
|
||||
|
||||
r_content = StoredContent.from_cid(request.ctx.db_session, request.json['content_address'])
|
||||
license_exist = request.ctx.db_session.query(UserContent).filter_by(
|
||||
onchain_address=request.json['content_address'],
|
||||
).first()
|
||||
if license_exist:
|
||||
r_content = StoredContent.from_cid(request.ctx.db_session, license_exist.content.cid.serialize_v2())
|
||||
else:
|
||||
r_content = StoredContent.from_cid(request.ctx.db_session, request.json['content_address'])
|
||||
|
||||
content = r_content.open_content(request.ctx.db_session)
|
||||
|
||||
licenses_cost = content['encrypted_content'].json_format()['license']
|
||||
assert request.json['license_type'] in licenses_cost
|
||||
|
||||
return response.json({
|
||||
'address': content['encrypted_content'].json_format()['item_address'],
|
||||
'address': (
|
||||
license_exist.onchain_address if license_exist else content['encrypted_content'].json_format()['item_address']
|
||||
),
|
||||
'amount': str(int(licenses_cost['resale']['price'])),
|
||||
'payload': b64encode((
|
||||
begin_cell()
|
||||
|
|
|
|||
|
|
@ -37,6 +37,13 @@ async def s_api_v1_content_list(request):
|
|||
|
||||
async def s_api_v1_content_view(request, content_address: str):
|
||||
# content_address can be CID or TON address
|
||||
|
||||
license_exist = request.ctx.db_session.query(UserContent).filter_by(
|
||||
onchain_address=content_address,
|
||||
).first()
|
||||
if license_exist:
|
||||
content_address = license_exist.content.cid.serialize_v2()
|
||||
|
||||
r_content = StoredContent.from_cid(request.ctx.db_session, content_address)
|
||||
content = r_content.open_content(request.ctx.db_session)
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from app.core._keyboards import get_inline_keyboard
|
|||
from app.core.models.node_storage import StoredContent
|
||||
import json
|
||||
from app.core.logger import make_log
|
||||
from app.core.models.content.user_content import UserAction
|
||||
from app.core.models.content.user_content import UserAction, UserContent
|
||||
|
||||
from app.client_bot.routers.home import router as home_router
|
||||
from app.client_bot.routers.tonconnect import router as tonconnect_router
|
||||
|
|
@ -94,7 +94,17 @@ router.callback_query.register(t_callback_purchase_node_content, F.data.startswi
|
|||
async def t_inline_query_node_content(query: types.InlineQuery, memory=None, user=None, db_session=None, chat_wrap=None, **extra):
|
||||
make_log("OwnedContent", f"Inline query: {query.query}", level='info')
|
||||
try:
|
||||
args = query.query[1:]
|
||||
source_args = query.query[1:]
|
||||
source_args_ext = query.query
|
||||
|
||||
if query.query.startswith('Q'):
|
||||
license_onchain_address = query.query[1:]
|
||||
args = db_session.query(UserContent).filter_by(
|
||||
onchain_address=license_onchain_address,
|
||||
).first().content.cid.serialize_v2()
|
||||
else:
|
||||
args = query.query[1:]
|
||||
|
||||
cid = ContentId.deserialize(args)
|
||||
|
||||
content_list = []
|
||||
|
|
@ -174,7 +184,7 @@ async def t_inline_query_node_content(query: types.InlineQuery, memory=None, use
|
|||
|
||||
content_share_link = {
|
||||
'text': user.translated('p_shareLinkContext').format(title=' – '.join(audio_title)),
|
||||
'url': f"https://t.me/{CLIENT_TELEGRAM_BOT_USERNAME}/content?startapp={content.cid.serialize_v2()}"
|
||||
'url': f"https://t.me/{CLIENT_TELEGRAM_BOT_USERNAME}/content?startapp={source_args}"
|
||||
}
|
||||
|
||||
# Create inline query result using decrypted content's file_id
|
||||
|
|
@ -192,7 +202,7 @@ async def t_inline_query_node_content(query: types.InlineQuery, memory=None, use
|
|||
'audio': user.translated('shareTrack_button'),
|
||||
'video': user.translated('shareVideo_button'),
|
||||
}[content_type_declared],
|
||||
'switch_inline_query': f"C{content.cid.serialize_v2()}"
|
||||
'switch_inline_query': source_args_ext
|
||||
},
|
||||
{
|
||||
'text': user.translated('shareLink_button'),
|
||||
|
|
@ -201,7 +211,7 @@ async def t_inline_query_node_content(query: types.InlineQuery, memory=None, use
|
|||
],
|
||||
[{
|
||||
'text': user.translated('viewTrack_button'),
|
||||
'url': f"https://t.me/MY_Web3Bot/content?startapp={content.cid.serialize_v2()}"
|
||||
'url': f"https://t.me/MY_Web3Bot/content?startapp={source_args}"
|
||||
}]
|
||||
]),
|
||||
**result_kwargs
|
||||
|
|
@ -229,7 +239,7 @@ async def t_inline_query_node_content(query: types.InlineQuery, memory=None, use
|
|||
|
||||
[{
|
||||
'text': user.translated('viewTrack_button'),
|
||||
'url': f"https://t.me/MY_Web3Bot/content?startapp={content.cid.serialize_v2()}"
|
||||
'url': f"https://t.me/MY_Web3Bot/content?startapp={source_args}"
|
||||
}]
|
||||
]),
|
||||
**result_kwargs
|
||||
|
|
@ -248,5 +258,5 @@ async def t_chosen_inline_result_node_content(query: types.ChosenInlineResult, m
|
|||
# return await query.answer([])
|
||||
|
||||
|
||||
router.inline_query.register(t_inline_query_node_content, F.query.startswith('C'))
|
||||
router.inline_query.register(t_inline_query_node_content, F.query.startswith('C') | F.query.startswith('Q'))
|
||||
router.chosen_inline_result.register(t_chosen_inline_result_node_content, lambda: True)
|
||||
|
|
|
|||
|
|
@ -48,5 +48,5 @@ TONCENTER_HOST = os.getenv('TONCENTER_HOST', 'https://toncenter.com/api/v2/')
|
|||
TONCENTER_API_KEY = os.getenv('TONCENTER_API_KEY')
|
||||
TONCENTER_V3_HOST = os.getenv('TONCENTER_V3_HOST', 'https://toncenter.com/api/v3/')
|
||||
|
||||
MY_PLATFORM_CONTRACT = 'EQAGbwW0sFghy9N4MQ0Ozp8YOIr0lcMI8J5kbbydFnQtheMY'
|
||||
MY_PLATFORM_CONTRACT = 'EQAX3WA7bRzmof9HoFoWCclSW1d7T954Gzj1Hsgt40AtheMY'
|
||||
MY_FUND_ADDRESS = 'UQDarChHFMOI2On9IdHJNeEKttqepgo0AY4bG1trw8OAAwMY'
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ class PlayerTemplates:
|
|||
else:
|
||||
cd_log += "Can't decrypt content. "
|
||||
|
||||
user_existing_license = self.db_session.query(UserContent).filter_by(owner_address=user_wallet_address, status='active', content_id=content.id).first()
|
||||
|
||||
if local_content:
|
||||
content_meta = content.json_format()
|
||||
local_content_meta = local_content.json_format()
|
||||
|
|
@ -73,6 +75,8 @@ class PlayerTemplates:
|
|||
'text': self.user.translated('p_shareLinkContext').format(title=content_metadata_json.get('name', "")),
|
||||
'url': f"https://t.me/{CLIENT_TELEGRAM_BOT_USERNAME}/content?startapp={content.cid.serialize_v2()}"
|
||||
}
|
||||
if user_existing_license:
|
||||
content_share_link['url'] = f"https://t.me/{CLIENT_TELEGRAM_BOT_USERNAME}/content?startapp={user_existing_license.onchain_address}"
|
||||
|
||||
preview_content = db_session.query(StoredContent).filter(
|
||||
StoredContent.hash == converted_content['low_preview']
|
||||
|
|
@ -97,7 +101,7 @@ class PlayerTemplates:
|
|||
inline_keyboard_array.append([
|
||||
{
|
||||
'text': self.user.translated('shareTrack_button'),
|
||||
'switch_inline_query': f"C{content.cid.serialize_v2()}",
|
||||
'switch_inline_query': f"Q{user_existing_license.onchain_address}" if user_existing_license else f"C{content.cid.serialize_v2()}",
|
||||
},
|
||||
{
|
||||
'text': self.user.translated('shareLink_button'),
|
||||
|
|
@ -115,7 +119,7 @@ class PlayerTemplates:
|
|||
}])
|
||||
inline_keyboard_array.append([{
|
||||
'text': self.user.translated('openContractPage_button'),
|
||||
'url': f"https://tonscan.org/address/{content_meta['item_address']}"
|
||||
'url': f"https://tonviewer.com/{content_meta['item_address']}"
|
||||
}])
|
||||
elif content_type == 'video':
|
||||
# Processing video
|
||||
|
|
@ -132,7 +136,7 @@ class PlayerTemplates:
|
|||
inline_keyboard_array.append([
|
||||
{
|
||||
'text': self.user.translated('shareVideo_button'),
|
||||
'switch_inline_query': f"C{content.cid.serialize_v2()}",
|
||||
'switch_inline_query': f"Q{user_existing_license.onchain_address}" if user_existing_license else f"C{content.cid.serialize_v2()}",
|
||||
},
|
||||
{
|
||||
'text': self.user.translated('shareLink_button'),
|
||||
|
|
@ -151,7 +155,7 @@ class PlayerTemplates:
|
|||
}])
|
||||
inline_keyboard_array.append([{
|
||||
'text': self.user.translated('openContractPage_button'),
|
||||
'url': f"https://tonscan.org/address/{content_meta['item_address']}"
|
||||
'url': f"https://tonviewer.com/address/{content_meta['item_address']}"
|
||||
}])
|
||||
else:
|
||||
local_content = None
|
||||
|
|
@ -169,7 +173,7 @@ class PlayerTemplates:
|
|||
user_wallet_address = self.user.wallet_address(self.db_session)
|
||||
have_access = (
|
||||
(content.owner_address == user_wallet_address)
|
||||
or bool(self.db_session.query(UserContent).filter_by(owner_address=user_wallet_address, status='active', content_id=content.id).first())
|
||||
or bool(user_existing_license)
|
||||
or bool(self.db_session.query(StarsInvoice).filter(
|
||||
and_(
|
||||
StarsInvoice.user_id == self.user.id,
|
||||
|
|
@ -222,6 +226,3 @@ class PlayerTemplates:
|
|||
self.db_session.commit()
|
||||
|
||||
return r
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue