fixed creation of database entries / links
This commit is contained in:
parent
73c225ac6d
commit
60f431d6cf
1 changed files with 9 additions and 31 deletions
|
@ -4,6 +4,8 @@ const { extname } = require('path');
|
||||||
const Artist = require('../models/Artist.js');
|
const Artist = require('../models/Artist.js');
|
||||||
const Album = require('../models/Album.js');
|
const Album = require('../models/Album.js');
|
||||||
const Track = require('../models/Track.js');
|
const Track = require('../models/Track.js');
|
||||||
|
const TrackToArtist = require('../models/TrackToArtist.js');
|
||||||
|
const TrackToAlbum = require('../models/TrackToAlbum.js');
|
||||||
const AlbumToArtist = require('../models/AlbumToArtist.js');
|
const AlbumToArtist = require('../models/AlbumToArtist.js');
|
||||||
|
|
||||||
class Queue {
|
class Queue {
|
||||||
|
@ -82,8 +84,8 @@ class Queue {
|
||||||
const artists = await this.addArtist(tags);
|
const artists = await this.addArtist(tags);
|
||||||
const album = await this.addAlbum(tags);
|
const album = await this.addAlbum(tags);
|
||||||
const track = await this.addTrack(tags, file);
|
const track = await this.addTrack(tags, file);
|
||||||
// this.linkTrackToArtist(track, artist);
|
this.linkTrackToArtists(track, artists);
|
||||||
// this.linkTrackToAlbum(track, album);
|
this.linkTrackToAlbum(track, album);
|
||||||
this.linkAlbumToArtists(album, artists);
|
this.linkAlbumToArtists(album, artists);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,23 +154,12 @@ class Queue {
|
||||||
return track;
|
return track;
|
||||||
}
|
}
|
||||||
|
|
||||||
async linkTrackToArtist(track, artist) {
|
async linkTrackToArtists(track, artists) {
|
||||||
if (track === undefined || artist === undefined) {
|
if (track === undefined || artists === undefined || artists.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
for (let index = 0; index < artists.length; index++) {
|
||||||
const [element, created] = await database.models.TrackToArtist.findOrCreate({
|
await new TrackToArtist(track, artists[index]).save();
|
||||||
where: {
|
|
||||||
track: track.id,
|
|
||||||
artist: artist.id
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (created) {
|
|
||||||
logger.debug('linked track \'' + track.id + '\' to artist \'' + artist.id + '\': ' + JSON.stringify(element));
|
|
||||||
}
|
|
||||||
return element;
|
|
||||||
} catch (err) {
|
|
||||||
logger.error('error finding or creating tracktoartist entry for track \'' + track.id + '\' and album \'' + artist.id + '\' > ' + err);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,20 +167,7 @@ class Queue {
|
||||||
if (track === undefined || album === undefined) {
|
if (track === undefined || album === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
await new TrackToAlbum(track, album).save();
|
||||||
const [element, created] = await database.models.TrackToAlbum.findOrCreate({
|
|
||||||
where: {
|
|
||||||
track: track.id,
|
|
||||||
album: album.id
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (created) {
|
|
||||||
logger.debug('linked track \'' + track.id + '\' to album \'' + album.id + '\': ' + JSON.stringify(element));
|
|
||||||
}
|
|
||||||
return element;
|
|
||||||
} catch (err) {
|
|
||||||
logger.error('error finding or creating tracktoalbum entry for track \'' + track.id + '\' and album \'' + album.id + '\' > ' + err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async linkAlbumToArtists(album, artists) {
|
async linkAlbumToArtists(album, artists) {
|
||||||
|
|
Loading…
Reference in a new issue