fix(nyaa): fix errors on nyaa

This commit is contained in:
Alexey Kasyanchuk
2018-08-19 20:52:22 +03:00
parent 4dfd5cd15a
commit 91fcc5d68e
2 changed files with 15 additions and 2 deletions

View File

@ -22,14 +22,19 @@ module.exports = class Nyaa
html = await fetch('https://nyaa.si/' + (this.threadId ? `view/${this.threadId}` : (this.hash ? `?q=${this.hash}` : ''))) html = await fetch('https://nyaa.si/' + (this.threadId ? `view/${this.threadId}` : (this.hash ? `?q=${this.hash}` : '')))
} catch(err) { } catch(err) {
resolve() resolve()
return
} }
if(!html) if(!html) {
resolve() resolve()
return
}
html = await html.textConverted() html = await html.textConverted()
const $ = cheerio.load(html) const $ = cheerio.load(html)
let topicTitle = $('.panel-title').first().text() let topicTitle = $('.panel-title').first().text()
if(!topicTitle) if(!topicTitle) {
resolve() resolve()
return
}
topicTitle = topicTitle.replace(/\t/g, '').replace(/\n/g, '') topicTitle = topicTitle.replace(/\t/g, '').replace(/\n/g, '')

View File

@ -35,6 +35,14 @@ describe("big table for check", () => {
assert.equal((await sphinx.query(`select data from feed where id = 1`))[0].data, '{"a":1,"b":2,"c":3,"d":6,"e":5}') assert.equal((await sphinx.query(`select data from feed where id = 1`))[0].data, '{"a":1,"b":2,"c":3,"d":6,"e":5}')
}) })
it("insert object to database", async function() {
const obj = {a: 1, v: 2}
const p = {id: 3, data: obj}
await sphinx.insertValues('feed', p)
assert.equal((await sphinx.query(`select data from feed where id = 3`))[0].data, '{"a":1,"v":2}')
assert.equal(obj, p.data)
})
it("close", async function() { it("close", async function() {
await sphinx.end() await sphinx.end()
}) })