feat(security): add cache to wallpaper endpoints to mitigate attacks

This commit is contained in:
InfinityPacer
2024-10-07 23:37:20 +08:00
parent 5c05845500
commit d7da2e133a

View File

@@ -1,5 +1,7 @@
from typing import Optional
from cachetools import TTLCache, cached
from app.utils.http import RequestUtils
@@ -73,6 +75,7 @@ class WebUtils:
return ""
@staticmethod
@cached(cache=TTLCache(maxsize=1, ttl=3600))
def get_bing_wallpaper() -> Optional[str]:
"""
获取Bing每日壁纸
@@ -90,6 +93,7 @@ class WebUtils:
return None
@staticmethod
@cached(cache=TTLCache(maxsize=1, ttl=3600))
def get_bing_wallpapers(num: int = 7) -> Optional[str]:
"""
获取7天的Bing每日壁纸