Fet
This commit is contained in:
18
bsky_post.py
18
bsky_post.py
@@ -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,17 +338,23 @@ 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...")
|
||||||
|
|||||||
Reference in New Issue
Block a user