# Copyright (c) 2025, JINGROW and contributors
# For license information, please see license.txt

"""
实时通信相关白名单函数 - 转发到 SaaS 端
"""

import jingrow
import requests
from jingrow.config import Config
from jingrow.utils.auth import get_request_session_cookie


@jingrow.whitelist(allow_guest=True)
def get_user_info():
    """获取用户信息 - 转发到 SaaS 端"""
    url = f"{Config.jingrow_server_url}/api/action/jingrow.realtime.get_user_info"
    headers = {"Accept": "application/json"}
    
    session_cookie = get_request_session_cookie()
    if session_cookie:
        headers["Cookie"] = f"sid={session_cookie}"
    
    resp = requests.get(url, headers=headers, timeout=30)
    if resp.status_code == 200:
        return resp.json().get("message", {})
    return {}
