perf: Add export torrent to trc menu (#625) @Larsluph

This commit is contained in:
Rémi Marseault 2023-01-27 15:06:52 +01:00 committed by GitHub
parent f8fcafa1b1
commit 353e26d51d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 2 deletions

View file

@ -235,6 +235,12 @@
</v-list-item>
</v-list>
</v-menu>
<v-list-item link @click="exportTorrents">
<v-icon>{{ (multiple) ? mdiDownloadMultiple : mdiDownload }}</v-icon>
<v-list-item-title class="ml-2 list-item__title">
{{ $tc('rightClick.export', (multiple) ? 2 : 1) | titleCase }}
</v-list-item-title>
</v-list-item>
<v-divider v-if="!multiple" />
<v-list-item v-if="!multiple" link @click="showInfo">
<v-icon>{{ mdiInformation }}</v-icon>
@ -276,7 +282,9 @@ import {
mdiShape,
mdiSpeedometerSlow,
mdiTag,
mdiTagOff
mdiTagOff,
mdiDownload,
mdiDownloadMultiple
} from '@mdi/js'
export default {
@ -319,7 +327,9 @@ export default {
mdiSpeedometerSlow,
mdiChevronUp,
mdiChevronDown,
mdiContentCopy
mdiContentCopy,
mdiDownload,
mdiDownloadMultiple
}
},
computed: {
@ -439,6 +449,20 @@ export default {
document.body.removeChild(textArea)
}
this.$toast.success(this.$i18n.t("toast.copySuccess").toString())
},
async exportTorrents() {
this.hashes.forEach(hash => {
qbit.exportTorrent(hash).then(blob => {
const url = window.URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.style.opacity = '0'
link.setAttribute('download', `${hash}.torrent`)
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
})
})
}
}
}

View file

@ -507,6 +507,7 @@
"notags": "No Tags",
"limit": "Set Limit",
"copy": "Copy",
"export": "Export Torrent | Export Torrents",
"info": "Show Info"
}
}

View file

@ -496,6 +496,7 @@
"notags": "Aucun tag",
"limit": "Définir la limite",
"copy": "Copier",
"export": "Exporter le torrent | Exporter les torrents",
"info": "Propriétés"
}
}

View file

@ -442,6 +442,17 @@ export class QBitApi {
await this.execute('/torrents/editCategory', params)
}
async exportTorrent(hash: string): Promise<Blob> {
return this.axios.get('/torrents/export', {
params: {hash},
responseType: "arraybuffer",
headers: {
"Accept": "application/x-bittorrent"
}
})
.then(res => new Blob([res.data], {type: "application/x-bittorrent"}))
}
/** Search **/
async getSearchPlugins(): Promise<SearchPlugin[]> {
return this.axios.get('/search/plugins').then(res => res.data)