Skip to content

Commit

Permalink
fix: bt task copy link bug agalwood#39
Browse files Browse the repository at this point in the history
  • Loading branch information
agalwood committed Feb 19, 2019
1 parent 4d024eb commit 5d93d4d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
15 changes: 10 additions & 5 deletions src/renderer/components/Task/TaskItemActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@

<script>
import is from 'electron-is'
import clipboard from 'clipboard-polyfill'
import { mapState } from 'vuex'
import * as clipboard from 'clipboard-polyfill'
import '@/components/Icons/task-start-line'
import '@/components/Icons/task-pause-line'
import '@/components/Icons/delete'
Expand Down Expand Up @@ -177,10 +178,14 @@
})
},
onLinkClick: function () {
const uri = getTaskUri(this.task)
clipboard.writeText(uri)
.then(() => {
this.$msg.success(this.$t('task.copy-link-success'))
this.$store.dispatch('app/fetchEngineOptions')
.then((data) => {
const { btTracker } = data
const uri = getTaskUri(this.task, btTracker)
clipboard.writeText(uri)
.then(() => {
this.$msg.success(this.$t('task.copy-link-success'))
})
})
},
onInfoClick: function () {
Expand Down
26 changes: 24 additions & 2 deletions src/shared/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
isEmpty,
isNaN,
compact,
difference,
parseInt,
isFunction,
camelCase,
Expand Down Expand Up @@ -164,11 +165,11 @@ export function getTaskFullPath (task) {
return result
}

export function getTaskUri (task) {
export function getTaskUri (task, btTracker = []) {
const { files } = task
let result = ''
if (checkTaskIsBT(task)) {
result = '种子任务'
result = buildMagnetLink(task, btTracker)
return result
}

Expand All @@ -180,6 +181,27 @@ export function getTaskUri (task) {
return result
}

export function buildMagnetLink (task, btTracker = []) {
const { bittorrent, infoHash } = task
const { announceList, info: { name } } = bittorrent
const trackers = difference(announceList, btTracker)

let params = [
`magnet:?xt=urn:btih:${infoHash}`
]
if (name) {
params.push(`dn=${encodeURI(name)}`)
}

trackers.forEach((tracker) => {
params.push(`tr=${encodeURI(tracker)}`)
})

const result = params.join('&')

return result
}

export function checkTaskTitleIsEmpty (task) {
const { files, bittorrent } = task
const [file] = files
Expand Down

0 comments on commit 5d93d4d

Please sign in to comment.