from tools import * from AppBridge import * from Utils.Config import * from Utils.Models import * from Utils.Safe import * class Timer: def __init__(self): pass @staticmethod def GetTime(Timezone: datetime.timezone = Timezone_UTCA8) -> datetime.datetime: return datetime.datetime.now(Timezone) class IP: def __init__(self): pass @staticmethod def GetIP(): return flask.request.headers.get('X-Forwarded-For', '').split(',')[0].strip() if flask.request.headers.get('X-Forwarded-For') else '*' class Router: def __init__(self): pass @staticmethod def AfterThisRequest(amfunc): return flask.after_this_request(amfunc) class Cookie: def __init__(self): pass @staticmethod def get(s: str): if not s: return False return flask.request.cookies.get(s) @staticmethod def delete(s: str, path: str = "/"): if not s: return False # 修复:使用默认参数 key=s, p=path 强制“捕获”当前的值 # 修复:直接操作 response 并返回它,而不是打包成元组 def delete_cookie_action(response: flask.Response, key=s, p=path): response.delete_cookie(key=key, path=p, secure=True, httponly=True) return response Router.AfterThisRequest(delete_cookie_action) @staticmethod def set(s: str, value: str = "", path: str = "/", samesite: str | None = "Lax", MaxAge: int = 3600 * 24 * 30, domain: str | None = ".gvsds.com"): if not s: return False # 修复:显式捕获所有参数 # 修复:默认值 None 改为 "Lax" (现代浏览器标准),None 可能导致无效 def set_cookie_action(response: flask.Response, key=s, val=value, p=path, site=samesite, age=MaxAge, dom=domain): print(key, val, value) response.set_cookie( key=key, value=val, path=p, secure=True, httponly=True, samesite=site, max_age=age, domain=dom ) return response Router.AfterThisRequest(set_cookie_action)