feat(gui): trackers basic display

This commit is contained in:
Alexey Kasyanchuk
2018-08-15 12:38:19 +03:00
parent 17371bd8ff
commit 7cf5c17fe4
7 changed files with 42 additions and 12 deletions

View File

@ -119,7 +119,7 @@ const expand = (sphinx) => {
})
sphinx.replaceValues = (table, values, options = {}, callback = () => {}) => new Promise((resolve) => {
const {particial, key, merge, mergeCallback} = Object.assign({
const {particial, key, merge, mergeCallback, sphinxIndex} = Object.assign({
particial: true,
key: 'id'
}, options)
@ -128,6 +128,10 @@ const expand = (sphinx) => {
let names = '';
let data = '';
const parseValues = (values) => {
if(sphinxIndex)
for(const k in sphinxIndex)
values[k] = values[sphinxIndex[k]]
let valuesData = ''
names = ''
for(const val in values)

View File

@ -116,14 +116,19 @@ module.exports = function (send, recive, dataDirectory, version, env)
return
logT('tracker', 'found', name, 'on', tracker)
this.sphinx.replaceValues('torrents', {hash, info: data}, {particial: true, key: 'hash', merge: ['info'], mergeCallback: (n, obj) => {
if(n != 'info')
return
this.sphinx.replaceValues('torrents', {hash, info: data}, {
particial: true,
key: 'hash',
sphinxIndex: {nameIndex: 'name'},
merge: ['info'],
mergeCallback: (n, obj) => {
if(n != 'info')
return
if(!obj.trackers)
obj.trackers = []
obj.trackers.push(name)
obj.trackers = [...new Set(obj.trackers)]
if(!obj.trackers)
obj.trackers = []
obj.trackers.push(tracker)
obj.trackers = [...new Set(obj.trackers)]
} })
})
}
@ -149,6 +154,7 @@ module.exports = function (send, recive, dataDirectory, version, env)
trackersChecked: row.trackersChecked ? row.trackersChecked.getTime() : undefined,
good: row.good,
bad: row.bad,
info: typeof row.info == 'string' && row.info.length > 0 ? JSON.parse(row.info) : undefined
}
}

View File

@ -14,7 +14,12 @@ module.exports = class Nyaa
async parse()
{
let html = await fetch('https://nyaa.si/' + (this.threadId ? `view/${this.threadId}` : (this.hash ? `?q=${this.hash}` : '')))
let html;
try {
html = await fetch('https://nyaa.si/' + (this.threadId ? `view/${this.threadId}` : (this.hash ? `?q=${this.hash}` : '')))
} catch(err) {
return
}
if(!html)
return
html = await html.text()

View File

@ -14,7 +14,12 @@ module.exports = class Rutracker
async parse()
{
let html = await fetch('https://rutracker.org/forum/viewtopic.php?' + (this.threadId ? `t=${this.threadId}` : (this.hash ? `h=${this.hash}` : '')))
let html;
try {
html = await fetch('https://rutracker.org/forum/viewtopic.php?' + (this.threadId ? `t=${this.threadId}` : (this.hash ? `h=${this.hash}` : '')))
} catch(err) {
return
}
if(!html)
return
html = await html.text()