From bee7cc88922311e56ef467ba6ef304b91ec76064 Mon Sep 17 00:00:00 2001 From: Aevann Date: Mon, 15 May 2023 03:04:14 +0300 Subject: [PATCH] put my fake headers in const --- files/helpers/actions.py | 5 ++--- files/helpers/config/const.py | 2 ++ files/routes/posts.py | 10 +++------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/files/helpers/actions.py b/files/helpers/actions.py index fcc84276d..68f9f8fc7 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -26,14 +26,13 @@ from files.helpers.slots import check_slots_command post_target_type = Union[Submission, User] def _archiveorg(url): - headers = {'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'} try: requests.get(f'https://web.archive.org/save/{url}', - headers=headers, timeout=10, proxies=proxies) + headers=HEADERS, timeout=10, proxies=proxies) except: pass try: requests.post('https://ghostarchive.org/archive2', data={"archive": url}, - headers=headers, timeout=10, proxies=proxies) + headers=HEADERS, timeout=10, proxies=proxies) except: pass diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index 2ffea9b6b..67b211072 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -1177,3 +1177,5 @@ CHUD_PHRASES = ( "Long live the CCP", "I stand with Ukraine", ) + +HEADERS = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36"} diff --git a/files/routes/posts.py b/files/routes/posts.py index c43f2d2b3..5f79d39da 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -30,8 +30,6 @@ from .users import userpagelisting from files.__main__ import app, limiter -titleheaders = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36"} - @app.post("/publish/") @limiter.limit('1/second', scope=rpath) @limiter.limit('1/second', scope=rpath, key_func=get_ID) @@ -291,10 +289,8 @@ def thumbnail_thread(pid:int, vid:int): if fetch_url.startswith('/') and '\\' not in fetch_url: fetch_url = f"{SITE_FULL}{fetch_url}" - headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36"} - try: - x=requests.get(fetch_url, headers=headers, timeout=5, proxies=proxies) + x=requests.get(fetch_url, headers=HEADERS, timeout=5, proxies=proxies) except: db.close() return @@ -342,7 +338,7 @@ def thumbnail_thread(pid:int, vid:int): for url in thumb_candidate_urls: try: - image_req=requests.get(url, headers=headers, timeout=5, proxies=proxies) + image_req=requests.get(url, headers=HEADERS, timeout=5, proxies=proxies) except: continue @@ -965,7 +961,7 @@ def get_post_title(v): abort(400) try: - x = gevent.with_timeout(POST_TITLE_TIMEOUT, requests.get, url, headers=titleheaders, timeout=POST_TITLE_TIMEOUT, proxies=proxies) + x = gevent.with_timeout(POST_TITLE_TIMEOUT, requests.get, url, headers=HEADERS, timeout=POST_TITLE_TIMEOUT, proxies=proxies) except: abort(400) content_type = x.headers.get("Content-Type")