From 1c14ef362de6903fbb21e08a6dcdc17f4117f892 Mon Sep 17 00:00:00 2001 From: ngfchl Date: Thu, 29 Sep 2022 19:06:14 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BC=98=E5=8C=96=E5=B7=B2=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E7=9A=84=E7=A7=8D=E5=AD=90=E6=8E=A7=E5=88=B6=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=202.=20=E4=BB=8E=E4=B8=8B=E8=BD=BD=E5=99=A8=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=9B=B4=E5=A4=9A=E4=BF=A1=E6=81=AF=EF=BC=8C=E5=BC=80?= =?UTF-8?q?=E5=A7=8B=E9=80=90=E6=AD=A5=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- auto_pt/views.py | 24 +++++++++++++++++------- templates/auto_pt/downloading.html | 17 +++++++++-------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/auto_pt/views.py b/auto_pt/views.py index a75957e..812f0da 100644 --- a/auto_pt/views.py +++ b/auto_pt/views.py @@ -107,12 +107,17 @@ def get_downloading(request): ) try: qb_client.auth_log_in() - torrents = qb_client.torrents_info() - transfer = qb_client.transfer_info() + # transfer = qb_client.transfer_info() + # torrents = qb_client.torrents_info() main_data = qb_client.sync_maindata() - print(transfer) - print(json.dumps(main_data)) - for torrent in torrents: + torrent_list = main_data.get('torrents') + print(type(torrent_list)) + # print(json.dumps(main_data)) + torrents = [] + for index, torrent in torrent_list.items(): + # print(type(torrent)) + # print(torrent) + # torrent = json.loads(torrent) # 时间处理 # 添加于 torrent['added_on'] = datetime.fromtimestamp(torrent.get('added_on')).strftime( @@ -149,10 +154,15 @@ def get_downloading(request): torrent['uploaded'] = '' if torrent['uploaded'] == 0 else torrent['uploaded'] torrent['upspeed'] = '' if torrent['upspeed'] == 0 else torrent['upspeed'] torrent['dlspeed'] = '' if torrent['dlspeed'] == 0 else torrent['dlspeed'] + torrent['hash'] = index + torrents.append(torrent) print(len(torrents)) - return JsonResponse(CommonResponse.success(data=torrents).to_dict(), safe=False) + main_data['torrents'] = torrents + # return JsonResponse(CommonResponse.success(data=torrents).to_dict(), safe=False) + return JsonResponse(CommonResponse.success(data=main_data).to_dict(), safe=False) except Exception as e: print(e) + # raise return JsonResponse(CommonResponse.error( msg='连接下载器出错咯!' ).to_dict(), safe=False) @@ -178,7 +188,7 @@ def control_torrent(request): # 根据指令字符串定位函数 command_exec = getattr(qb_client.torrents, command) print(command_exec) - command_exec(torrent_hashes=ids.split(',')) + command_exec(torrent_hashes=ids.split(','), enable=True) # 延缓2秒等待操作生效 time.sleep(2) except Exception as e: diff --git a/templates/auto_pt/downloading.html b/templates/auto_pt/downloading.html index c893b90..742e167 100644 --- a/templates/auto_pt/downloading.html +++ b/templates/auto_pt/downloading.html @@ -391,9 +391,10 @@ console.log('获取下载器列表成功', res.data) if (res.data.code === 0) { this.downloaders = res.data.data + console.log(this.torrents) this.downloader_id = this.downloaders[0].id this.get_downloading(this.downloader_id) - console.log(this.torrents.length) + {#console.log(this.torrents.length)#} this.loading = false } else { this.loading = false @@ -435,15 +436,15 @@ } } ).then(res => { + {#console.log(res.data.data.torrents)#} if (res.data.code === 0) { - console.log(res.data.data.length) - this.torrents = res.data.data - this.$message({ - type: 'success', - message: '任务加载成功!!' - }) + this.torrents = res.data.data.torrents + //this.$message({ + // type: 'success', + // message: '任务加载成功!!' + //}) } else { - console.log(res.data.data) + {#console.log(res.data.data)#} this.$message({ type: 'warning', message: '任务加载出错!!'