From 7c6df55780e1c5acb16b78c999f92222839a559e Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Wed, 1 Feb 2017 11:04:45 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=82=D0=B8=D0=BF=D0=B0=20=D1=84?= =?UTF-8?q?=D0=B0=D0=B9=D0=BB=D0=B0=20=D0=B2=20=D1=81=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=BA=D0=B5=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 2 +- lib/content.js | 6 +- patches/bad.js | 2 +- patches/clear.js | 2 +- patches/patch1.js | 2 +- src/torrent-page.js | 4 +- src/torrent.js | 253 ++++++++++++++++++++++---------------------- 7 files changed, 137 insertions(+), 134 deletions(-) diff --git a/index.js b/index.js index e148982..9917f37 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,7 @@ var sm = require('sitemap'); var phantomjs = require('phantomjs-prebuilt') var ipaddr = require('ipaddr.js'); -const torrentTypeDetect = require('./lib/content'); +const {torrentTypeDetect} = require('./lib/content'); // Start server server.listen(config.httpPort); diff --git a/lib/content.js b/lib/content.js index 2cb4a6f..a62906c 100644 --- a/lib/content.js +++ b/lib/content.js @@ -274,7 +274,7 @@ const detectSubCategory = (torrent, files, typesPriority, contentType) => { } } -const fileDetect = (file) => { +const fileTypeDetect = (file) => { let name = file.path.split('/').pop(); let extension = name.split('.').pop(); if(name.length == 0) @@ -291,7 +291,7 @@ const torrentTypeDetect = (torrent, files) => { for(let i = 0; i < files.length; i++) { let file = files[i]; - let type = fileDetect(file) + let type = fileTypeDetect(file) if(type) { if(!typesPriority[type]) @@ -309,4 +309,4 @@ const torrentTypeDetect = (torrent, files) => { detectSubCategory(torrent, files, typesPriority, torrent[ContentTypeProp]); } -module.exports = torrentTypeDetect; +module.exports = {torrentTypeDetect, fileTypeDetect}; diff --git a/patches/bad.js b/patches/bad.js index 7dcedb6..b7f7fd9 100644 --- a/patches/bad.js +++ b/patches/bad.js @@ -1,5 +1,5 @@ const mysql = require('mysql'); -const torrentTypeDetect = require('../lib/content'); +const {torrentTypeDetect} = require('../lib/content'); const mysqlSettings = { host : 'localhost', diff --git a/patches/clear.js b/patches/clear.js index f96f49a..363795f 100644 --- a/patches/clear.js +++ b/patches/clear.js @@ -1,5 +1,5 @@ const mysql = require('mysql'); -const torrentTypeDetect = require('../lib/content'); +const {torrentTypeDetect} = require('../lib/content'); const mysqlSettings = { host : 'localhost', diff --git a/patches/patch1.js b/patches/patch1.js index 1705ef1..4c6a292 100644 --- a/patches/patch1.js +++ b/patches/patch1.js @@ -1,5 +1,5 @@ const mysql = require('mysql'); -const torrentTypeDetect = require('../lib/content'); +const {torrentTypeDetect} = require('../lib/content'); const mysqlSettings = { host : 'localhost', diff --git a/src/torrent-page.js b/src/torrent-page.js index 47278fa..e3db600 100644 --- a/src/torrent-page.js +++ b/src/torrent-page.js @@ -18,6 +18,8 @@ var moment = require('moment'); import RefreshIndicator from 'material-ui/RefreshIndicator'; let rating = require('../lib/rating'); import LinearProgress from 'material-ui/LinearProgress'; +import {fileTypeDetect} from '../lib/content' +import {contentIcon} from './torrent' let buildFilesTree = (filesList) => { let rootTree = { @@ -55,7 +57,7 @@ const treeToTorrentFiles = (tree) => { nestedItems={treeToTorrentFiles(tree[file])} primaryTogglesNestedList={true} innerDivStyle={{wordBreak: 'break-word'}} - leftIcon={tree[file] && Object.keys(tree[file]).length > 1 ? : null} + leftIcon={tree[file] && Object.keys(tree[file]).length > 1 ? : contentIcon(fileTypeDetect({path: file}))} />); } return arr; diff --git a/src/torrent.js b/src/torrent.js index bb08bcd..83fe842 100644 --- a/src/torrent.js +++ b/src/torrent.js @@ -3,6 +3,132 @@ import formatBytes from './format-bytes' import {ListItem} from 'material-ui/List'; import Divider from 'material-ui/Divider'; +const contentIcon = (type) => { + switch(type) + { + case 'video': + return ( + + + + + + + ) + case 'audio': + return ( + + + + + + ) + case 'pictures': + return ( + + + + ) + case 'application': + return ( + + + + ) + case 'books': + return ( + + + + + + + + + ) + case 'archive': + return ( + + + + + + + ) + case 'disc': + return ( + + + + + + + ) + default: + return ( + + + + + + + + ) + } +}; +export {contentIcon} + export default (props) => { const torrent = props.torrent; @@ -56,132 +182,7 @@ return ( } - leftIcon={ - (() => { - switch(torrent.contentType) - { - case 'video': - return ( - - - - - - - ) - case 'audio': - return ( - - - - - - ) - case 'pictures': - return ( - - - - ) - case 'application': - return ( - - - - ) - case 'books': - return ( - - - - - - - - - ) - case 'archive': - return ( - - - - - - - ) - case 'disc': - return ( - - - - - - - ) - default: - return ( - - - - - - - - ) - } - })() - } + leftIcon={contentIcon(torrent.contentType)} rightIcon={