dowload & selectWallet & fixes & auth me
This commit is contained in:
1 parent
ac6d102a3f
commit
b02ded982c
7 files changed
+79
-8
No files matched your search
@@ -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()
|
||||
|
||||
+65
-2
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user