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"""
|
"""import cookie from file"""
|
||||||
cache_path = self.config["application"]["cache_dir"]
|
cache_path = self.config["application"]["cache_dir"]
|
||||||
import_path = os.path.join(cache_path, "import", "cookies.google.txt")
|
import_path = os.path.join(cache_path, "import", "cookies.google.txt")
|
||||||
with open(import_path, encoding="utf-8") as cookie_file:
|
|
||||||
cookie = cookie_file.read()
|
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)
|
self.set_cookie(cookie)
|
||||||
|
|
||||||
|
@ -929,26 +929,37 @@ class SettingsView(View):
|
|||||||
if config_value == "cookie_import":
|
if config_value == "cookie_import":
|
||||||
self.process_cookie(config, updated_value)
|
self.process_cookie(config, updated_value)
|
||||||
|
|
||||||
@staticmethod
|
def process_cookie(self, config, updated_value):
|
||||||
def process_cookie(config, updated_value):
|
|
||||||
"""import and validate cookie"""
|
"""import and validate cookie"""
|
||||||
handler = CookieHandler(config)
|
handler = CookieHandler(config)
|
||||||
if updated_value:
|
if updated_value:
|
||||||
handler.import_cookie()
|
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()
|
valid = handler.validate()
|
||||||
if not valid:
|
if not valid:
|
||||||
handler.revoke()
|
handler.revoke()
|
||||||
key = "message:setting"
|
self._fail_message("Failed to validate cookie file.")
|
||||||
message = {
|
|
||||||
"status": key,
|
|
||||||
"level": "error",
|
|
||||||
"title": "Cookie import failed",
|
|
||||||
"message": "",
|
|
||||||
}
|
|
||||||
RedisArchivist().set_message(key, message=message, expire=True)
|
|
||||||
else:
|
else:
|
||||||
handler.revoke()
|
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_line,
|
||||||
|
}
|
||||||
|
RedisArchivist().set_message(key, message=message, expire=True)
|
||||||
|
|
||||||
|
|
||||||
def progress(request):
|
def progress(request):
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
|
Loading…
Reference in New Issue
Block a user