fix progress inconsistency+

This commit is contained in:
Simon
2025-02-02 16:30:43 +07:00
parent 847764e440
commit 3aa41232db
3 changed files with 10 additions and 7 deletions

View File

@@ -6,15 +6,17 @@ functionality:
from datetime import datetime
from common.src.es_connect import ElasticWrap
from common.src.ta_redis import RedisArchivist
from common.src.urlparser import Parser
class WatchState:
"""handle watched checkbox for videos and channels"""
def __init__(self, youtube_id, is_watched):
def __init__(self, youtube_id: str, is_watched: bool, user_id: int):
self.youtube_id = youtube_id
self.is_watched = is_watched
self.user_id = user_id
self.stamp = int(datetime.now().timestamp())
self.pipeline = f"_ingest/pipeline/watch_{youtube_id}"
@@ -50,6 +52,8 @@ class WatchState:
}
}
response, status_code = ElasticWrap(path).post(data=data)
key = f"{self.user_id}:progress:{self.youtube_id}"
RedisArchivist().del_message(key)
if status_code != 200:
print(response)
raise ValueError("failed to mark video as watched")

View File

@@ -75,7 +75,7 @@ class WatchedView(ApiBaseView):
message = {"message": "missing id or is_watched"}
return Response(message, status=400)
WatchState(youtube_id, is_watched).change()
WatchState(youtube_id, is_watched, request.user.id).change()
return Response({"message": "success"}, status=200)