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'
|
|
|
|
}
|
2019-10-03 13:40:09 +00:00
|
|
|
if (vnode.attrs.file.filename.toLowerCase().indexOf('flac') >= 0) {
|
2019-10-03 13:34:16 +00:00
|
|
|
return 'FLAC'
|
|
|
|
}
|
2019-10-03 13:40:09 +00:00
|
|
|
if (vnode.attrs.file.filename.toLowerCase().indexOf('mp3') >= 0) {
|
2019-10-03 13:34:16 +00:00
|
|
|
return 'MP3'
|
|
|
|
}
|
2019-10-03 13:40:09 +00:00
|
|
|
if (vnode.attrs.file.filename.toLowerCase().indexOf('psd') >= 0) {
|
|
|
|
return 'PSD'
|
|
|
|
}
|
|
|
|
if (vnode.attrs.file.filename.toLowerCase().indexOf('.zip') >= 0) {
|
|
|
|
return 'ZIP'
|
|
|
|
}
|
2019-09-14 19:03:38 +00:00
|
|
|
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' : ''}, [
|
2022-08-05 14:26:29 +00:00
|
|
|
m('p', [
|
|
|
|
m('span', this.getPrefix(vnode) + ':'),
|
2019-09-14 19:03:38 +00:00
|
|
|
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,
|
2022-08-05 14:26:29 +00:00
|
|
|
this.getTitle(vnode),
|
2019-09-14 19:03:38 +00:00
|
|
|
]),
|
2019-10-02 17:40:32 +00:00
|
|
|
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,
|
2019-10-03 14:34:12 +00:00
|
|
|
vnode.attrs.trim
|
|
|
|
&& vnode.attrs.file.meta.torrent
|
|
|
|
&& vnode.attrs.file.meta.torrent.files.length > 4
|
2019-10-02 17:40:32 +00:00
|
|
|
? m('div.trimmed', '...' + vnode.attrs.file.meta.torrent.files.length + ' files...')
|
|
|
|
: null,
|
2019-09-14 19:03:38 +00:00
|
|
|
])
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Fileinfo
|