mirror of
https://git.vectorsigma.ru/public/tubearchivist.git
synced 2026-08-04 21:39:49 +00:00
add /api/channel/{channel-id}/about/ (#783)
* add /api/channel/{channel-id}/about/
* move testing function
* remove unused import
* fix unused import
* fix formatting
* simplify channel overwrites
* remove unused
---------
Co-authored-by: Simon <simobilleter@gmail.com>
This commit is contained in:
@@ -326,21 +326,11 @@ class YoutubeChannel(YouTubeItem):
|
|||||||
for key, value in overwrites.items():
|
for key, value in overwrites.items():
|
||||||
if key not in valid_keys:
|
if key not in valid_keys:
|
||||||
raise ValueError(f"invalid overwrite key: {key}")
|
raise ValueError(f"invalid overwrite key: {key}")
|
||||||
elif value == "disable":
|
|
||||||
to_write[key] = False
|
if value is None and key in to_write:
|
||||||
|
to_write.pop(key)
|
||||||
continue
|
continue
|
||||||
elif value == "0":
|
|
||||||
if key in to_write:
|
|
||||||
del to_write[key]
|
|
||||||
continue
|
|
||||||
elif value == "1":
|
|
||||||
to_write[key] = True
|
|
||||||
continue
|
|
||||||
elif isinstance(value, int) and int(value) < 0:
|
|
||||||
if key in to_write:
|
|
||||||
del to_write[key]
|
|
||||||
continue
|
|
||||||
elif value is not None and value != "":
|
|
||||||
to_write.update({key: value})
|
to_write.update({key: value})
|
||||||
|
|
||||||
self.json_data["channel_overwrites"] = to_write
|
self.json_data["channel_overwrites"] = to_write
|
||||||
@@ -353,3 +343,5 @@ def channel_overwrites(channel_id, overwrites):
|
|||||||
channel.set_overwrites(overwrites)
|
channel.set_overwrites(overwrites)
|
||||||
channel.upload_to_es()
|
channel.upload_to_es()
|
||||||
channel.sync_to_videos()
|
channel.sync_to_videos()
|
||||||
|
|
||||||
|
return channel.json_data["channel_overwrites"]
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ urlpatterns = [
|
|||||||
views.ChannelApiView.as_view(),
|
views.ChannelApiView.as_view(),
|
||||||
name="api-channel",
|
name="api-channel",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"<slug:channel_id>/about/",
|
||||||
|
views.ChannelApiAboutView.as_view(),
|
||||||
|
name="api-channel-view",
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
"<slug:channel_id>/aggs/",
|
"<slug:channel_id>/aggs/",
|
||||||
views.ChannelAggsApiView.as_view(),
|
views.ChannelAggsApiView.as_view(),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"""all channel API views"""
|
"""all channel API views"""
|
||||||
|
|
||||||
from channel.src.index import YoutubeChannel
|
from channel.src.index import YoutubeChannel, channel_overwrites
|
||||||
from channel.src.nav import ChannelNav
|
from channel.src.nav import ChannelNav
|
||||||
from common.src.urlparser import Parser
|
from common.src.urlparser import Parser
|
||||||
from common.views_base import AdminWriteOnly, ApiBaseView
|
from common.views_base import AdminWriteOnly, ApiBaseView
|
||||||
@@ -102,6 +102,38 @@ class ChannelApiView(ApiBaseView):
|
|||||||
return Response(message, status=status_code)
|
return Response(message, status=status_code)
|
||||||
|
|
||||||
|
|
||||||
|
class ChannelApiAboutView(ApiBaseView):
|
||||||
|
"""resolves to /api/channel/<channel_id>/about/
|
||||||
|
GET: returns the channel specific settings
|
||||||
|
POST: sets the channel specific settings, returning current values
|
||||||
|
"""
|
||||||
|
|
||||||
|
permission_classes = [AdminWriteOnly]
|
||||||
|
|
||||||
|
def get(self, request, channel_id):
|
||||||
|
"""get channel overwrites"""
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
channel = YoutubeChannel(channel_id)
|
||||||
|
channel.get_from_es()
|
||||||
|
if not channel.json_data:
|
||||||
|
return Response({"error": "unknown channel id"}, status=404)
|
||||||
|
|
||||||
|
return Response(channel.get_overwrites())
|
||||||
|
|
||||||
|
def post(self, request, channel_id):
|
||||||
|
"""modify channel overwrites"""
|
||||||
|
data = request.data
|
||||||
|
if not isinstance(data, dict):
|
||||||
|
return Response({"error": "invalid payload"}, status=400)
|
||||||
|
|
||||||
|
try:
|
||||||
|
new_channel_overwrites = channel_overwrites(channel_id, data)
|
||||||
|
except ValueError as err:
|
||||||
|
return Response({"error": str(err)}, status=400)
|
||||||
|
|
||||||
|
return Response(new_channel_overwrites, status=200)
|
||||||
|
|
||||||
|
|
||||||
class ChannelAggsApiView(ApiBaseView):
|
class ChannelAggsApiView(ApiBaseView):
|
||||||
"""resolves to /api/channel/<channel_id>/aggs/
|
"""resolves to /api/channel/<channel_id>/aggs/
|
||||||
GET: get channel aggregations
|
GET: get channel aggregations
|
||||||
|
|||||||
Reference in New Issue
Block a user