feat(vote): rating update on torrent request
This commit is contained in:
parent
a9c27083da
commit
51caccbce4
@ -17,6 +17,7 @@ module.exports = async ({
|
||||
crypto,
|
||||
insertTorrentToDB,
|
||||
removeTorrentFromDB,
|
||||
updateTorrentToDB,
|
||||
checkTorrent,
|
||||
p2pStore,
|
||||
feed
|
||||
@ -141,6 +142,13 @@ module.exports = async ({
|
||||
send('votes', {
|
||||
hash, good, bad, selfVote
|
||||
});
|
||||
if(torrent.good != good || torrent.bad != bad)
|
||||
{
|
||||
console.log('finded new rating on', torrent.name, 'update votes to it')
|
||||
torrent.good = good
|
||||
torrent.bad = bad
|
||||
updateTorrentToDB(torrent)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -760,6 +768,8 @@ module.exports = async ({
|
||||
let {good, bad} = await getVotes(torrent.hash)
|
||||
torrent.good = good
|
||||
torrent.bad = bad
|
||||
if(torrent.good > 0 || torrent.bad > 0)
|
||||
updateTorrentToDB(torrent)
|
||||
|
||||
feed.add(torrent)
|
||||
|
||||
|
@ -52,6 +52,46 @@ const expand = (sphinx) => {
|
||||
})
|
||||
})
|
||||
|
||||
sphinx.updateValues = (table, values, whereObject, callback) => new Promise((resolve) => {
|
||||
let set = ''
|
||||
for(const val in values)
|
||||
{
|
||||
if(values[val] === null)
|
||||
continue;
|
||||
|
||||
if(typeof values[val] == 'object')
|
||||
continue;
|
||||
|
||||
// skip text indexes (manticore bug https://github.com/manticoresoftware/manticoresearch/issues/84)
|
||||
if(typeof values[val] == 'string')
|
||||
continue;
|
||||
|
||||
set += '`' + val + '` = ' + sphinx.escape(values[val]) + ',';
|
||||
}
|
||||
if(set.length == 0)
|
||||
return
|
||||
set = set.slice(0, -1)
|
||||
|
||||
let where = ''
|
||||
for(const w in whereObject)
|
||||
{
|
||||
if(whereObject[w] === null)
|
||||
continue;
|
||||
|
||||
where += '`' + w + '` = ' + sphinx.escape(whereObject[w]) + ' and';
|
||||
}
|
||||
if(where.length == 0)
|
||||
return
|
||||
where = where.slice(0, -3)
|
||||
|
||||
const query = `UPDATE ${table} SET ${set} WHERE ${where}`;
|
||||
queryCall(query, (...responce) => {
|
||||
if(callback)
|
||||
callback(...responce)
|
||||
resolve(...responce)
|
||||
})
|
||||
})
|
||||
|
||||
return sphinx
|
||||
}
|
||||
|
||||
|
@ -528,10 +528,19 @@ const insertTorrentToDB = (torrent, silent) => {
|
||||
})
|
||||
}
|
||||
|
||||
const removeTorrentFromDB = (torrent) => {
|
||||
const removeTorrentFromDB = async (torrent) => {
|
||||
const {hash} = torrent
|
||||
mysqlSingle.query('DELETE FROM torrents WHERE hash = ?', hash)
|
||||
mysqlSingle.query('DELETE FROM files WHERE hash = ?', hash)
|
||||
await mysqlSingle.query('DELETE FROM torrents WHERE hash = ?', hash)
|
||||
await mysqlSingle.query('DELETE FROM files WHERE hash = ?', hash)
|
||||
}
|
||||
|
||||
const updateTorrentToDB = async (torrent) => {
|
||||
if(typeof torrent !== 'object')
|
||||
return
|
||||
|
||||
delete torrent.id
|
||||
|
||||
await mysqlSingle.updateValues('torrents', torrent, {hash: torrent.hash})
|
||||
}
|
||||
|
||||
const updateTorrent = (metadata, infohash, rinfo) => {
|
||||
@ -718,6 +727,7 @@ API({
|
||||
crypto,
|
||||
insertTorrentToDB,
|
||||
removeTorrentFromDB,
|
||||
updateTorrentToDB,
|
||||
checkTorrent,
|
||||
p2pStore,
|
||||
feed
|
||||
|
Loading…
Reference in New Issue
Block a user