File size: 1,069 Bytes
08ca036 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import json
import time
from utils.Logger import logger
import utils.globals as globals
def save_wss_map(wss_map):
with open(globals.WSS_MAP_FILE, "w") as f:
json.dump(wss_map, f, indent=4)
async def token2wss(token):
if not token:
return False, None
if token in globals.wss_map:
wss_mode = globals.wss_map[token]["wss_mode"]
if wss_mode:
if int(time.time()) - globals.wss_map.get(token, {}).get("timestamp", 0) < 60 * 60:
wss_url = globals.wss_map[token]["wss_url"]
logger.info(f"token -> wss_url from cache")
return wss_mode, wss_url
else:
logger.info(f"token -> wss_url expired")
return wss_mode, None
else:
return False, None
return False, None
async def set_wss(token, wss_mode, wss_url=None):
if not token:
return True
globals.wss_map[token] = {"timestamp": int(time.time()), "wss_url": wss_url, "wss_mode": wss_mode}
save_wss_map(globals.wss_map)
return True
|