mirror of
https://github.com/tubearchivist/tubearchivist.git
synced 2024-12-22 09:50:12 +00:00
handle filenotfounderror for manual cookie import
This commit is contained in:
parent
eb229440d4
commit
4b1ebf44c9
@ -83,8 +83,13 @@ class CookieHandler:
|
||||
"""import cookie from file"""
|
||||
cache_path = self.config["application"]["cache_dir"]
|
||||
import_path = os.path.join(cache_path, "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)
|
||||
|
||||
|
@ -929,25 +929,36 @@ class SettingsView(View):
|
||||
if config_value == "cookie_import":
|
||||
self.process_cookie(config, updated_value)
|
||||
|
||||
@staticmethod
|
||||
def process_cookie(config, updated_value):
|
||||
def process_cookie(self, config, updated_value):
|
||||
"""import and validate cookie"""
|
||||
handler = CookieHandler(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
|
||||
def _fail_message(message_line):
|
||||
"""notify our failure"""
|
||||
key = "message:setting"
|
||||
message = {
|
||||
"status": key,
|
||||
"level": "error",
|
||||
"title": "Cookie import failed",
|
||||
"message": "",
|
||||
"message": message_line,
|
||||
}
|
||||
RedisArchivist().set_message(key, message=message, expire=True)
|
||||
else:
|
||||
handler.revoke()
|
||||
|
||||
|
||||
def progress(request):
|
||||
|
Loading…
Reference in New Issue
Block a user