feat(torrent): generation of torrent functionality

This commit is contained in:
Alexey Kasyanchuk 2021-07-07 15:19:45 +03:00
parent 1686f3e028
commit 9699f1eb7f
6 changed files with 66 additions and 6 deletions

View File

@ -9,8 +9,8 @@ export default class ContextMenu extends Component {
render() render()
{ {
return ( return (
<div style={{position: 'relative', display: 'inline-block'}}> <div style={{position: 'relative', display: 'inline-block', zIndex: this.props.style?.zIndex || null}}>
<div style={{display: 'inline-block'}} onClick={(e) => { <div style={{display: 'inline-block', zIndex: this.props.style?.zIndex || null}} onClick={(e) => {
this.setState({toggle: !this.state.toggle}) this.setState({toggle: !this.state.toggle})
if(this.props.onClick) if(this.props.onClick)
this.props.onClick(e) this.props.onClick(e)

View File

@ -4,7 +4,13 @@ import Background from './images/pirate-mod.jpg'
import RaisedButton from 'material-ui/RaisedButton'; import RaisedButton from 'material-ui/RaisedButton';
import Search from './search' import Search from './search'
import Tooltip from './tooltip' import Tooltip from './tooltip'
import ContextMenu from './context-menu'
import createTorrent from 'create-torrent';
import fs from 'fs'
let dialog
if(typeof WEB === 'undefined')
dialog = require('electron').remote.dialog
class Header extends React.Component { class Header extends React.Component {
constructor(props) constructor(props)
{ {
@ -48,6 +54,27 @@ class Header extends React.Component {
window.onscroll = null window.onscroll = null
} }
generateTorrent(folder)
{
let path = dialog.showOpenDialogSync({properties: [folder ? "openDirectory" : "openFile"]})
if(path && path[0])
{
path = path[0]
createTorrent(path, (err, torrent) => {
if (!err) {
console.log('generated torrent size', torrent.length)
let savePath = dialog.showSaveDialogSync({title: 'Save generated torrent file', defaultPath: 'generated', filters: [
{ name: 'Torrent files', extensions: ['torrent'] },
]});
if(savePath) {
fs.writeFileSync(savePath, torrent)
console.log('saved', torrent.length, 'to', savePath)
}
}
})
}
}
render() render()
{ {
return ( return (
@ -273,6 +300,27 @@ class Header extends React.Component {
</svg> </svg>
} }
/> />
{
dialog &&
<ContextMenu rightAlign={true} style={{zIndex: 1}} onClick={(e) => {
e.preventDefault();
e.stopPropagation();
}} menu={[
{name: __('File'), click: () => this.generateTorrent(false)},
{name: __('Folder'), click: () => this.generateTorrent(true)},
]}>
<RaisedButton
label={__('Generate')}
backgroundColor='#eb9534'
labelColor='white'
style={{height: 60, width: 160, borderRadius: 5, margin: 5, zIndex: 1}}
buttonStyle={{borderRadius: 5}}
icon={
<svg fill='white' style={{height: 30}} viewBox="0 0 512 512"><path d="m437.02 74.98c-48.352-48.351-112.64-74.98-181.02-74.98s-132.668 26.629-181.02 74.98c-48.351 48.352-74.98 112.64-74.98 181.02s26.629 132.668 74.981 181.02c3.585 3.585 8.533 4.965 13.176 4.161.007.001.01.008.019.007l121.199-21.227c3.038-.532 5.838-1.987 8.019-4.168l194.918-194.919c5.858-5.858 5.858-15.355 0-21.213l-99.986-99.986c-5.857-5.858-15.355-5.858-21.213 0l-194.919 194.919c-2.182 2.181-3.637 4.982-4.169 8.02l-15.814 90.361c-29.97-39.169-46.211-86.821-46.211-136.975 0-124.617 101.383-226 226-226s226 101.383 226 226-101.383 226-226 226c-8.284 0-15 6.716-15 15s6.716 15 15 15c68.38 0 132.668-26.629 181.02-74.98 48.351-48.352 74.98-112.64 74.98-181.02s-26.629-132.668-74.98-181.02zm-320.419 261.234 59.176 59.175-71.73 12.563zm90.185 47.759-28.773-28.773 173.705-173.705 28.773 28.773zm94.933-252.478 28.787 28.787-173.706 173.705-28.786-28.787z"/></svg>
}
/>
</ContextMenu>
}
<div className='fs0-85 pad0-75 column search-panel' style={{ <div className='fs0-85 pad0-75 column search-panel' style={{
marginLeft: 'auto', marginLeft: 'auto',
marginTop: '-10px', marginTop: '-10px',

View File

@ -194,6 +194,9 @@
"Performance settings": "Performance settings", "Performance settings": "Performance settings",
"Start application minimized": "Start application minimized", "Start application minimized": "Start application minimized",
"Magnet": "磁鐵鍊接", "Magnet": "磁鐵鍊接",
"You can extend your collected search DB with your own .torrent files. Just drag and drop them into the Rats window (or folder with them). They will immediately appear on activity tab.": "您可以使用自己的.torrent文件擴展收集的搜索數據庫。 只需將它們拖放到Rats窗口或帶有它們的文件夾即可。 它們將立即顯示在活動選項卡上。" "You can extend your collected search DB with your own .torrent files. Just drag and drop them into the Rats window (or folder with them). They will immediately appear on activity tab.": "您可以使用自己的.torrent文件擴展收集的搜索數據庫。 只需將它們拖放到Rats窗口或帶有它們的文件夾即可。 它們將立即顯示在活動選項卡上。",
"File": "文件",
"Folder": "文件夾",
"Generate": "產生"
} }
} }

View File

@ -194,6 +194,9 @@
"Performance settings": "Performance settings", "Performance settings": "Performance settings",
"Start application minimized": "Start application minimized", "Start application minimized": "Start application minimized",
"Magnet": "Magnet", "Magnet": "Magnet",
"You can extend your collected search DB with your own .torrent files. Just drag and drop them into the Rats window (or folder with them). They will immediately appear on activity tab.": "You can extend your collected search DB with your own .torrent files. Just drag and drop them into the Rats window (or folder with them). They will immediately appear on activity tab." "You can extend your collected search DB with your own .torrent files. Just drag and drop them into the Rats window (or folder with them). They will immediately appear on activity tab.": "You can extend your collected search DB with your own .torrent files. Just drag and drop them into the Rats window (or folder with them). They will immediately appear on activity tab.",
"File": "File",
"Folder": "Folder",
"Generate": "Generate"
} }
} }

View File

@ -194,6 +194,9 @@
"Performance settings": "Настройки производительности", "Performance settings": "Настройки производительности",
"Start application minimized": "Запусть приложение свернутым", "Start application minimized": "Запусть приложение свернутым",
"Magnet": "Магнет-ссылка", "Magnet": "Магнет-ссылка",
"You can extend your collected search DB with your own .torrent files. Just drag and drop them into the Rats window (or folder with them). They will immediately appear on activity tab.": "Вы можете расшириться вашу базу поиска вашими .torrent файлами. Просто переместите их в окно программы (или папку с ними). Они сразу же появятся во вкладке активности." "You can extend your collected search DB with your own .torrent files. Just drag and drop them into the Rats window (or folder with them). They will immediately appear on activity tab.": "Вы можете расшириться вашу базу поиска вашими .torrent файлами. Просто переместите их в окно программы (или папку с ними). Они сразу же появятся во вкладке активности.",
"File": "Файл",
"Folder": "Папка",
"Generate": "Сгенерировать"
} }
} }

View File

@ -194,6 +194,9 @@
"Performance settings": "Performance settings", "Performance settings": "Performance settings",
"Start application minimized": "Start application minimized", "Start application minimized": "Start application minimized",
"Magnet": "Magnet", "Magnet": "Magnet",
"You can extend your collected search DB with your own .torrent files. Just drag and drop them into the Rats window (or folder with them). They will immediately appear on activity tab.": "You can extend your collected search DB with your own .torrent files. Just drag and drop them into the Rats window (or folder with them). They will immediately appear on activity tab." "You can extend your collected search DB with your own .torrent files. Just drag and drop them into the Rats window (or folder with them). They will immediately appear on activity tab.": "You can extend your collected search DB with your own .torrent files. Just drag and drop them into the Rats window (or folder with them). They will immediately appear on activity tab.",
"File": "Файл",
"Folder": "Папка",
"Generate": "Згенерувати"
} }
} }