From 3b5a998aaa26894d262cc36651fb5d94cdfc3f9e Mon Sep 17 00:00:00 2001 From: Zhao Zuohong Date: Sat, 4 Mar 2023 18:18:39 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20Select=20download=20path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/__init__.py | 25 ++- frontend/src/views/AudioDownload.vue | 6 +- frontend/src/views/InputVideoNumber.vue | 22 ++- main.py | 10 + manager/__init__.py | 17 +- poetry.lock | 239 +++++++++++++++++++++++- pyproject.toml | 2 + 7 files changed, 303 insertions(+), 18 deletions(-) create mode 100755 main.py diff --git a/backend/__init__.py b/backend/__init__.py index 69c7e7f..56d77f8 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -1,12 +1,23 @@ -from bottle import request, response, Bottle, HTTPResponse +from bottle import request, response, Bottle, static_file from manager import Manager from json import dumps from pathlib import Path +from tkinter import filedialog as fd manager = Manager() app = Bottle() +@app.get("/") +def frontend(): + return static_file("index.html", root="frontend/dist") + + +@app.get("/") +def frontend(filepath): + return static_file(filepath, root="frontend/dist") + + @app.post("/video") def add_videos(): nvlist = request.json["nvlist"].split() @@ -20,8 +31,14 @@ def get_progress(): return dumps(manager.get_progress()) -@app.post("/download") +@app.get("/download") def download(): - parent_dir = Path(request.json["parent_dir"]) - manager.download(parent_dir) + manager.download() return "OK" + + +@app.get("/path") +def get_path(): + path = fd.askdirectory() + manager.path = path + return path diff --git a/frontend/src/views/AudioDownload.vue b/frontend/src/views/AudioDownload.vue index ef29dbf..6b2190f 100644 --- a/frontend/src/views/AudioDownload.vue +++ b/frontend/src/views/AudioDownload.vue @@ -57,14 +57,12 @@ const progress_info = computed(() => { }); function start_download() { - axios.post("http://localhost:8000/download", { - parent_dir: "/home/zhao/Desktop/tmp", - }); + axios.get("/download"); } onMounted(() => { setInterval(() => { - axios.get("http://localhost:8000/progress").then((resp) => { + axios.get("/progress").then((resp) => { state_list.value = resp.data; }); }, 200); diff --git a/frontend/src/views/InputVideoNumber.vue b/frontend/src/views/InputVideoNumber.vue index 942ecc6..5a8bf90 100644 --- a/frontend/src/views/InputVideoNumber.vue +++ b/frontend/src/views/InputVideoNumber.vue @@ -8,18 +8,38 @@ const nvlist = ref(""); const axios = inject("axios"); +const path = ref(""); + onMounted(() => { input.value.focus(); }); function sendNVList() { - axios.post("http://localhost:8000/video", { nvlist: nvlist.value }); + axios.post("/video", { nvlist: nvlist.value }); emit("change-stage"); } + +function get_path() { + axios.get("/path").then(({ data }) => { + path.value = data; + input.value.focus(); + }); +}