Skip to content
This repository was archived by the owner on Mar 4, 2021. It is now read-only.

Commit f2cace9

Browse files
committed
feat: 优化qbt推送方法,使得每次add不会都先login
1 parent 19a00dd commit f2cace9

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

src/plugins/btclient/qbittorrent.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,22 @@ export const defaultQbittorrentConfig: QbittorrentTorrentClientConfig = {
2424

2525
export default class Qbittorrent implements TorrentClient {
2626
isLogin: boolean | null = null;
27-
lastLoginAt: number = 0;
27+
lastCheckLoginAt: number = 0;
2828
config: QbittorrentTorrentClientConfig;
2929

3030
constructor(options: Partial<QbittorrentTorrentClientConfig> = {}) {
3131
this.config = {...defaultQbittorrentConfig, ...options}
3232
}
3333

3434
async ping(): Promise<boolean> {
35-
const pong = await this.login();
36-
return pong.data === 'Ok.'
35+
try {
36+
const pong = await this.login();
37+
this.isLogin = pong.data === 'Ok.'
38+
this.lastCheckLoginAt = Date.now()
39+
return this.isLogin
40+
} catch (e) {
41+
return false
42+
}
3743
}
3844

3945
async login(): Promise<AxiosResponse> {
@@ -52,9 +58,8 @@ export default class Qbittorrent implements TorrentClient {
5258
headers?: any): Promise<AxiosResponse> {
5359
// qbt 默认Session时长 3600s,这里取 600s
5460
// FIXME 是否每次操作都login一下好些?就像PTPP一样
55-
if (this.isLogin === null || Date.now() + 600 * 1e3 > this.lastLoginAt) {
56-
await this.login()
57-
this.lastLoginAt = Date.now()
61+
if (this.isLogin === null || Date.now() - 600 * 1e3 > this.lastCheckLoginAt) {
62+
await this.ping()
5863
}
5964

6065
return await axios.request({

src/views/Gratitude/Donate.vue

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@
1818
<el-tag class="demonstration">
1919
支付宝
2020
</el-tag>
21-
<!--suppress NpmUsedModulesInstalled, HtmlUnknownTarget -->
22-
<el-image class="donate-img" src="/assets/donate/Rhilip/alipay.jpg" />
21+
<el-image class="donate-img" src="/assets/donate/Rhilip/alipay.jpg" lazy />
2322
</el-col>
2423
<el-col :span="12">
2524
<el-tag class="demonstration">
2625
微信支付
2726
</el-tag>
28-
<!--suppress NpmUsedModulesInstalled, HtmlUnknownTarget -->
29-
<el-image class="donate-img" src="/assets/donate/Rhilip/wechat.png" />
27+
<el-image class="donate-img" src="/assets/donate/Rhilip/wechat.png" lazy />
3028
</el-col>
3129
</el-row>
3230
</div>
@@ -41,8 +39,7 @@
4139
<el-tag class="demonstration">
4240
微信赞赏码
4341
</el-tag>
44-
<!--suppress NpmUsedModulesInstalled, HtmlUnknownTarget -->
45-
<el-image class="donate-img" src="/assets/donate/ledccn/wechat.png" />
42+
<el-image class="donate-img" src="/assets/donate/ledccn/wechat.png" lazy />
4643
</el-col>
4744
</el-row>
4845
</div>

src/views/Mission.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
</div>
4545
<div>
4646
<el-scrollbar>
47-
<div style="height: 295px">
47+
<div style="height: 285px">
4848
<pre v-if="logId !== ''">{{ formatLogs(logs) }}</pre>
4949
</div>
5050
</el-scrollbar>

0 commit comments

Comments
 (0)