dowload & selectWallet & fixes & auth me
This commit is contained in:
parent
ac6d102a3f
commit
b02ded982c
|
|
@ -13,7 +13,7 @@ app.register_middleware(close_db_session, "response")
|
|||
|
||||
from app.api.routes._index import s_index, s_favicon
|
||||
from app.api.routes._system import s_api_v1_node, s_api_system_version, s_api_system_send_status, s_api_v1_node_friendly
|
||||
from app.api.routes.auth import s_api_v1_auth_twa, s_api_v1_auth_select_wallet
|
||||
from app.api.routes.auth import s_api_v1_auth_twa, s_api_v1_auth_select_wallet, s_api_v1_auth_me
|
||||
from app.api.routes.statics import s_api_tonconnect_manifest, s_api_platform_metadata
|
||||
from app.api.routes.node_storage import s_api_v1_storage_post, s_api_v1_storage_get, \
|
||||
s_api_v1_storage_decode_cid
|
||||
|
|
@ -37,6 +37,7 @@ app.add_route(s_api_tonconnect_manifest, "/api/tonconnect-manifest.json", method
|
|||
app.add_route(s_api_platform_metadata, "/api/platform-metadata.json", methods=["GET", "OPTIONS"])
|
||||
|
||||
app.add_route(s_api_v1_auth_twa, "/api/v1/auth.twa", methods=["POST", "OPTIONS"])
|
||||
app.add_route(s_api_v1_auth_me, "/api/v1/auth.me", methods=["GET", "OPTIONS"])
|
||||
app.add_route(s_api_v1_auth_select_wallet, "/api/v1/auth.selectWallet", methods=["POST", "OPTIONS"])
|
||||
|
||||
app.add_route(s_api_v1_tonconnect_new, "/api/v1/tonconnect.new", methods=["GET", "OPTIONS"])
|
||||
|
|
|
|||
|
|
@ -258,6 +258,9 @@ 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"
|
||||
|
||||
if not request.ctx.wallet_address(request.ctx.db_session):
|
||||
return response.json({"error": "No wallet address provided"}, status=400)
|
||||
|
||||
license_exist = request.ctx.db_session.query(UserContent).filter_by(
|
||||
onchain_address=request.json['content_address'],
|
||||
).first()
|
||||
|
|
|
|||
|
|
@ -109,8 +109,7 @@ async def s_api_v1_auth_twa(request):
|
|||
WalletConnection.network == 'ton',
|
||||
WalletConnection.invalidated == False
|
||||
)
|
||||
))).scalars().first()
|
||||
|
||||
))).order_by(WalletConnection.created.desc()).scalars().first()
|
||||
known_user.last_use = datetime.now()
|
||||
request.ctx.db_session.commit()
|
||||
|
||||
|
|
@ -120,8 +119,72 @@ async def s_api_v1_auth_twa(request):
|
|||
'auth_v1_token': new_user_key['auth_v1_token']
|
||||
})
|
||||
|
||||
async def s_api_v1_auth_me(request):
|
||||
if not request.ctx.user:
|
||||
return response.json({"error": "Unauthorized"}, status=401)
|
||||
|
||||
ton_connection = (request.ctx.db_session.execute(select(WalletConnection).where(
|
||||
and_(
|
||||
WalletConnection.user_id == request.ctx.user.id,
|
||||
WalletConnection.network == 'ton',
|
||||
WalletConnection.invalidated == False
|
||||
)
|
||||
))).order_by(WalletConnection.created.desc()).scalars().first()
|
||||
|
||||
return response.json({
|
||||
'user': request.ctx.user.json_format(),
|
||||
'connected_wallet': ton_connection.json_format() if ton_connection else None
|
||||
})
|
||||
|
||||
async def s_api_v1_auth_select_wallet(request):
|
||||
if not request.ctx.user:
|
||||
return response.json({"error": "Unauthorized"}, status=401)
|
||||
|
||||
try:
|
||||
data = request.json
|
||||
except Exception as e:
|
||||
return response.json({"error": "Invalid JSON"}, status=400)
|
||||
|
||||
if "wallet_address" not in data:
|
||||
return response.json({"error": "wallet_address is required"}, status=400)
|
||||
|
||||
# Convert raw wallet address to canonical format using Address from tonsdk.utils
|
||||
raw_addr = data["wallet_address"]
|
||||
canonical_address = Address(raw_addr).to_string(1, 1, 1)
|
||||
|
||||
db_session = request.ctx.db_session
|
||||
user = request.ctx.user
|
||||
|
||||
# Check if a WalletConnection already exists for this user with the given canonical wallet address
|
||||
existing_connection = db_session.query(WalletConnection).filter(
|
||||
WalletConnection.user_id == user.id,
|
||||
WalletConnection.wallet_address == canonical_address
|
||||
).first()
|
||||
|
||||
if not existing_connection:
|
||||
return response.json({"error": "Wallet connection not found"}, status=404)
|
||||
|
||||
saved_values = {
|
||||
'keys': existing_connection.keys,
|
||||
'meta': existing_connection.meta,
|
||||
'wallet_key': existing_connection.wallet_key,
|
||||
'connection_id': existing_connection.connection_id,
|
||||
'network': existing_connection.network,
|
||||
}
|
||||
|
||||
db_session.delete(existing_connection)
|
||||
db_session.commit()
|
||||
|
||||
new_connection = WalletConnection(
|
||||
**saved_values,
|
||||
user_id=user.id,
|
||||
wallet_address=canonical_address,
|
||||
created=datetime.now(),
|
||||
updated=datetime.now(),
|
||||
invalidated=False,
|
||||
without_pk=False
|
||||
)
|
||||
db_session.add(new_connection)
|
||||
db_session.commit()
|
||||
|
||||
return response.empty(status=200)
|
||||
|
|
|
|||
|
|
@ -147,6 +147,7 @@ async def s_api_v1_content_view(request, content_address: str):
|
|||
).first()
|
||||
if converted_content:
|
||||
display_options['content_url'] = converted_content.web_url
|
||||
opts['content_ext'] = converted_content.filename.split('.')[-1]
|
||||
|
||||
content_meta = content['encrypted_content'].json_format()
|
||||
content_metadata = StoredContent.from_cid(request.ctx.db_session, content_meta.get('metadata_cid') or None)
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ async def t_inline_query_node_content(query: types.InlineQuery, memory=None, use
|
|||
'mov': 'video'
|
||||
}.get(preview_content.filename.split('.')[-1], content_type_declared)
|
||||
|
||||
hashtags_str = (' '.join(f"#{_h}" for _h in metadata_content_json.get('hashtags', []))).strip()
|
||||
hashtags_str = metadata_content_json.get('description', '').strip()
|
||||
if hashtags_str:
|
||||
hashtags_str = hashtags_str + '\n'
|
||||
|
||||
|
|
@ -212,7 +212,7 @@ async def t_inline_query_node_content(query: types.InlineQuery, memory=None, use
|
|||
types.InlineQueryResultCachedAudio(
|
||||
id=f"NC_{content.id}_{int(datetime.now().timestamp() // 60)}",
|
||||
audio_file_id=decrypted_content.meta['telegram_file_cache_preview'],
|
||||
caption=hashtags_str + user.translated('p_playerContext_preview'),
|
||||
caption=hashtags_str + user.translated('p_playerAudioContext_preview'),
|
||||
parse_mode='html',
|
||||
reply_markup=get_inline_keyboard([
|
||||
[
|
||||
|
|
@ -242,7 +242,7 @@ async def t_inline_query_node_content(query: types.InlineQuery, memory=None, use
|
|||
id=f"NC_{content.id}_{int(datetime.now().timestamp() // 60)}",
|
||||
video_file_id=decrypted_content.meta['telegram_file_cache_preview'],
|
||||
title=title,
|
||||
caption=hashtags_str + user.translated('p_playerContext_preview'),
|
||||
caption=hashtags_str + user.translated('p_playerVideoContext_preview'),
|
||||
parse_mode='html',
|
||||
reply_markup=get_inline_keyboard([
|
||||
[
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -148,8 +148,11 @@ msgid "buyTrackListenLicense_button"
|
|||
msgstr "💶 Купить лицензию ({price} TON)"
|
||||
|
||||
#: app/core/models/_telegram/templates/player.py:117
|
||||
msgid "p_playerContext_preview"
|
||||
msgstr "<i>Это демонстрационная версия трека. Чтобы прослушать полную версию, необходимо приобрести лицензию 🎧.</i>"
|
||||
msgid "p_playerAudioContext_preview"
|
||||
msgstr "<i>Превью аудиозаписи. Полная версия доступна только по лицензии 🎧</i>"
|
||||
|
||||
msgid "p_playerVideoContext_preview"
|
||||
msgstr "<i>Превью видео. Полная версия доступна только по лицензии 🎬</i>"
|
||||
|
||||
#: app/client_bot/routers/content.py:32
|
||||
msgid "error_contentNotFound"
|
||||
|
|
|
|||
Loading…
Reference in New Issue