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