This repository was archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 969
/
Copy pathtorrentFileList.js
62 lines (57 loc) · 1.8 KB
/
torrentFileList.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const prettierBytes = require('prettier-bytes')
const React = require('react')
const SortableTable = require('../../components/sortableTable')
class TorrentFileList extends React.Component {
render () {
const { torrent, stateOwner } = this.props
const files = torrent && torrent.files
let content
if (files == null) {
content = <div data-l10n-id='missingFilesList' />
} else if (files.length === 0) {
content = <div data-l10n-id='loadingFilesList' />
} else {
content = [
<SortableTable
headings={['num', 'name', 'downloadFile', 'size']}
defaultHeading='num'
defaultHeadingSortOrder='asc'
rows={files.map((file, i) => [
i + 1,
{cell: this.renderFileLink(file, false)},
{cell: this.renderFileLink(file, true)},
prettierBytes(file.length)
])}
rowObjects={files}
columnClassNames={['num', 'name', 'downloadFile', 'size']}
addHoverClass
stateOwner={stateOwner} />
]
}
return (
<div className='torrentFileList'>
<div data-l10n-id='files' className='sectionTitle' />
{content}
</div>
)
}
renderFileLink (file, isDownload) {
const { torrentId, torrent, serverUrl } = this.props
const ix = torrent.files.indexOf(file)
if (isDownload) {
if (serverUrl) {
const httpURL = serverUrl + '/' + ix
return <a href={httpURL} download={file.name}>⇩</a>
} else {
return <div /> // No download links until the server is ready
}
} else {
const suffix = /^https?:/.test(torrentId)
? '#ix=' + ix
: '&ix=' + ix
const href = torrentId + suffix
return <a href={href}>{file.name}</a>
}
}
}
module.exports = TorrentFileList