Fix patch request for track.

master
Sander Vocke 4 years ago
parent 510cddcf13
commit 9a19bf3cc2
  1. 10
      KNOWN_ISSUES
  2. 17
      client/src/components/windows/track/TrackWindow.tsx
  3. 8
      client/src/lib/integration/spotify/SpotifyClientCreds.tsx
  4. 24
      server/db/Track.ts

@ -3,7 +3,15 @@ last updated: 0a9bec1c874a9b62000b4156ae75e23991121ed0
- Youtube web scraper integration broken - Youtube web scraper integration broken
- Spotify integration only finds artists, not albums or tracks - Spotify integration only finds artists, not albums or tracks
- Tag management shows only top-level tags - Tag management shows only top-level tags
- (Maybe) editing of items broken? - (Maybe) patch requests broken?
- Checked and fixed track
- Lots of front-end typescript warnings - Lots of front-end typescript warnings
- When not logged in, an exception may occur trying to visit a page - When not logged in, an exception may occur trying to visit a page
instead of redirecting properly instead of redirecting properly
- Google Play Music still listed although the service has been
terminated by Google
- during batch linking, linking dialog closes when clicking outside.
this shouldn't happen.
- during batch linking, if the page is left or the dialog closes,
the jobs are still continuing to execute. This shouldn't happen.
- no way to exit the edit dialog

@ -15,6 +15,7 @@ import EditTrackDialog from './EditTrackDialog';
import EditIcon from '@material-ui/icons/Edit'; import EditIcon from '@material-ui/icons/Edit';
import { modifyTrack } from '../../../lib/saveChanges'; import { modifyTrack } from '../../../lib/saveChanges';
import { getTrack } from '../../../lib/backend/tracks'; import { getTrack } from '../../../lib/backend/tracks';
import { Artist, Id, Tag } from '../../../api/api';
export type TrackMetadata = serverApi.QueryResponseTrackDetails; export type TrackMetadata = serverApi.QueryResponseTrackDetails;
@ -142,7 +143,21 @@ export function TrackWindowControlled(props: {
open={editing} open={editing}
onClose={() => { setEditing(false); }} onClose={() => { setEditing(false); }}
onSubmit={(v: serverApi.PatchTrackRequest) => { onSubmit={(v: serverApi.PatchTrackRequest) => {
modifyTrack(trackId, v) // Remove any details about linked resources and leave only their IDs.
let v_modified = {
...v,
album: undefined,
artists: undefined,
tags: undefined,
albumId: v.albumId || v.album?.id || undefined,
artistIds: v.artistIds || v.artists?.map (
(a: (Artist & Id)) => { return a.id }
) || undefined,
tagIds: v.tagIds || v.tags?.map (
(t: (Tag & Id)) => { return t.id }
) || undefined,
};
modifyTrack(trackId, v_modified)
.then(() => dispatch({ .then(() => dispatch({
type: TrackWindowStateActions.Reload type: TrackWindowStateActions.Reload
})) }))

@ -40,8 +40,10 @@ export default class SpotifyClientCreds extends Integration {
`/integrations/${this.integrationId}/v1/search?q=queens&type=artist`); `/integrations/${this.integrationId}/v1/search?q=queens&type=artist`);
if (!response.ok) { if (!response.ok) {
throw new Error("Spttify Client Credentials test failed: " + JSON.stringify(response)); throw new Error("Spotify Client Credentials test failed: " + JSON.stringify(response));
} }
console.log("Spotify test response:", await response.json())
} }
async searchTrack(query: string, limit: number): Promise<IntegrationTrack[]> { async searchTrack(query: string, limit: number): Promise<IntegrationTrack[]> {
@ -49,10 +51,10 @@ export default class SpotifyClientCreds extends Integration {
} }
async searchAlbum(query: string, limit: number): Promise<IntegrationAlbum[]> { async searchAlbum(query: string, limit: number): Promise<IntegrationAlbum[]> {
return this.search(query, SearchType.Album, limit); return this.search(query, SearchType.Album, limit);
} }
async searchArtist(query: string, limit: number): Promise<IntegrationArtist[]> { async searchArtist(query: string, limit: number): Promise<IntegrationArtist[]> {
return this.search(query, SearchType.Artist, limit); return this.search(query, SearchType.Artist, limit);
} }
async search(query: string, type: SearchType, limit: number): async search(query: string, type: SearchType, limit: number):
Promise<IntegrationTrack[] | IntegrationAlbum[] | IntegrationArtist[]> { Promise<IntegrationTrack[] | IntegrationAlbum[] | IntegrationArtist[]> {

@ -180,19 +180,19 @@ export async function modifyTrack(userId: number, trackId: number, track: Track,
// Start retrieving artists if we are modifying those. // Start retrieving artists if we are modifying those.
const artistIdsPromise: Promise<number[] | undefined> = const artistIdsPromise: Promise<number[] | undefined> =
track.artistIds ? track.artistIds ?
trx.select('artistId') trx.select('id')
.from('tracks_artists') .from('artists')
.whereIn('artistId', track.artistIds) .whereIn('id', track.artistIds)
.then((as: any) => as.map((a: any) => a['artistId'])) .then((as: any) => as.map((a: any) => a['id']))
: (async () => undefined)(); : (async () => undefined)();
// Start retrieving tags if we are modifying those. // Start retrieving tags if we are modifying those.
const tagIdsPromise = const tagIdsPromise =
track.tagIds ? track.tagIds ?
trx.select('id') trx.select('id')
.from('tracks_tags') .from('tags')
.whereIn('tagId', track.tagIds) .whereIn('id', track.tagIds)
.then((ts: any) => ts.map((t: any) => t['tagId'])) : .then((ts: any) => ts.map((t: any) => t['id'])) :
(async () => undefined)(); (async () => undefined)();
// Start retrieving album if we are modifying that. // Start retrieving album if we are modifying that.
@ -205,15 +205,15 @@ export async function modifyTrack(userId: number, trackId: number, track: Track,
.then((r: any) => (r && r[0]) ? r[0]['id'] : undefined) : .then((r: any) => (r && r[0]) ? r[0]['id'] : undefined) :
(async () => undefined)(); (async () => undefined)();
let blablums = await trx.select('id').from('albums');
// Wait for the requests to finish. // Wait for the requests to finish.
var [oldTrack, artists, tags, album] = await Promise.all([trackIdPromise, artistIdsPromise, tagIdsPromise, albumIdPromise]);; var [oldTrack, artists, tags, album] = await Promise.all([trackIdPromise, artistIdsPromise, tagIdsPromise, albumIdPromise]);;
console.log("Patch track: ", oldTrack, artists, tags, album);
// Check that we found all objects we need. // Check that we found all objects we need.
if ((!artists || !_.isEqual(artists.sort(), (track.artistIds || []).sort())) || if ((track.artistIds && (!artists || !_.isEqual(artists.sort(), (track.artistIds || []).sort()))) ||
(!tags || !_.isEqual(tags.sort(), (track.tagIds || []).sort())) || (track.tagIds && (!tags || !_.isEqual(tags.sort(), (track.tagIds || []).sort()))) ||
(!album && track.albumId) || (track.albumId && !album) ||
!oldTrack) { !oldTrack) {
throw makeNotFoundError(); throw makeNotFoundError();
} }

Loading…
Cancel
Save