feat(replication): replicate torrent on open

This commit is contained in:
Alexey Kasyanchuk 2018-04-18 23:19:42 +03:00
parent f23310065d
commit 34e964126b
2 changed files with 16 additions and 12 deletions

View File

@ -91,8 +91,10 @@ module.exports = ({
} }
delete options.peer; delete options.peer;
peer.emit('torrent', {hash, options}, (data) => { peer.emit('torrent', {hash, options}, (data) => {
console.log('remote torrent result') console.log('remote torrent result', hash)
callback(data) callback(data)
if(data)
insertTorrentToDB(data, true) // copy torrent to our db
}) })
return; return;
} }

View File

@ -390,7 +390,7 @@ const checkTorrent = (torrent) => {
return true return true
} }
const insertTorrentToDB = (torrent) => { const insertTorrentToDB = (torrent, silent) => {
if(!torrent) if(!torrent)
return return
@ -432,15 +432,16 @@ const insertTorrentToDB = (torrent) => {
mysqlSingle.insertValues('torrents', torrent, function(err, result) { mysqlSingle.insertValues('torrents', torrent, function(err, result) {
if(result) { if(result) {
send('newTorrent', { if(!silent)
hash: torrent.hash, send('newTorrent', {
name: torrent.name, hash: torrent.hash,
size: torrent.size, name: torrent.name,
files: torrent.files, size: torrent.size,
piecelength: torrent.piecelength, files: torrent.files,
contentType: torrent.contentType, piecelength: torrent.piecelength,
contentCategory: torrent.contentCategory, contentType: torrent.contentType,
}); contentCategory: torrent.contentCategory,
});
updateTorrentTrackers(torrent.hash); updateTorrentTrackers(torrent.hash);
} }
else else
@ -475,7 +476,8 @@ const insertTorrentToDB = (torrent) => {
return return
} }
if(--filesToAdd === 0) { if(--filesToAdd === 0) {
send('filesReady', torrent.hash); if(!silent)
send('filesReady', torrent.hash);
} }
}); });
}); });