remove old cookie import, #856

This commit is contained in:
Simon
2025-01-11 10:55:43 +07:00
parent d1a42c4b57
commit 44035187b9
3 changed files with 2 additions and 47 deletions

View File

@@ -13,7 +13,6 @@ from appsettings.src.snapshot import ElasticSnapshot
from common.src.es_connect import ElasticWrap from common.src.es_connect import ElasticWrap
from common.src.ta_redis import RedisArchivist from common.src.ta_redis import RedisArchivist
from django.conf import settings from django.conf import settings
from download.src.yt_dlp_base import CookieHandler
class SubscriptionsConfigType(TypedDict): class SubscriptionsConfigType(TypedDict):
@@ -127,30 +126,9 @@ class AppConfig:
def post_process_updated(self, data: dict) -> None: def post_process_updated(self, data: dict) -> None:
"""apply hooks for some config keys""" """apply hooks for some config keys"""
for config_value, updated_value in data: for config_value, updated_value in data:
if config_value == "downloads.cookie_import":
self.process_cookie(updated_value)
if config_value == "application.enable_snapshot" and updated_value: if config_value == "application.enable_snapshot" and updated_value:
ElasticSnapshot().setup() ElasticSnapshot().setup()
def process_cookie(self, updated_value):
"""import and validate cookie"""
handler = CookieHandler(self.config)
if updated_value:
try:
handler.import_cookie()
except FileNotFoundError:
print("cookie: import failed, file not found")
handler.revoke()
self._fail_message("Cookie file not found.")
return
valid = handler.validate()
if not valid:
handler.revoke()
self._fail_message("Failed to validate cookie file.")
else:
handler.revoke()
@staticmethod @staticmethod
def _fail_message(message_line): def _fail_message(message_line):
"""notify our failure""" """notify our failure"""

View File

@@ -4,13 +4,12 @@ functionality:
- handle yt-dlp errors - handle yt-dlp errors
""" """
import os
from datetime import datetime from datetime import datetime
from http import cookiejar from http import cookiejar
from io import StringIO from io import StringIO
import yt_dlp import yt_dlp
from common.src.env_settings import EnvironmentSettings from appsettings.src.config import AppConfig
from common.src.ta_redis import RedisArchivist from common.src.ta_redis import RedisArchivist
@@ -87,7 +86,6 @@ class CookieHandler:
def __init__(self, config): def __init__(self, config):
self.cookie_io = False self.cookie_io = False
self.config = config self.config = config
self.cache_dir = EnvironmentSettings.CACHE_DIR
def get(self): def get(self):
"""get cookie io stream""" """get cookie io stream"""
@@ -95,28 +93,8 @@ class CookieHandler:
self.cookie_io = StringIO(cookie) self.cookie_io = StringIO(cookie)
return self.cookie_io return self.cookie_io
def import_cookie(self):
"""import cookie from file"""
import_path = os.path.join(
self.cache_dir, "import", "cookies.google.txt"
)
try:
with open(import_path, encoding="utf-8") as cookie_file:
cookie = cookie_file.read()
except FileNotFoundError as err:
print(f"cookie: {import_path} file not found")
raise err
self.set_cookie(cookie)
os.remove(import_path)
print("cookie: import successful")
def set_cookie(self, cookie): def set_cookie(self, cookie):
"""set cookie str and activate in config""" """set cookie str and activate in config"""
from appsettings.src.config import AppConfig
RedisArchivist().set_message("cookie", cookie, save=True) RedisArchivist().set_message("cookie", cookie, save=True)
AppConfig().update_config({"downloads.cookie_import": True}) AppConfig().update_config({"downloads.cookie_import": True})
self.config["downloads"]["cookie_import"] = True self.config["downloads"]["cookie_import"] = True
@@ -125,8 +103,6 @@ class CookieHandler:
@staticmethod @staticmethod
def revoke(): def revoke():
"""revoke cookie""" """revoke cookie"""
from appsettings.src.config import AppConfig
RedisArchivist().del_message("cookie") RedisArchivist().del_message("cookie")
RedisArchivist().del_message("cookie:valid") RedisArchivist().del_message("cookie:valid")
AppConfig().update_config({"downloads.cookie_import": False}) AppConfig().update_config({"downloads.cookie_import": False})

View File

@@ -489,6 +489,7 @@ const SettingsApplication = () => {
{showCookieForm ? ( {showCookieForm ? (
<> <>
<textarea <textarea
rows={4}
value={cookieFormData} value={cookieFormData}
onChange={e => { onChange={e => {
setCookieFormData(e.currentTarget.value); setCookieFormData(e.currentTarget.value);