actually use push target filters when new books are published
parent
460cf44c4c
commit
a734069b74
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
const HttpError = require('../errors/HttpError')
|
const HttpError = require('../errors/HttpError')
|
||||||
const request = require('request')
|
const request = require('request')
|
||||||
|
const uriRegex = /^(.+:\/\/)?(.+\.)*(.+\.).{1,}(:\d+)?(.+)?/i
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
publish: async function (req, res) {
|
publish: async function (req, res) {
|
||||||
|
@ -73,16 +74,27 @@ module.exports = {
|
||||||
async function sendUpdatesAsync (id) {
|
async function sendUpdatesAsync (id) {
|
||||||
const book = await Book.findOne({ id })
|
const book = await Book.findOne({ id })
|
||||||
const targets = await TargetUrl.find()
|
const targets = await TargetUrl.find()
|
||||||
|
if (!book) return
|
||||||
for (const i in targets) {
|
for (const i in targets) {
|
||||||
sails.log('sending ' + book.id + ' info to ' + targets[i].url)
|
const item = targets[i]
|
||||||
request.post({
|
const { author: fAuthor, publisher: fPublisher, title: fTitle, isbn: fIsbn, url } = item
|
||||||
url: targets[i].url,
|
const { author: bAuthor, publisher: bPublisher, title: bTitle, isbn: bIsbn } = book
|
||||||
headers: { 'User-Agent': 'RoE-aggregator' },
|
sails.log('sending ' + book.id + ' info to ' + url)
|
||||||
form: book
|
|
||||||
}, function (err, httpResp, body) {
|
if (uriRegex.test(url)) {
|
||||||
if (err) {
|
if (fAuthor && !((bAuthor || '').includes(fAuthor))) continue
|
||||||
sails.log(`error: failed to send book ${id} to ${targets[i].url}`)
|
if (fPublisher && !((bPublisher || '').includes(fPublisher))) continue
|
||||||
}
|
if (fTitle && !((bTitle || '').includes(fTitle))) continue
|
||||||
})
|
if (fIsbn && !((bIsbn || '').includes(fIsbn))) continue
|
||||||
|
request.post({
|
||||||
|
url: url,
|
||||||
|
headers: { 'User-Agent': 'RoE-aggregator' },
|
||||||
|
form: book
|
||||||
|
}, function (err, httpResp, body) {
|
||||||
|
if (err) {
|
||||||
|
sails.log(`error: failed to send book ${id} to ${url}`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ module.exports = {
|
||||||
},
|
},
|
||||||
title: { type: 'string', required: true },
|
title: { type: 'string', required: true },
|
||||||
author: { type: 'string' },
|
author: { type: 'string' },
|
||||||
|
publisher: { type: 'string' },
|
||||||
isbn: { type: 'string' },
|
isbn: { type: 'string' },
|
||||||
version: { type: 'string' }
|
version: { type: 'string' }
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
exports.up = function (knex, Promise) {
|
||||||
|
return Promise.all([
|
||||||
|
knex.schema.table('book', t => {
|
||||||
|
t.string('publisher')
|
||||||
|
})
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.down = function (knex, Promise) {
|
||||||
|
return Promise.all([
|
||||||
|
knex.schema.table('book', t => {
|
||||||
|
t.dropColumns('publisher')
|
||||||
|
})
|
||||||
|
])
|
||||||
|
}
|
|
@ -21,7 +21,8 @@
|
||||||
"debug": "node --inspect app.js",
|
"debug": "node --inspect app.js",
|
||||||
"custom-tests": "echo 'Nothing yet'",
|
"custom-tests": "echo 'Nothing yet'",
|
||||||
"db:migrate": "knex migrate:latest",
|
"db:migrate": "knex migrate:latest",
|
||||||
"db:rollback": "knex migrate:rollback"
|
"db:rollback": "knex migrate:rollback",
|
||||||
|
"db:gmig": "knex migrate:make"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sailshq/connect-redis": "^3.2.1",
|
"@sailshq/connect-redis": "^3.2.1",
|
||||||
|
|
Loading…
Reference in New Issue