diff --git a/backend/download/serializers.py b/backend/download/serializers.py index b838b69c..f0ad3274 100644 --- a/backend/download/serializers.py +++ b/backend/download/serializers.py @@ -89,12 +89,15 @@ class BulkUpdateDowloadQuerySerializer(serializers.Serializer): vid_type = serializers.ChoiceField( choices=VideoTypeEnum.values_known(), required=False ) + error = serializers.BooleanField(required=False, allow_null=True) class BulkUpdateDowloadDataSerializer(serializers.Serializer): """serialize data""" - status = serializers.ChoiceField(choices=["pending", "ignore", "priority"]) + status = serializers.ChoiceField( + choices=["pending", "ignore", "priority", "clear_error"] + ) class DownloadQueueItemUpdateSerializer(serializers.Serializer): diff --git a/backend/download/src/queue_interact.py b/backend/download/src/queue_interact.py index 260b5e5a..22f0f039 100644 --- a/backend/download/src/queue_interact.py +++ b/backend/download/src/queue_interact.py @@ -30,27 +30,42 @@ class PendingInteract: _, _ = ElasticWrap(path).post(data=data) def update_bulk( - self, channel_id: str | None, vid_type: str | None, new_status: str + self, + channel_id: str | None, + vid_type: str | None, + new_status: str, + error: bool | None = None, ): """update status in bulk""" must_list = [{"term": {"status": {"value": self.status}}}] + must_not_list = [] + if channel_id: must_list.append({"term": {"channel_id": {"value": channel_id}}}) if vid_type: must_list.append({"term": {"vid_type": {"value": vid_type}}}) + if error is not None: + exists = {"exists": {"field": "message"}} + if error: + must_list.append(exists) # type: ignore + else: + must_not_list.append(exists) + if new_status == "priority": source = """ ctx._source.status = 'pending'; ctx._source.auto_start = true; ctx._source.message = null; """ + elif new_status == "clear_error": + source = "ctx._source.message = null" else: source = f"ctx._source.status = '{new_status}'" data = { - "query": {"bool": {"must": must_list}}, + "query": {"bool": {"must": must_list, "must_not": must_not_list}}, "script": {"source": source, "lang": "painless"}, } diff --git a/backend/download/views.py b/backend/download/views.py index 05f3deb5..a4290cab 100644 --- a/backend/download/views.py +++ b/backend/download/views.py @@ -155,9 +155,13 @@ class DownloadApiListView(ApiBaseView): status_filter = validated_query.get("filter") channel = validated_query.get("channel") vid_type = validated_query.get("vid_type") + error = validated_query.get("error") PendingInteract(status=status_filter).update_bulk( - channel_id=channel, vid_type=vid_type, new_status=new_status + channel_id=channel, + vid_type=vid_type, + new_status=new_status, + error=error, ) if new_status == "priority": diff --git a/frontend/src/api/actions/updateDownloadQueueByFilter.ts b/frontend/src/api/actions/updateDownloadQueueByFilter.ts index 1410360e..aac840a5 100644 --- a/frontend/src/api/actions/updateDownloadQueueByFilter.ts +++ b/frontend/src/api/actions/updateDownloadQueueByFilter.ts @@ -1,18 +1,20 @@ import APIClient from '../../functions/APIClient'; type FilterType = 'ignore' | 'pending'; -export type DownloadQueueStatus = 'ignore' | 'pending' | 'priority'; +export type DownloadQueueStatus = 'ignore' | 'pending' | 'priority' | 'clear_error'; const updateDownloadQueueByFilter = async ( filter: FilterType, channel: string | null, vid_type: string | null, + error: string | null, status: DownloadQueueStatus, ) => { const searchParams = new URLSearchParams(); if (filter) searchParams.append('filter', filter); if (channel) searchParams.append('channel', channel); if (vid_type) searchParams.append('vid_type', vid_type); + if (error) searchParams.append('error', error); return APIClient(`/api/download/?${searchParams.toString()}`, { method: 'PATCH', diff --git a/frontend/src/pages/Download.tsx b/frontend/src/pages/Download.tsx index 10510f99..5a2cd271 100644 --- a/frontend/src/pages/Download.tsx +++ b/frontend/src/pages/Download.tsx @@ -162,6 +162,7 @@ const Download = () => { showIgnoredFilter, channelFilterFromUrl, vidTypeFilterFromUrl, + errorFilterFromUrl, status, ); setRefresh(true); @@ -467,16 +468,22 @@ const Download = () => {

Bulk actions

Applied filtered by status '{showIgnoredFilter}' + {vidTypeFilterFromUrl && ( + + {' '} + and by type: '{vidTypeFilterFromUrl}' + + )} {channelFilterFromUrl && ( {' '} and by channel: '{channel_filter_name}' )} - {vidTypeFilterFromUrl && ( + {errorFilterFromUrl && ( {' '} - and by type: '{vidTypeFilterFromUrl}' + and by error state: '{errorFilterFromUrl}' )}

@@ -489,6 +496,9 @@ const Download = () => {
+
)}