diff --git a/index.js b/index.js index d8ecf90..4b36bd7 100644 --- a/index.js +++ b/index.js @@ -423,10 +423,29 @@ io.on('connection', function(socket) updateTorrentTrackers(hash); }); - /* - socket.on('topTorrents', function(params, callback) + socket.on('topTorrents', function(type, callback) { - mysqlPool.query('SELECT * FROM `torrents` ORDER BY seeders LIMIT 10', hash, function (error, rows) { + let where = ''; + let max = 20; + if(type && type.length > 0) + { + where += ' and contentType = ' + mysqlPool.escape(type) + ' '; + max = 15; + + if(type == 'hours') + { + where = ' and `added` > DATE_SUB(NOW(), INTERVAL 24 HOUR) ' + } + if(type == 'week') + { + where = ' and `added` > DATE_SUB(NOW(), INTERVAL 7 DAY) ' + } + if(type == 'month') + { + where = ' and `added` > DATE_SUB(NOW(), INTERVAL 7 DAY) ' + } + } + mysqlPool.query(`SELECT * FROM torrents WHERE seeders > 0 and (contentCategory is null or contentCategory != 'xxx') ${where} ORDER BY seeders + leechers DESC LIMIT ${max}`, function (error, rows) { if(!rows || rows.length == 0) { callback(undefined) return; @@ -439,7 +458,6 @@ io.on('connection', function(socket) callback(searchList); }); }); - */ socket.on('admin', function(callback) { diff --git a/src/recent-torrents.js b/src/recent-torrents.js index 02552d4..7c83c0b 100644 --- a/src/recent-torrents.js +++ b/src/recent-torrents.js @@ -139,6 +139,9 @@ export default class RecentTorrents extends Component { return ( + { + window.router('/top'); + }} /> { this.pauseAndContinue() }} /> diff --git a/src/router.js b/src/router.js index db6d087..ae961ac 100644 --- a/src/router.js +++ b/src/router.js @@ -6,6 +6,7 @@ import IndexPage from './index-page.js' import TorrentPage from './torrent-page.js' import DMCAPage from './dmca-page.js' import AdminPage from './admin-page.js' +import TopPage from './top-page.js' router('/', () => { //singleton @@ -33,4 +34,10 @@ router('/admi5p', () => { //singleton let pie = new PagesPie; pie.open(AdminPage, {replace: 'all'}); +}); + +router('/top', () => { + //singleton + let pie = new PagesPie; + pie.open(TopPage, {replace: 'all'}); }); \ No newline at end of file diff --git a/src/top-page.js b/src/top-page.js new file mode 100644 index 0000000..049ca89 --- /dev/null +++ b/src/top-page.js @@ -0,0 +1,78 @@ +import React from 'react'; +import Page from './page'; +import Footer from './footer'; +import { Header } from './index-page' + +import TorrentLine from './torrent' +import {List} from 'material-ui/List'; +import Subheader from 'material-ui/Subheader'; +import RaisedButton from 'material-ui/RaisedButton'; + +export default class TopPage extends Page { + constructor(props) { + super(props) + this.setTitle('Rats On The Boat - Torrents top'); + this.topTorrents = {}; + this.types = ['main', 'week', 'hours', 'month', 'video', 'audio', 'books', 'pictures', 'application', 'archive'] + this.descriptions = { + main: 'All', + video: 'Video', + audio: 'Audio/Music', + books: 'Books', + pictures: 'Pictures/Images', + application: 'Applications/Games', + archive: 'Archives', + week: 'Last week', + hours: 'Last 24 hours', + month: 'Last month' + } + } + componentDidMount() + { + super.componentDidMount(); + for(const type of this.types) + { + window.torrentSocket.emit('topTorrents', type == 'main' ? null : type, window.customLoader((data) => { + this.topTorrents[type] = data; + this.forceUpdate() + })) + } + } + render() { + return ( +
+
+
+ { + window.router('/') + }} /> + { + this.types.map((type) => { + const torrents = this.topTorrents[type]; + + if(!torrents) + return null; + + return ( + + + { + this.descriptions[type] + } + + { + torrents.map((torrent, index) => { + return + }) + } + + ) + + }) + } +
+
+ ); + } +}