This commit is contained in:
Guillem Hernandez Sola
2026-05-08 10:31:54 +02:00
parent 233697cca1
commit c5338de043

View File

@@ -326,7 +326,11 @@ def upload_video_and_wait(
alt_text: str = ""
) -> models.AppBskyEmbedVideo.Main | None:
# --- Helper class to mock the SDK's internal Session object ---
# --- Helper classes to mock the SDK's internal Session object ---
class MockPayload:
def __init__(self, exp):
self.exp = exp
class VideoSession:
def __init__(self, token, handle, did):
self.access_jwt = token
@@ -334,18 +338,24 @@ def upload_video_and_wait(
self.handle = handle
self.did = did
# The SDK needs this payload to check token expiration
self.access_jwt_payload = {"exp": int(time.time()) + 3600}
# Default to 1 hour from now if decoding fails
exp_time = int(time.time()) + 3600
try:
parts = token.split('.')
if len(parts) == 3:
payload = parts[1]
# Pad base64 string if necessary
payload += '=' * (-len(payload) % 4)
self.access_jwt_payload = json.loads(base64.urlsafe_b64decode(payload).decode('utf-8'))
decoded = json.loads(base64.urlsafe_b64decode(payload).decode('utf-8'))
if 'exp' in decoded:
exp_time = decoded['exp']
except Exception:
pass
# Assign as an object so the SDK can call .exp
self.access_jwt_payload = MockPayload(exp_time)
try:
logging.info("🎬 Requesting Service Auth for Video Upload...")