store validation result, return in API

This commit is contained in:
simon 2022-06-23 06:48:55 +07:00
parent b4add20d10
commit 74d74d95a1
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
3 changed files with 24 additions and 6 deletions

View File

@ -233,11 +233,14 @@ List of valid task names:
## Cookie View
Check your youtube cookie settings
Check your youtube cookie settings, *status* turns to `true` if cookie has been validated.
GET /api/cookie/
```json
{
"cookie_enabled": true
"cookie_enabled": true,
"status": true,
"validated": <timestamp>,
"validated_str": "timestamp"
}
```

View File

@ -488,9 +488,11 @@ class CookieView(ApiBaseView):
"""handle get request"""
# pylint: disable=unused-argument
config = AppConfig().config
cookie_enabled = config["downloads"]["cookie_import"]
valid = RedisArchivist().get_message("cookie:valid")
response = {"cookie_enabled": config["downloads"]["cookie_import"]}
response.update(valid)
return Response({"cookie_enabled": cookie_enabled})
return Response(response)
@staticmethod
def post(request):

View File

@ -5,6 +5,7 @@ functionality:
"""
import os
from datetime import datetime
from http import cookiejar
from io import StringIO
@ -115,7 +116,8 @@ class CookieHandler:
"extract_flat": True,
}
validator = YtWrap(obs_request, self.config)
response = validator.extract("LL")
response = bool(validator.extract("LL"))
self.store_validation(response)
# update in redis to avoid expiring
modified = validator.obs["cookiefile"].getvalue()
@ -134,4 +136,15 @@ class CookieHandler:
)
print("cookie validation failed, exiting...")
return bool(response)
return response
@staticmethod
def store_validation(response):
"""remember last validation"""
now = datetime.now()
message = {
"status": response,
"validated": int(now.strftime("%s")),
"validated_str": now.strftime("%Y-%m-%d %H:%M"),
}
RedisArchivist().set_message("cookie:valid", message)