22 lines
500 B
Python
22 lines
500 B
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import json
|
||
|
|
import base64
|
||
|
|
|
||
|
|
from yuxi.utils.logging_config import logger
|
||
|
|
|
||
|
|
|
||
|
|
def decode_pubsub_push(body: dict) -> dict | None:
|
||
|
|
message = body.get("message", {})
|
||
|
|
data_b64 = message.get("data", "")
|
||
|
|
|
||
|
|
if not data_b64:
|
||
|
|
return None
|
||
|
|
|
||
|
|
try:
|
||
|
|
decoded = base64.b64decode(data_b64).decode("utf-8")
|
||
|
|
return json.loads(decoded)
|
||
|
|
except Exception as e:
|
||
|
|
logger.warning(f"Failed to decode Pub/Sub push data: {e}")
|
||
|
|
return None
|