|
|
|
@ -75,21 +75,21 @@ function normalizeDB(oldDb: ReferenceDatabase) { |
|
|
|
|
db[userId].tags.forEach((x: TagWithRefsWithId) => { x.id = remapId(x.id, tagMap); }) |
|
|
|
|
} |
|
|
|
|
for (const userId in db) { |
|
|
|
|
// Now remap the references.
|
|
|
|
|
// Now remap and sort the references.
|
|
|
|
|
db[userId].tracks.forEach((x: TrackWithRefsWithId) => { |
|
|
|
|
x.tagIds = x.tagIds.map((id: number) => remapId(id, tagMap)); |
|
|
|
|
x.artistIds = x.artistIds.map((id: number) => remapId(id, artistMap)); |
|
|
|
|
x.tagIds = x.tagIds.map((id: number) => remapId(id, tagMap)).sort(); |
|
|
|
|
x.artistIds = x.artistIds.map((id: number) => remapId(id, artistMap)).sort(); |
|
|
|
|
x.albumId = x.albumId ? remapId(x.albumId, albumMap) : null; |
|
|
|
|
}); |
|
|
|
|
db[userId].albums.forEach((x: AlbumWithRefsWithId) => { |
|
|
|
|
x.tagIds = x.tagIds.map((id: number) => remapId(id, tagMap)); |
|
|
|
|
x.artistIds = x.artistIds.map((id: number) => remapId(id, artistMap)); |
|
|
|
|
x.trackIds = x.trackIds.map((id: number) => remapId(id, trackMap)); |
|
|
|
|
x.tagIds = x.tagIds.map((id: number) => remapId(id, tagMap)).sort(); |
|
|
|
|
x.artistIds = x.artistIds.map((id: number) => remapId(id, artistMap)).sort(); |
|
|
|
|
x.trackIds = x.trackIds.map((id: number) => remapId(id, trackMap)).sort(); |
|
|
|
|
}); |
|
|
|
|
db[userId].artists.forEach((x: ArtistWithRefsWithId) => { |
|
|
|
|
x.tagIds = x.tagIds.map((id: number) => remapId(id, tagMap)); |
|
|
|
|
x.albumIds = x.albumIds.map((id: number) => remapId(id, albumMap)); |
|
|
|
|
x.trackIds = x.trackIds.map((id: number) => remapId(id, trackMap)); |
|
|
|
|
x.tagIds = x.tagIds.map((id: number) => remapId(id, tagMap)).sort(); |
|
|
|
|
x.albumIds = x.albumIds.map((id: number) => remapId(id, albumMap)).sort(); |
|
|
|
|
x.trackIds = x.trackIds.map((id: number) => remapId(id, trackMap)).sort(); |
|
|
|
|
}); |
|
|
|
|
db[userId].tags.forEach((x: TagWithRefsWithId) => { |
|
|
|
|
x.parentId = x.parentId ? remapId(x.parentId, tagMap) : null; |
|
|
|
@ -118,32 +118,48 @@ function transformActionIDs(action: DBAction, mappings: IDMappings, rng: any) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
switch (r.type) { |
|
|
|
|
case DBActionType.CreateTrack: { |
|
|
|
|
let track = r.payload as TrackWithRefsWithId; |
|
|
|
|
track.tagIds.forEach((id: number) => doMap(id, mappings.tags)); |
|
|
|
|
track.artistIds.forEach((id: number) => doMap(id, mappings.artists)); |
|
|
|
|
track.albumId = track.albumId ? doMap(track.albumId, mappings.albums) : null; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case DBActionType.CreateArtist: { |
|
|
|
|
let artist = r.payload as ArtistWithRefsWithId; |
|
|
|
|
artist.tagIds.forEach((id: number) => doMap(id, mappings.tags)); |
|
|
|
|
artist.albumIds.forEach((id: number) => doMap(id, mappings.albums)); |
|
|
|
|
artist.trackIds.forEach((id: number) => doMap(id, mappings.tracks)); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case DBActionType.CreateAlbum: { |
|
|
|
|
let album = r.payload as AlbumWithRefsWithId; |
|
|
|
|
album.tagIds.forEach((id: number) => doMap(id, mappings.tags)); |
|
|
|
|
album.artistIds.forEach((id: number) => doMap(id, mappings.artists)); |
|
|
|
|
album.trackIds.forEach((id: number) => doMap(id, mappings.tracks)); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case DBActionType.CreateTag: { |
|
|
|
|
let tag = r.payload as TagWithRefsWithId; |
|
|
|
|
tag.parentId = tag.parentId ? doMap(tag.parentId, mappings.tags) : null; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case DBActionType.CreateTrack: |
|
|
|
|
case DBActionType.PutTrack: |
|
|
|
|
case DBActionType.PatchTrack: |
|
|
|
|
{ |
|
|
|
|
let track = r.payload as TrackWithRefsWithId; |
|
|
|
|
track.tagIds && track.tagIds.forEach((id: number) => doMap(id, mappings.tags)); |
|
|
|
|
track.artistIds && track.artistIds.forEach((id: number) => doMap(id, mappings.artists)); |
|
|
|
|
if (track.albumId) { track.albumId = doMap(track.albumId, mappings.albums); } |
|
|
|
|
if (track.id) { track.id = doMap(track.id, mappings.tracks); } |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case DBActionType.CreateArtist: |
|
|
|
|
case DBActionType.PutArtist: |
|
|
|
|
case DBActionType.PatchArtist: |
|
|
|
|
{ |
|
|
|
|
let artist = r.payload as ArtistWithRefsWithId; |
|
|
|
|
artist.tagIds && artist.tagIds.forEach((id: number) => doMap(id, mappings.tags)); |
|
|
|
|
artist.albumIds && artist.albumIds.forEach((id: number) => doMap(id, mappings.albums)); |
|
|
|
|
artist.trackIds && artist.trackIds.forEach((id: number) => doMap(id, mappings.tracks)); |
|
|
|
|
if (artist.id) { artist.id = doMap(artist.id, mappings.artists); } |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case DBActionType.CreateAlbum: |
|
|
|
|
case DBActionType.PutAlbum: |
|
|
|
|
case DBActionType.PatchAlbum: |
|
|
|
|
{ |
|
|
|
|
let album = r.payload as AlbumWithRefsWithId; |
|
|
|
|
album.tagIds && album.tagIds.forEach((id: number) => doMap(id, mappings.tags)); |
|
|
|
|
album.artistIds && album.artistIds.forEach((id: number) => doMap(id, mappings.artists)); |
|
|
|
|
album.trackIds && album.trackIds.forEach((id: number) => doMap(id, mappings.tracks)); |
|
|
|
|
if (album.id) { album.id = doMap(album.id, mappings.albums); } |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case DBActionType.CreateTag: |
|
|
|
|
case DBActionType.PutTag: |
|
|
|
|
case DBActionType.PatchTag: |
|
|
|
|
{ |
|
|
|
|
let tag = r.payload as TagWithRefsWithId; |
|
|
|
|
if (tag.parentId) { tag.parentId = doMap(tag.parentId, mappings.tags); } |
|
|
|
|
if (tag.id) { tag.id = doMap(tag.id, mappings.tags); } |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case DBActionType.DeleteTrack: |
|
|
|
|
case DBActionType.DeleteArtist: |
|
|
|
|
case DBActionType.DeleteAlbum: |
|
|
|
|