From 2ad85ad69aab9d9071a22182aa2f1a8d4c18d4e6 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Wed, 1 Sep 2021 23:37:43 -0700 Subject: [PATCH] Add Channel.set_download_directory. --- .../backend/endpoints/channel_endpoints.py | 17 ++++++++ frontends/ycdl_flask/static/js/api.js | 9 +++++ frontends/ycdl_flask/templates/channel.html | 20 ++++++++++ ycdl/objects.py | 40 ++++++++++++++++++- ycdl/ycdldb.py | 6 +-- 5 files changed, 87 insertions(+), 5 deletions(-) diff --git a/frontends/ycdl_flask/backend/endpoints/channel_endpoints.py b/frontends/ycdl_flask/backend/endpoints/channel_endpoints.py index 066a483..c416339 100644 --- a/frontends/ycdl_flask/backend/endpoints/channel_endpoints.py +++ b/frontends/ycdl_flask/backend/endpoints/channel_endpoints.py @@ -2,6 +2,7 @@ import flask; from flask import request import itertools from voussoirkit import flasktools +from voussoirkit import pathclass import ycdl @@ -157,6 +158,22 @@ def post_set_automark(channel_id): return flasktools.make_json_response({}) +@site.route('/channel//set_download_directory', methods=['POST']) +def post_set_download_directory(channel_id): + download_directory = request.form['download_directory'] + channel = common.ycdldb.get_channel(channel_id) + + try: + channel.set_download_directory(download_directory) + except pathclass.NotDirectory: + exc = { + 'error_type': 'NOT_DIRECTORY', + 'error_message': f'"{download_directory}" is not a directory.', + } + return flasktools.make_json_response(exc, status=400) + + return flasktools.make_json_response({}) + @site.route('/channel//set_queuefile_extension', methods=['POST']) def post_set_queuefile_extension(channel_id): extension = request.form['extension'] diff --git a/frontends/ycdl_flask/static/js/api.js b/frontends/ycdl_flask/static/js/api.js index b3aabba..774c9af 100644 --- a/frontends/ycdl_flask/static/js/api.js +++ b/frontends/ycdl_flask/static/js/api.js @@ -47,6 +47,15 @@ function set_automark(channel_id, state, callback) return common.post(url, data, callback); } +api.channels.set_download_directory = +function set_download_directory(channel_id, download_directory, callback) +{ + const url = `/channel/${channel_id}/set_download_directory`; + const data = new FormData(); + data.append("download_directory", download_directory); + return common.post(url, data, callback); +} + api.channels.set_queuefile_extension = function set_queuefile_extension(channel_id, extension, callback) { diff --git a/frontends/ycdl_flask/templates/channel.html b/frontends/ycdl_flask/templates/channel.html index ce6747d..9f74766 100644 --- a/frontends/ycdl_flask/templates/channel.html +++ b/frontends/ycdl_flask/templates/channel.html @@ -274,6 +274,11 @@ https://stackoverflow.com/a/35153397 +
+ + +
+
Channel RSS