Migrate all the things
* Migrates from Mongo to Postgres. * Migrates from JSPM to Webpack. * Migrates from React to Vuejs. * Migrates from Bootstrap to Bulma. Also: * Fixes rendering of meta data in the document head tag.
This commit is contained in:
parent
09706778d9
commit
7bb0497ff4
76 changed files with 6741 additions and 1760 deletions
91
lib/share.js
Normal file
91
lib/share.js
Normal file
|
@ -0,0 +1,91 @@
|
|||
import co from 'co';
|
||||
import debuglog from 'debug';
|
||||
|
||||
import models from '../models';
|
||||
import services from '../lib/services';
|
||||
|
||||
const debug = debuglog('match.audio:share');
|
||||
|
||||
export function find(music) {
|
||||
return models[music.type].findOne({
|
||||
where: {
|
||||
externalId: music.id,
|
||||
},
|
||||
include: [
|
||||
{ model: models.artist },
|
||||
{ model: models.match },
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
export function create(music) {
|
||||
return models[music.type].create({
|
||||
externalId: music.id,
|
||||
service: music.service,
|
||||
name: music.name,
|
||||
albumName: music.type === 'track' ? music.album.name : null,
|
||||
artist: {
|
||||
name: music.artist.name,
|
||||
artworkSmall: null,
|
||||
artworkLarge: null,
|
||||
},
|
||||
matches: [
|
||||
{
|
||||
externalId: music.id,
|
||||
service: music.service,
|
||||
name: music.name,
|
||||
streamUrl: music.streamUrl,
|
||||
purchaseUrl: music.purchaseUrl,
|
||||
artworkSmall: music.artwork.small,
|
||||
artworkLarge: music.artwork.large,
|
||||
},
|
||||
],
|
||||
}, {
|
||||
include: [
|
||||
{ model: models.artist },
|
||||
{ model: models.match },
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
export function findMatchesAsync(share) {
|
||||
process.nextTick(() => {
|
||||
for (const service of services) {
|
||||
if (service.id === share.service) {
|
||||
continue; // eslint-disable-line no-continue
|
||||
}
|
||||
co(function* gen() { // eslint-disable-line no-loop-func
|
||||
const match = yield service.search(share);
|
||||
console.log(service.id)
|
||||
console.log(match)
|
||||
if (match.id) {
|
||||
models.match.create({
|
||||
trackId: share.albumName ? share.id : null,
|
||||
albumId: share.albumName ? null : share.id,
|
||||
externalId: match.id,
|
||||
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.trackId ? share.id : null,
|
||||
albumId: share.albumId ? share.id : null,
|
||||
externalId: null,
|
||||
service: match.service,
|
||||
name: null,
|
||||
streamUrl: null,
|
||||
purchaseUrl: null,
|
||||
artworkSmall: null,
|
||||
artworkLarge: null,
|
||||
});
|
||||
}
|
||||
}).catch((err) => {
|
||||
debug(err);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue