Fix matching from share, add fix script
This commit is contained in:
parent
183d58a540
commit
62b7121301
7 changed files with 152 additions and 60 deletions
77
worker.js
77
worker.js
|
@ -4,7 +4,6 @@ import raven from 'raven';
|
|||
|
||||
import models from './models';
|
||||
import services from './lib/services';
|
||||
import { find, create, findMatchesAsync } from './lib/share';
|
||||
|
||||
raven.config(process.env.SENTRY_DSN).install();
|
||||
|
||||
|
@ -12,46 +11,44 @@ const queue = kue.createQueue({
|
|||
redis: process.env.REDIS_URL,
|
||||
});
|
||||
|
||||
function search(share, done) {
|
||||
for (const service of services) {
|
||||
if (service.id === share.service) {
|
||||
continue; // eslint-disable-line no-continue
|
||||
function search(data, done) {
|
||||
const share = data.share;
|
||||
const service = services.find(item => data.service.id === item.id);
|
||||
console.log(service);
|
||||
co(function* gen() { // eslint-disable-line no-loop-func
|
||||
const match = yield service.search(share);
|
||||
|
||||
if (match.id) {
|
||||
models.match.create({
|
||||
trackId: share.type === 'track' ? share.id : null,
|
||||
albumId: share.type === 'album' ? share.id : null,
|
||||
externalId: match.id.toString(),
|
||||
service: match.service,
|
||||
name: match.name,
|
||||
streamUrl: match.streamUrl,
|
||||
purchaseUrl: match.purchaseUrl,
|
||||
artworkSmall: match.artwork.small,
|
||||
artworkLarge: match.artwork.large,
|
||||
});
|
||||
} else {
|
||||
models.match.create({
|
||||
trackId: share.type === 'track' ? share.id : null,
|
||||
albumId: share.type === 'album' ? share.id : null,
|
||||
externalId: null,
|
||||
service: match.service,
|
||||
name: null,
|
||||
streamUrl: null,
|
||||
purchaseUrl: null,
|
||||
artworkSmall: null,
|
||||
artworkLarge: null,
|
||||
});
|
||||
}
|
||||
co(function* gen() { // eslint-disable-line no-loop-func
|
||||
const match = yield service.search(share);
|
||||
|
||||
if (match.id) {
|
||||
models.match.create({
|
||||
trackId: share.type === 'track' ? share.id : null,
|
||||
albumId: share.type === 'album' ? share.id : null,
|
||||
externalId: match.id.toString(),
|
||||
service: match.service,
|
||||
name: match.name,
|
||||
streamUrl: match.streamUrl,
|
||||
purchaseUrl: match.purchaseUrl,
|
||||
artworkSmall: match.artwork.small,
|
||||
artworkLarge: match.artwork.large,
|
||||
});
|
||||
} else {
|
||||
models.match.create({
|
||||
trackId: share.type === 'track' ? share.id : null,
|
||||
albumId: share.type === 'album' ? share.id : null,
|
||||
externalId: null,
|
||||
service: match.service,
|
||||
name: null,
|
||||
streamUrl: null,
|
||||
purchaseUrl: null,
|
||||
artworkSmall: null,
|
||||
artworkLarge: null,
|
||||
});
|
||||
}
|
||||
}).catch((err) => {
|
||||
raven.captureException(err);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
return done();
|
||||
return done();
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
raven.captureException(err);
|
||||
return done();
|
||||
});
|
||||
}
|
||||
|
||||
queue.process('search', (job, done) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue