feat(torrents): add support for dropping torrent to base just with window
This commit is contained in:
@ -147,6 +147,24 @@ class App extends Component {
|
||||
changeLanguage(lang, () => this.forceUpdate())
|
||||
})
|
||||
|
||||
const processTorrents = (files) => {
|
||||
if(!files || files.length == 0)
|
||||
return
|
||||
|
||||
torrentSocket.emit('dropTorrents', Array.from(files).filter(file => file.type == 'application/x-bittorrent').map(file => file.path))
|
||||
}
|
||||
|
||||
document.addEventListener('dragover', (event) => {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
event.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy.
|
||||
}, false);
|
||||
document.addEventListener('drop', (event) => {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
processTorrents(event.dataTransfer.files); // FileList object.
|
||||
}, false);
|
||||
|
||||
window.router()
|
||||
appReady = true;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ const config = require('./config');
|
||||
const client = new (require('./bt/client'))
|
||||
const spider = new (require('./bt/spider'))(client)
|
||||
const fs = require('fs');
|
||||
const parseTorrent = require('parse-torrent')
|
||||
const {single, pool} = require('./mysql')
|
||||
const getPeersStatisticUDP = require('./bt/udp-tracker-request')
|
||||
const crypto = require('crypto')
|
||||
@ -573,9 +574,11 @@ app.get('*', function(req, res)
|
||||
await mysqlSingle.updateValues('torrents', torrent, {hash: torrent.hash})
|
||||
}
|
||||
|
||||
const updateTorrent = (metadata, infohash, rinfo) => {
|
||||
const insertMetadata = (metadata, infohash, rinfo) => {
|
||||
console.log('finded torrent', metadata.info.name, ' and add to database');
|
||||
|
||||
const bufferToString = (buffer) => Buffer.isBuffer(buffer) ? buffer.toString() : buffer
|
||||
|
||||
const hash = infohash.toString('hex');
|
||||
let size = metadata.info.length ? metadata.info.length : 0;
|
||||
let filesCount = 1;
|
||||
@ -595,19 +598,19 @@ app.get('*', function(req, res)
|
||||
for(let i = 0; i < metadata.info.files.length; i++)
|
||||
{
|
||||
let file = metadata.info.files[i];
|
||||
let filePath = file.path.join('/');
|
||||
let filePath = bufferToString(file.path).join('/');
|
||||
filesAdd(filePath, file.length);
|
||||
size += file.length;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
filesAdd(metadata.info.name, size)
|
||||
filesAdd(bufferToString(metadata.info.name), size)
|
||||
}
|
||||
|
||||
const torrentQ = {
|
||||
hash: hash,
|
||||
name: metadata.info.name,
|
||||
name: bufferToString(metadata.info.name),
|
||||
size: size,
|
||||
files: filesCount,
|
||||
piecelength: metadata.info['piece length'],
|
||||
@ -636,7 +639,7 @@ app.get('*', function(req, res)
|
||||
if(free >= config.spaceDiskLimit)
|
||||
{
|
||||
hideFakeTorrents(); // also enable fake torrents;
|
||||
updateTorrent(metadata, infohash, rinfo);
|
||||
insertMetadata(metadata, infohash, rinfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -648,7 +651,7 @@ app.get('*', function(req, res)
|
||||
}
|
||||
else
|
||||
{
|
||||
updateTorrent(metadata, infohash, rinfo);
|
||||
insertMetadata(metadata, infohash, rinfo);
|
||||
}
|
||||
});
|
||||
|
||||
@ -671,6 +674,12 @@ app.get('*', function(req, res)
|
||||
client._download(peer, infoHash)
|
||||
}
|
||||
|
||||
recive('dropTorrents', (pathTorrents) => {
|
||||
console.log('drop torrents and replicate from original')
|
||||
const torrents = pathTorrents.map(path => parseTorrent(fs.readFileSync(path)))
|
||||
torrents.forEach(torrent => insertMetadata(torrent, torrent.infoHashBuffer, {address: '127.0.0.1', port: 666}))
|
||||
})
|
||||
|
||||
checkInternet((connected) => {
|
||||
if(!connected)
|
||||
return
|
||||
|
Reference in New Issue
Block a user