nfp_sites/app/widgets/fileinfo.js

79 lines
2.2 KiB
JavaScript
Raw Normal View History

2019-09-14 19:03:38 +00:00
const Fileinfo = {
2019-10-01 11:35:00 +00:00
getPrefix: function(vnode) {
2019-09-14 19:03:38 +00:00
if (!vnode.attrs.file.filename.endsWith('.torrent')) {
return vnode.attrs.file.filename.split('.').slice(-1)
}
if (vnode.attrs.file.filename.indexOf('720 ') >= 0) {
return '720p'
}
if (vnode.attrs.file.filename.indexOf('1080 ') >= 0) {
return '1080p'
}
if (vnode.attrs.file.filename.indexOf('480 ') >= 0) {
return '480p'
}
return 'Other'
},
2019-10-01 11:35:00 +00:00
getTitle: function(vnode) {
2019-09-14 19:03:38 +00:00
if (vnode.attrs.file.meta.torrent) {
return vnode.attrs.file.meta.torrent.name
}
return vnode.attrs.file.filename
},
2019-10-01 11:35:00 +00:00
getDownloadName: function(vnode) {
2019-09-14 19:03:38 +00:00
if (vnode.attrs.file.meta.torrent) {
return 'Torrent'
}
return 'Download'
},
2019-10-01 11:35:00 +00:00
getSize: function(orgSize) {
2019-09-14 19:03:38 +00:00
var size = orgSize
var i = -1
var byteUnits = [' kB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB']
do {
size = size / 1024
i++
} while (size > 1024)
return Math.max(size, 0.1).toFixed(1) + byteUnits[i]
},
view: function(vnode) {
return m('fileinfo', { class: vnode.attrs.slim ? 'slim' : ''}, [
m('div.filetitle', [
m('span.prefix', this.getPrefix(vnode) + ':'),
m('a', {
target: '_blank',
2019-10-01 03:45:44 +00:00
rel: 'noopener',
2019-09-14 19:03:38 +00:00
href: vnode.attrs.file.url,
}, this.getDownloadName(vnode)),
vnode.attrs.file.magnet
? m('a', {
href: vnode.attrs.file.magnet,
}, 'Magnet')
: null,
m('span', this.getTitle(vnode)),
]),
vnode.attrs.file.meta.torrent
&& !vnode.attrs.slim
&& vnode.attrs.file.meta.torrent.files.length > 1
&& (!vnode.attrs.trim || vnode.attrs.file.meta.torrent.files.length <= 4)
2019-09-14 19:03:38 +00:00
? m('ul', vnode.attrs.file.meta.torrent.files.map(function(file) {
return m('li', [
file.name + ' ',
m('span.meta', '(' + Fileinfo.getSize(file.size) + ')'),
])
}))
: null,
vnode.attrs.trim && vnode.attrs.file.meta.torrent.files.length > 4
? m('div.trimmed', '...' + vnode.attrs.file.meta.torrent.files.length + ' files...')
: null,
2019-09-14 19:03:38 +00:00
])
},
}
module.exports = Fileinfo