import React from 'react'; import Page from './page'; import formatBytes from './format-bytes' import Footer from './footer'; import {List, ListItem} from 'material-ui/List'; import Subheader from 'material-ui/Subheader'; import Divider from 'material-ui/Divider'; import {Tabs, Tab} from 'material-ui/Tabs'; import ActionInfo from 'material-ui/svg-icons/action/info'; import RaisedButton from 'material-ui/RaisedButton'; import FontIcon from 'material-ui/FontIcon'; import FileFolder from 'material-ui/svg-icons/file/folder'; import NoImage from './images/no-image-icon.png' var moment = require('moment'); import RefreshIndicator from 'material-ui/RefreshIndicator'; let rating = require('./rating'); import LinearProgress from 'material-ui/LinearProgress'; import {fileTypeDetect} from './content' import {contentIcon} from './torrent' let buildFilesTree = (filesList) => { let rootTree = { __sizeBT: 0 }; filesList.forEach((file) => { let pathTree = file.path.split('/'); let currentItem = rootTree; pathTree.forEach((pathItem) => { if(!(pathItem in currentItem)) { currentItem[pathItem] = { __sizeBT: 0 } } currentItem = currentItem[pathItem] currentItem.__sizeBT += file.size; }) rootTree.__sizeBT += file.size; }); return rootTree; } const treeToTorrentFiles = (tree) => { let arr = []; for(let file in tree) { if(file == '__sizeBT') continue; arr.push( 1 ? : contentIcon(fileTypeDetect({path: file}))} />); } return arr; } const TorrentFiles = (props) => { let filesList = props.torrent.filesList; let tree = buildFilesTree(filesList); return ( { filesList.length > 0 ?
Content of the torrent: {treeToTorrentFiles(tree)}
:
Processing files...
}
); }; const TorrentInformation = (props) => { let torrent = props.torrent; return ( Information about torrent } backgroundColor={blue500} />} rightIcon={} primaryText="Torrent Name" secondaryText={{torrent.name}} /> } backgroundColor={yellow600} />} rightIcon={} primaryText="Torrent Size" secondaryText={formatBytes(torrent.size)} /> } backgroundColor={yellow600} />} rightIcon={} primaryText="Torrent contains files" secondaryText={torrent.files} onClick={() => { if(!props.parent) return props.parent.setState({ value: 'files' }) }} /> } backgroundColor={yellow600} />} rightIcon={} primaryText="Indexed/Added torrent date" secondaryText={moment(torrent.added).format('MMMM Do YYYY, h:mm:ss')} /> } backgroundColor={yellow600} />} rightIcon={} primaryText="Content type" secondaryText={torrent.contentType || 'unknown'} /> } backgroundColor={yellow600} />} rightIcon={} primaryText="Category" secondaryText={torrent.contentCategory || 'unknown'} /> ); } export default class TorrentPage extends Page { constructor(props) { super(props); this.state = { value: 'info', searchingIndicator: false, voting: false, voted: false, }; this.setTitle('Information about torrent'); } changeTab(tab) { if(this.state.value != tab) { this.setState({ value: tab }); console.log('change'); } } onSwipeRight() { this.changeTab('files'); } onSwipeLeft() { this.changeTab('info'); } handleChange = (value) => { if(value == 'main') { window.router('/'); return; } this.setState({ value: value, }); }; getTorrentInfo() { window.torrentSocket.emit('torrent', this.props.hash, {files: true}, window.customLoader((data) => { if(data) { this.torrent = data this.setTitle(this.torrent.name + ' - RatsOnTheBoat.org'); if(this.torrent.contentCategory == 'xxx') { this.setMetaTag('robots', 'noindex'); } //this.forceUpdate(); // вызывается через searchingIndicator // Получаем более новую статистику пира if((new Date).getTime() - this.torrent.trackersChecked > 10 * 60 * 1000) { window.torrentSocket.emit('checkTrackers', this.torrent.hash); } } }, () => { this.setState({ searchingIndicator: true }); }, () => { this.setState({ searchingIndicator: false }); })); } componentDidMount() { super.componentDidMount(); this.getTorrentInfo(); this.filesUpdated = (hash) => { if(this.props.hash != hash) return; this.getTorrentInfo(); } window.torrentSocket.on('filesReady', this.filesUpdated); this.trackerUpdate = (info) => { if(this.props.hash != info.hash) return; if(!this.torrent) return; Object.assign(this.torrent, info); this.forceUpdate(); } window.torrentSocket.on('trackerTorrentUpdate', this.trackerUpdate); this.onVote = ({hash, good, bad}) => { if(this.props.hash != hash) return; if(!this.torrent) return; this.torrent.good = good; this.torrent.bad = bad; this.forceUpdate(); } window.torrentSocket.on('vote', this.onVote); } componentWillUnmount() { if(this.filesUpdated) window.torrentSocket.off('filesReady', this.filesUpdated); if(this.trackerUpdate) window.torrentSocket.off('trackerTorrentUpdate', this.trackerUpdate); if(this.onVote) window.torrentSocket.off('vote', this.onVote); if(this.torrent && this.torrent.contentCategory == 'xxx') { this.removeMetaTag('robots'); } } vote(good) { if(!this.torrent) return; this.setState({ voting: true }); window.torrentSocket.emit('vote', this.torrent.hash, !!good, window.customLoader((success) => { this.setState({ voted: true, voting: false }); })); } render() { const style = { refresh: { display: 'inline-block', position: 'relative', }, }; if(this.state.searchingIndicator) { return (
); } let torrentRating; if(this.torrent) { torrentRating = Math.round(rating(this.torrent.good, this.torrent.bad) * 100); } return (
{ this.torrent ?
} />
BTIH:
{this.torrent.hash}
{ this.torrent.seeders || this.torrent.leechers || this.torrent.completed ?
seeders: {this.torrent.seeders}
leechers: {this.torrent.leechers}
completed: {this.torrent.completed}
: null } { !this.state.voted && !this.state.voting ?
} onClick={() => this.vote(true)} /> } onClick={() => this.vote(false)} />
: this.state.voting ?
voting...
:
Thank you for voting!
} { this.torrent.good > 0 || this.torrent.bad > 0 ?
= 50 ? '#00E676' : '#FF3D00'} style={{ height: '5px', }} />
= 50 ? '#00E676' : '#FF3D00'}}>Torrent rating: {torrentRating}%
: null }
: null }
); } }