From cf01ca24ffc1a0676d449c26031d62eaf848610e Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 15 Mar 2022 13:53:40 -0700 Subject: [PATCH] Add show_download_directory, and a few ui fixes. --- .../backend/endpoints/channel_endpoints.py | 27 ++++++++++++ frontends/ycdl_flask/static/js/api.js | 7 ++++ frontends/ycdl_flask/templates/channel.html | 42 ++++++++++++------- 3 files changed, 61 insertions(+), 15 deletions(-) diff --git a/frontends/ycdl_flask/backend/endpoints/channel_endpoints.py b/frontends/ycdl_flask/backend/endpoints/channel_endpoints.py index 6fb5a94..ced3a24 100644 --- a/frontends/ycdl_flask/backend/endpoints/channel_endpoints.py +++ b/frontends/ycdl_flask/backend/endpoints/channel_endpoints.py @@ -1,5 +1,7 @@ import flask; from flask import request import itertools +import os +import subprocess import time from voussoirkit import flasktools @@ -217,3 +219,28 @@ def post_set_queuefile_extension(channel_id): response = {'id': channel.id, 'queuefile_extension': channel.queuefile_extension} return flasktools.json_response(response) + +@site.route('/channel//show_download_directory', methods=['POST']) +def post_show_download_directory(channel_id): + if not request.is_localhost: + flask.abort(403) + + channel = common.ycdldb.get_channel(channel_id) + if channel.download_directory: + abspath = channel.download_directory.absolute_path + else: + abspath = common.ycdldb.config['download_directory'] + + if not os.path.exists(abspath): + return flask.abort(400) + + if os.name == 'nt': + command = f'explorer.exe "{abspath}"' + subprocess.Popen(command, shell=True) + return flasktools.json_response({}) + else: + command = ['xdg-open', abspath] + subprocess.Popen(command, shell=True) + return flasktools.json_response({}) + + flask.abort(501) \ No newline at end of file diff --git a/frontends/ycdl_flask/static/js/api.js b/frontends/ycdl_flask/static/js/api.js index 3465045..190384d 100644 --- a/frontends/ycdl_flask/static/js/api.js +++ b/frontends/ycdl_flask/static/js/api.js @@ -75,6 +75,13 @@ function set_queuefile_extension(channel_id, extension, callback) return common.post(url, data, callback); } +api.channels.show_download_directory = +function show_download_directory(channel_id, callback) +{ + const url = `/channel/${channel_id}/show_download_directory`; + return common.post(url, null, callback); +} + api.channels.callback_go_to_channels = function callback_go_to_channels(response) { diff --git a/frontends/ycdl_flask/templates/channel.html b/frontends/ycdl_flask/templates/channel.html index 5691ca6..e8ddd0e 100644 --- a/frontends/ycdl_flask/templates/channel.html +++ b/frontends/ycdl_flask/templates/channel.html @@ -5,8 +5,8 @@ {{channel.name}} - - + + @@ -264,12 +264,13 @@ https://stackoverflow.com/a/35153397
Channel ID: {{channel.id}}
- - + +
- + {% set checked = 'checked' if channel.autorefresh else '' %} +
@@ -285,12 +286,15 @@ https://stackoverflow.com/a/35153397
- +
- + + {% if request.is_localhost %} + + {% endif %}
Channel page
@@ -299,8 +303,9 @@ https://stackoverflow.com/a/35153397 + @@ -377,12 +382,8 @@ var video_card_first_selected = null; function select_all() { video_card_first_selected = null; - for (const video_card of document.getElementsByClassName("video_card")) + for (const video_card of document.querySelectorAll(".video_card:not(.hidden)")) { - if (video_card.classList.contains("hidden")) - { - continue; - } video_card.classList.add("video_card_selected"); } } @@ -437,8 +438,7 @@ function select_one(event) function select_shift(event) { - let video_cards = Array.from(document.getElementsByClassName("video_card")); - video_cards = video_cards.filter(card => ! card.classList.contains("hidden")) + const video_cards = Array.from(document.querySelectorAll(".video_card:not(.hidden)")); let start_index = video_cards.indexOf(video_card_first_selected); let end_index = video_cards.indexOf(event.target); @@ -739,7 +739,19 @@ function set_queuefile_extension_callback(response) { set_queuefile_extension_input.value = extension; } +} +function show_download_directory_form() +{ + function callback(response) + { + if (response.meta.status !== 200) + { + alert(JSON.stringify(response)); + return; + } + } + api.channels.show_download_directory(CHANNEL_ID, callback); } if (CHANNEL_ID)