mirror of
https://github.com/VueTorrent/VueTorrent.git
synced 2024-11-28 21:18:54 +03:00
feat: add support for setting global speed limits (#406)
This commit is contained in:
parent
1667bc6796
commit
23fee419fd
3 changed files with 71 additions and 6 deletions
|
@ -1,10 +1,12 @@
|
||||||
<template>
|
<template>
|
||||||
<v-card
|
<v-card
|
||||||
|
v-ripple
|
||||||
flat
|
flat
|
||||||
rounded="md"
|
rounded="md"
|
||||||
color="secondary"
|
color="secondary"
|
||||||
class="speedCard"
|
class="speedCard"
|
||||||
data-testid="SpeedCard"
|
data-testid="SpeedCard"
|
||||||
|
@click="open"
|
||||||
>
|
>
|
||||||
<v-layout row align-center :class="color + '--text'">
|
<v-layout row align-center :class="color + '--text'">
|
||||||
<v-flex v-if="icon" xs2 class="pl-1">
|
<v-flex v-if="icon" xs2 class="pl-1">
|
||||||
|
@ -31,6 +33,8 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { General } from '@/mixins'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'SpeedCard',
|
name: 'SpeedCard',
|
||||||
filters: {
|
filters: {
|
||||||
|
@ -43,7 +47,13 @@ export default {
|
||||||
return `${parseFloat((value / Math.pow(c, f)).toFixed(d))}`
|
return `${parseFloat((value / Math.pow(c, f)).toFixed(d))}`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
props: ['color', 'icon', 'value']
|
mixins: [General],
|
||||||
|
props: ['color', 'icon', 'value'],
|
||||||
|
methods: {
|
||||||
|
open() {
|
||||||
|
this.createModal('SpeedLimitModal', { mode: this.color })
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -51,5 +61,6 @@ export default {
|
||||||
.speedCard {
|
.speedCard {
|
||||||
padding: 20px 20px !important;
|
padding: 20px 20px !important;
|
||||||
font-size: 1.10em;
|
font-size: 1.10em;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -76,13 +76,23 @@ export default {
|
||||||
return this.$vuetify.breakpoint.xsOnly
|
return this.$vuetify.breakpoint.xsOnly
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
async created() {
|
||||||
switch (this.mode) {
|
switch (this.mode) {
|
||||||
case 'download':
|
case 'download':
|
||||||
this.limit = this.torrent.dl_limit > 0 ? this.limit = this.torrent.dl_limit / 1024 : '∞'
|
if (this.isGlobal()) {
|
||||||
|
const limit = await qbit.getGlobalDownloadLimit()
|
||||||
|
this.limit = this.formatLimit(limit)
|
||||||
|
} else {
|
||||||
|
this.limit = this.formatLimit(this.torrent?.dl_limit)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case 'upload':
|
case 'upload':
|
||||||
this.limit = this.torrent.up_limit > 0 ? this.torrent.up_limit / 1024 : '∞'
|
if (this.isGlobal()) {
|
||||||
|
const limit = await qbit.getGlobalUploadLimit()
|
||||||
|
this.limit = this.formatLimit(limit)
|
||||||
|
} else {
|
||||||
|
this.limit = this.formatLimit(this.torrent?.up_limit)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
|
@ -92,16 +102,34 @@ export default {
|
||||||
setLimit() {
|
setLimit() {
|
||||||
switch (this.mode) {
|
switch (this.mode) {
|
||||||
case 'download':
|
case 'download':
|
||||||
qbit.setDownloadLimit([this.hash], this.limit > 0 ? this.limit * 1024 : NaN)
|
if (this.isGlobal()) {
|
||||||
|
qbit.setGlobalDownloadLimit(this.exportLimit())
|
||||||
|
} else {
|
||||||
|
qbit.setDownloadLimit([this.hash], this.exportLimit())
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case 'upload':
|
case 'upload':
|
||||||
qbit.setUploadLimit([this.hash], this.limit > 0 ? this.limit * 1024 : NaN)
|
if (this.isGlobal()) {
|
||||||
|
qbit.setGlobalUploadLimit(this.exportLimit())
|
||||||
|
} else {
|
||||||
|
qbit.setUploadLimit([this.hash], this.exportLimit())
|
||||||
|
}
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
this.close()
|
this.close()
|
||||||
},
|
},
|
||||||
|
isGlobal() {
|
||||||
|
return this.torrent ? false : true
|
||||||
|
},
|
||||||
|
formatLimit(limit) {
|
||||||
|
return limit > 0 ? limit / 1024 : '∞'
|
||||||
|
},
|
||||||
|
exportLimit() {
|
||||||
|
return this.limit > 0 ? this.limit * 1024 : NaN
|
||||||
|
},
|
||||||
close() {
|
close() {
|
||||||
this.dialog = false
|
this.dialog = false
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,6 +225,32 @@ class Qbit {
|
||||||
return this.torrentAction('setUploadLimit', hashes, { limit })
|
return this.torrentAction('setUploadLimit', hashes, { limit })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getGlobalDownloadLimit() {
|
||||||
|
const { data } = await this.axios.get('/transfer/downloadLimit')
|
||||||
|
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
async getGlobalUploadLimit() {
|
||||||
|
const { data } = await this.axios.get('/transfer/uploadLimit')
|
||||||
|
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
setGlobalDownloadLimit(limit) {
|
||||||
|
const formData = new FormData()
|
||||||
|
formData.append('limit', limit)
|
||||||
|
|
||||||
|
return this.axios.post('/transfer/setDownloadLimit', formData)
|
||||||
|
}
|
||||||
|
|
||||||
|
setGlobalUploadLimit(limit) {
|
||||||
|
const formData = new FormData()
|
||||||
|
formData.append('limit', limit)
|
||||||
|
|
||||||
|
return this.axios.post('/transfer/setUploadLimit', formData)
|
||||||
|
}
|
||||||
|
|
||||||
setShareLimit(hashes, ratioLimit, seedingTimeLimit) {
|
setShareLimit(hashes, ratioLimit, seedingTimeLimit) {
|
||||||
return this.torrentAction('setShareLimits', hashes, { ratioLimit, seedingTimeLimit })
|
return this.torrentAction('setShareLimits', hashes, { ratioLimit, seedingTimeLimit })
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue