Separate HTML caches
This commit is contained in:
parent
abbe5c3bd9
commit
71fa5ad6b6
12
app.py
12
app.py
@ -280,9 +280,16 @@ def get_oembed_url(params):
|
|||||||
def proxy(video_id):
|
def proxy(video_id):
|
||||||
logger.info(f"{video_id}: Received request")
|
logger.info(f"{video_id}: Received request")
|
||||||
|
|
||||||
|
cache_html_suffix = "_html"
|
||||||
|
request_user_agent = request.headers.get('User-Agent', '').lower()
|
||||||
|
if 'twitterbot' in request_user_agent:
|
||||||
|
cache_html_suffix = "_html_twitterbot"
|
||||||
|
elif 'discordbot' in request_user_agent:
|
||||||
|
cache_html_suffix = "_html_discordbot"
|
||||||
|
|
||||||
if cache is not None:
|
if cache is not None:
|
||||||
logger.debug(f"{video_id}: Checking cache")
|
logger.debug(f"{video_id}: Checking cache")
|
||||||
cached_html = cache.get(f"{video_id}_html")
|
cached_html = cache.get(f"{video_id}{cache_html_suffix}")
|
||||||
if cached_html is not None:
|
if cached_html is not None:
|
||||||
logger.info(f"{video_id}: Returning cached response")
|
logger.info(f"{video_id}: Returning cached response")
|
||||||
return Response(cached_html, mimetype="text/html") # type: ignore
|
return Response(cached_html, mimetype="text/html") # type: ignore
|
||||||
@ -312,7 +319,6 @@ def proxy(video_id):
|
|||||||
video_width, video_height = get_video_resolution(params) if params else (None, None)
|
video_width, video_height = get_video_resolution(params) if params else (None, None)
|
||||||
|
|
||||||
download_allowed = True
|
download_allowed = True
|
||||||
request_user_agent = request.headers.get('User-Agent', '').lower()
|
|
||||||
if download_allowed and 'discordbot' not in request_user_agent:
|
if download_allowed and 'discordbot' not in request_user_agent:
|
||||||
logger.info(f"{video_id}: Video download ignored due to user agent ({request_user_agent})")
|
logger.info(f"{video_id}: Video download ignored due to user agent ({request_user_agent})")
|
||||||
download_allowed = False
|
download_allowed = False
|
||||||
@ -403,7 +409,7 @@ if you want to download videos, please consider using a tool like nndownload: ht
|
|||||||
|
|
||||||
if cache is not None:
|
if cache is not None:
|
||||||
logger.info(f"{video_id}: Caching HTML response")
|
logger.info(f"{video_id}: Caching HTML response")
|
||||||
cache.set(f"{video_id}_html", html_response, expire=CACHE_EXPIRATION_HTML)
|
cache.set(f"{video_id}{cache_html_suffix}", html_response, expire=CACHE_EXPIRATION_HTML)
|
||||||
|
|
||||||
logger.info(f"{video_id}: Returning response")
|
logger.info(f"{video_id}: Returning response")
|
||||||
logger.debug(f"{video_id}: HTML response:\n----------\n{html_response}\n----------")
|
logger.debug(f"{video_id}: HTML response:\n----------\n{html_response}\n----------")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user