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. 4
      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
- Spotify integration only finds artists, not albums or tracks
- 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
- When not logged in, an exception may occur trying to visit a page
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 { modifyTrack } from '../../../lib/saveChanges';
import { getTrack } from '../../../lib/backend/tracks';
import { Artist, Id, Tag } from '../../../api/api';
export type TrackMetadata = serverApi.QueryResponseTrackDetails;
@ -142,7 +143,21 @@ export function TrackWindowControlled(props: {
open={editing}
onClose={() => { setEditing(false); }}
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({
type: TrackWindowStateActions.Reload
}))

@ -40,8 +40,10 @@ export default class SpotifyClientCreds extends Integration {
`/integrations/${this.integrationId}/v1/search?q=queens&type=artist`);
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[]> {

@ -180,19 +180,19 @@ export async function modifyTrack(userId: number, trackId: number, track: Track,
// Start retrieving artists if we are modifying those.
const artistIdsPromise: Promise<number[] | undefined> =
track.artistIds ?
trx.select('artistId')
.from('tracks_artists')
.whereIn('artistId', track.artistIds)
.then((as: any) => as.map((a: any) => a['artistId']))
trx.select('id')
.from('artists')
.whereIn('id', track.artistIds)
.then((as: any) => as.map((a: any) => a['id']))
: (async () => undefined)();
// Start retrieving tags if we are modifying those.
const tagIdsPromise =
track.tagIds ?
trx.select('id')
.from('tracks_tags')
.whereIn('tagId', track.tagIds)
.then((ts: any) => ts.map((t: any) => t['tagId'])) :
.from('tags')
.whereIn('id', track.tagIds)
.then((ts: any) => ts.map((t: any) => t['id'])) :
(async () => undefined)();
// 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) :
(async () => undefined)();
let blablums = await trx.select('id').from('albums');
// Wait for the requests to finish.
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.
if ((!artists || !_.isEqual(artists.sort(), (track.artistIds || []).sort())) ||
(!tags || !_.isEqual(tags.sort(), (track.tagIds || []).sort())) ||
(!album && track.albumId) ||
if ((track.artistIds && (!artists || !_.isEqual(artists.sort(), (track.artistIds || []).sort()))) ||
(track.tagIds && (!tags || !_.isEqual(tags.sort(), (track.tagIds || []).sort()))) ||
(track.albumId && !album) ||
!oldTrack) {
throw makeNotFoundError();
}

Loading…
Cancel
Save