From bc8802b11e31b9b0d5a0af0819cbd42deb7cfd30 Mon Sep 17 00:00:00 2001 From: x1ao4 Date: Sun, 25 May 2025 23:34:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=87=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/run.py | 78 ++++++++++++++++++++++++++++++++++++++++ app/static/css/main.css | 5 +++ app/templates/index.html | 48 +++++++++++++++++++++++++ 3 files changed, 131 insertions(+) diff --git a/app/run.py b/app/run.py index 2f637b2..5225bd8 100644 --- a/app/run.py +++ b/app/run.py @@ -1010,6 +1010,84 @@ def get_user_info(): return jsonify({"success": True, "data": user_info_list}) +# 重置文件夹(删除文件夹内所有文件和相关记录) +@app.route("/reset_folder", methods=["POST"]) +def reset_folder(): + if not is_login(): + return jsonify({"success": False, "message": "未登录"}) + + # 获取请求参数 + save_path = request.json.get("save_path", "") + task_name = request.json.get("task_name", "") + + if not save_path: + return jsonify({"success": False, "message": "保存路径不能为空"}) + + try: + # 初始化夸克网盘客户端 + account = Quark(config_data["cookie"][0], 0) + + # 1. 获取文件夹ID + # 先检查是否已有缓存的文件夹ID + folder_fid = account.savepath_fid.get(save_path) + + # 如果没有缓存的ID,则尝试创建文件夹以获取ID + if not folder_fid: + mkdir_result = account.mkdir(save_path) + if mkdir_result.get("code") == 0: + folder_fid = mkdir_result["data"]["fid"] + account.savepath_fid[save_path] = folder_fid + else: + return jsonify({"success": False, "message": f"获取文件夹ID失败: {mkdir_result.get('message', '未知错误')}"}) + + # 2. 获取文件夹内的所有文件 + file_list = account.ls_dir(folder_fid) + if isinstance(file_list, dict) and file_list.get("error"): + return jsonify({"success": False, "message": f"获取文件列表失败: {file_list.get('error', '未知错误')}"}) + + # 收集所有文件ID + file_ids = [] + for item in file_list: + file_ids.append(item["fid"]) + + # 3. 删除所有文件 + deleted_files = 0 + if file_ids: + delete_result = account.delete(file_ids) + if delete_result.get("code") == 0: + deleted_files = len(file_ids) + + # 4. 删除相关的历史记录 + deleted_records = 0 + try: + # 初始化数据库 + db = RecordDB() + + # 查询与该保存路径相关的所有记录 + cursor = db.conn.cursor() + cursor.execute("SELECT id FROM transfer_records WHERE save_path = ?", (save_path,)) + record_ids = [row[0] for row in cursor.fetchall()] + + # 删除找到的所有记录 + for record_id in record_ids: + deleted_records += db.delete_record(record_id) + + except Exception as e: + logging.error(f">>> 删除记录时出错: {str(e)}") + # 即使删除记录失败,也返回文件删除成功 + + return jsonify({ + "success": True, + "message": f"重置成功,删除了 {deleted_files} 个文件和 {deleted_records} 条记录", + "deleted_files": deleted_files, + "deleted_records": deleted_records + }) + + except Exception as e: + logging.error(f">>> 重置文件夹时出错: {str(e)}") + return jsonify({"success": False, "message": f"重置文件夹时出错: {str(e)}"}) + + if __name__ == "__main__": init() reload_tasks() diff --git a/app/static/css/main.css b/app/static/css/main.css index 9ae9200..1d97288 100644 --- a/app/static/css/main.css +++ b/app/static/css/main.css @@ -805,6 +805,11 @@ main div[v-if="activeTab === 'config'"] .row.title:first-child { font-size: 0.98rem; } +/* 重置文件夹图标样式 */ +.bi-folder-x { + font-size: 0.98rem; +} + /* 恢复图标样式 */ .bi-reply { color: var(--dark-text-color); diff --git a/app/templates/index.html b/app/templates/index.html index 936284e..eb0e9bd 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -554,6 +554,7 @@
+
@@ -3536,6 +3537,53 @@ event.preventDefault(); } }, + resetFolder(index) { + // 重置文件夹 + this.formData.tasklist[index].savepath = this.formData.tasklist[index].savepath.split('/').slice(0, -1).join('/'); + if (this.formData.tasklist[index].savepath.endsWith('/')) { + this.formData.tasklist[index].savepath = this.formData.tasklist[index].savepath.slice(0, -1); + } + this.showToast('文件夹已重置'); + }, + resetFolder(index) { + // 获取当前任务的保存路径 + const savePath = this.formData.tasklist[index].savepath; + const taskName = this.formData.tasklist[index].taskname; + + if (!savePath) { + this.showToast('保存路径为空,无法重置'); + return; + } + + // 显示确认对话框 + if (confirm(`确定要重置文件夹「${savePath}」吗?`)) { + // 显示加载状态 + this.modalLoading = true; + + // 调用后端API + axios.post('/reset_folder', { + save_path: savePath, + task_name: taskName + }) + .then(response => { + if (response.data.success) { + this.showToast(`重置成功:删除了 ${response.data.deleted_files || 0} 个文件,${response.data.deleted_records || 0} 条记录`); + // 如果当前是历史记录页面,刷新记录 + if (this.activeTab === 'history') { + this.loadHistoryRecords(); + } + } else { + alert(response.data.message || '重置文件夹失败'); + } + this.modalLoading = false; + }) + .catch(error => { + console.error('重置文件夹出错:', error); + alert('重置文件夹出错: ' + (error.response?.data?.message || error.message)); + this.modalLoading = false; + }); + } + }, } });