mirror of
https://github.com/tubearchivist/tubearchivist
synced 2024-11-04 12:00:21 +00:00
[API] implement delete playlist endpoint
This commit is contained in:
parent
2bccb698e6
commit
a514dda1ff
@ -13,6 +13,7 @@ from home.src.frontend.searching import SearchForm
|
||||
from home.src.frontend.watched import WatchState
|
||||
from home.src.index.channel import YoutubeChannel
|
||||
from home.src.index.generic import Pagination
|
||||
from home.src.index.playlist import YoutubePlaylist
|
||||
from home.src.index.reindex import ReindexProgress
|
||||
from home.src.index.video import SponsorBlock, YoutubeVideo
|
||||
from home.src.ta.config import AppConfig, ReleaseVersion
|
||||
@ -438,6 +439,17 @@ class PlaylistApiView(ApiBaseView):
|
||||
self.get_document(playlist_id)
|
||||
return Response(self.response, status=self.status_code)
|
||||
|
||||
def delete(self, request, playlist_id):
|
||||
"""delete playlist"""
|
||||
print(f"{playlist_id}: delete playlist")
|
||||
delete_videos = request.GET.get("delete-videos", False)
|
||||
if delete_videos:
|
||||
YoutubePlaylist(playlist_id).delete_videos_playlist()
|
||||
else:
|
||||
YoutubePlaylist(playlist_id).delete_metadata()
|
||||
|
||||
return Response({"success": True})
|
||||
|
||||
|
||||
class PlaylistApiVideoView(ApiBaseView):
|
||||
"""resolves to /api/playlist/<playlist_id>/video
|
||||
|
@ -4,7 +4,6 @@ Functionality:
|
||||
- called via user input
|
||||
"""
|
||||
|
||||
from home.src.index.playlist import YoutubePlaylist
|
||||
from home.src.ta.ta_redis import RedisArchivist
|
||||
from home.tasks import run_restore_backup
|
||||
|
||||
@ -36,7 +35,6 @@ class PostData:
|
||||
"show_subed_only": self._show_subed_only,
|
||||
"show_ignored_only": self._show_ignored_only,
|
||||
"db-restore": self._db_restore,
|
||||
"delete-playlist": self._delete_playlist,
|
||||
}
|
||||
|
||||
return exec_map[self.to_exec]
|
||||
@ -104,16 +102,3 @@ class PostData:
|
||||
filename = self.exec_val
|
||||
run_restore_backup.delay(filename)
|
||||
return {"success": True}
|
||||
|
||||
def _delete_playlist(self):
|
||||
"""delete playlist, only metadata or incl all videos"""
|
||||
playlist_dict = self.exec_val
|
||||
playlist_id = playlist_dict["playlist-id"]
|
||||
playlist_action = playlist_dict["playlist-action"]
|
||||
print(f"{playlist_id}: delete playlist {playlist_action}")
|
||||
if playlist_action == "metadata":
|
||||
YoutubePlaylist(playlist_id).delete_metadata()
|
||||
elif playlist_action == "all":
|
||||
YoutubePlaylist(playlist_id).delete_videos_playlist()
|
||||
|
||||
return {"success": True}
|
||||
|
@ -40,8 +40,8 @@
|
||||
<button onclick="deleteConfirm()" id="delete-item">Delete Playlist</button>
|
||||
<div class="delete-confirm" id="delete-button">
|
||||
<span>Delete {{ playlist_info.playlist_name }}?</span>
|
||||
<button onclick="deletePlaylist(this)" data-action="metadata" data-id="{{ playlist_info.playlist_id }}">Delete metadata</button>
|
||||
<button onclick="deletePlaylist(this)" data-action="all" class="danger-button" data-id="{{ playlist_info.playlist_id }}">Delete all</button><br>
|
||||
<button onclick="deletePlaylist(this)" data-action="" data-id="{{ playlist_info.playlist_id }}">Delete metadata</button>
|
||||
<button onclick="deletePlaylist(this)" data-action="delete-videos" class="danger-button" data-id="{{ playlist_info.playlist_id }}">Delete all</button><br>
|
||||
<button onclick="cancelDelete()">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -381,13 +381,11 @@ function deleteChannel(button) {
|
||||
function deletePlaylist(button) {
|
||||
let playlist_id = button.getAttribute('data-id');
|
||||
let playlist_action = button.getAttribute('data-action');
|
||||
let payload = JSON.stringify({
|
||||
'delete-playlist': {
|
||||
'playlist-id': playlist_id,
|
||||
'playlist-action': playlist_action,
|
||||
},
|
||||
});
|
||||
sendPost(payload);
|
||||
let apiEndpoint = `/api/playlist/${playlist_id}/`;
|
||||
if (playlist_action === 'delete-videos') {
|
||||
apiEndpoint += '?delete-videos=true';
|
||||
}
|
||||
apiRequest(apiEndpoint, 'DELETE');
|
||||
setTimeout(function () {
|
||||
window.location.replace('/playlist/');
|
||||
}, 1000);
|
||||
|
Loading…
Reference in New Issue
Block a user