mirror of
https://git.vectorsigma.ru/public/tubearchivist.git
synced 2026-08-04 21:39:49 +00:00
implement po_token extractor args
This commit is contained in:
@@ -40,6 +40,7 @@ class DownloadsConfigType(TypedDict):
|
||||
comment_max: str | bool
|
||||
comment_sort: Literal["top", "new"]
|
||||
cookie_import: bool
|
||||
potoken: bool
|
||||
throttledratelimit: int
|
||||
extractor_lang: str | bool
|
||||
integrate_ryd: bool
|
||||
@@ -85,6 +86,7 @@ class AppConfig:
|
||||
"comment_max": False,
|
||||
"comment_sort": "top",
|
||||
"cookie_import": False,
|
||||
"potoken": False,
|
||||
"throttledratelimit": False,
|
||||
"extractor_lang": False,
|
||||
"integrate_ryd": False,
|
||||
|
||||
@@ -34,6 +34,11 @@ urlpatterns = [
|
||||
views.CookieView.as_view(),
|
||||
name="api-cookie",
|
||||
),
|
||||
path(
|
||||
"potoken/",
|
||||
views.POTokenView.as_view(),
|
||||
name="api-potoken",
|
||||
),
|
||||
path(
|
||||
"token/",
|
||||
views.TokenView.as_view(),
|
||||
|
||||
@@ -5,7 +5,7 @@ from appsettings.src.config import AppConfig
|
||||
from appsettings.src.snapshot import ElasticSnapshot
|
||||
from common.src.ta_redis import RedisArchivist
|
||||
from common.views_base import AdminOnly, ApiBaseView
|
||||
from download.src.yt_dlp_base import CookieHandler
|
||||
from download.src.yt_dlp_base import CookieHandler, POTokenHandler
|
||||
from rest_framework.authtoken.models import Token
|
||||
from rest_framework.response import Response
|
||||
from task.src.task_manager import TaskCommand
|
||||
@@ -252,6 +252,36 @@ class CookieView(ApiBaseView):
|
||||
return validation
|
||||
|
||||
|
||||
class POTokenView(ApiBaseView):
|
||||
"""handle PO token"""
|
||||
|
||||
permission_classes = [AdminOnly]
|
||||
|
||||
def get(self, request):
|
||||
"""get token"""
|
||||
config = AppConfig().config
|
||||
potoken = POTokenHandler(config).get()
|
||||
return Response({"potoken": potoken})
|
||||
|
||||
def post(self, request):
|
||||
"""post token"""
|
||||
config = AppConfig().config
|
||||
new_token = request.data.get("potoken")
|
||||
if not new_token:
|
||||
message = "missing potoken key in request data"
|
||||
print(message)
|
||||
return Response({"message": message}, status=400)
|
||||
|
||||
POTokenHandler(config).set_token(new_token)
|
||||
return Response({"potoken": new_token})
|
||||
|
||||
def delete(self, request):
|
||||
"""delete token"""
|
||||
config = AppConfig().config
|
||||
POTokenHandler(config).revoke_token()
|
||||
return Response({"potoken": None})
|
||||
|
||||
|
||||
class TokenView(ApiBaseView):
|
||||
"""resolves to /api/appsettings/token/
|
||||
DELETE: revoke the token
|
||||
|
||||
Reference in New Issue
Block a user