From c5338de04345013bb58ea4ddc67cb411fdb4c25b Mon Sep 17 00:00:00 2001 From: Guillem Hernandez Sola Date: Fri, 8 May 2026 10:31:54 +0200 Subject: [PATCH] Fet --- bsky_post.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/bsky_post.py b/bsky_post.py index 68097da..570f471 100644 --- a/bsky_post.py +++ b/bsky_post.py @@ -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,17 +338,23 @@ 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...")