Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to track uploading #941

Merged
merged 4 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 38 additions & 31 deletions client/src/components/Header/HeaderSearch.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,49 @@
import React from "react";
import { useTranslation } from "react-i18next";
import { Link, useLocation } from "react-router-dom";
import { Link } from "react-router-dom";
import api from "services/api";
import AutoComplete from "components/common/AutoComplete";
import { debounce } from "lodash";

const HeaderSearch: React.FC = () => {
const { t } = useTranslation("translation", { keyPrefix: "headerSearch" });

const getOptions = React.useCallback(async (searchString: string) => {
const artists = await api.getMany<Artist>(`artists`, {
name: searchString,
});
const trackGroups = await api.getMany<TrackGroup>(`trackGroups`, {
title: searchString,
});
const tracks = await api.getMany<Track>(`tracks`, {
title: searchString,
});
return [
...artists.results.map((r) => ({
artistId: r.urlSlug ?? r.id,
id: r.id,
name: r.name,
})),
...trackGroups.results.map((t) => ({
id: t.urlSlug ?? t.id,
artistId: t.artist?.urlSlug ?? t.artistId,
trackGroupId: t.urlSlug ?? t.id,
name: t.title,
})),
...tracks.results.map((t) => ({
id: t.id,
trackGroupId: t.trackGroup.urlSlug ?? t.trackGroupId,
artistId: t.trackGroup.artist.urlSlug ?? t.trackGroup.artistId,
name: t.title,
})),
];
}, []);
const getOptions = React.useCallback(
debounce(async (searchString: string) => {
const artists = await api.getMany<Artist>(`artists`, {
name: searchString,
});
const trackGroups = await api.getMany<TrackGroup>(`trackGroups`, {
title: searchString,
});
const tracks = await api.getMany<Track>(`tracks`, {
title: searchString,
});
return [
...artists.results.map((r) => ({
artistId: r.urlSlug ?? r.id,
id: r.id,
name: r.name,
isArtist: true,
})),
...trackGroups.results.map((t) => ({
id: t.urlSlug ?? t.id,
artistId: t.artist?.urlSlug ?? t.artistId,
trackGroupId: t.urlSlug ?? t.id,
name: t.title,
isTrackGroup: true,
})),
...tracks.results.map((t) => ({
id: t.id,
trackGroupId: t.trackGroup.urlSlug ?? t.trackGroupId,
artistId: t.trackGroup.artist.urlSlug ?? t.trackGroup.artistId,
name: t.title,
isTrack: true,
})),
];
}, 500),
[]
);

return (
<AutoComplete
Expand Down
40 changes: 26 additions & 14 deletions client/src/components/ManageArtist/BulkTrackUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { BulkTrackUploadRow } from "./BulkTrackUploadRow";

import { Buffer } from "buffer";
import process from "process";
import { pick, pickBy } from "lodash";
import { pick } from "lodash";
import {
TrackData,
UploadField,
Expand All @@ -19,6 +19,7 @@ import {
produceNewStatus,
} from "./utils";
import { useAuthContext } from "state/AuthContext";
import { useSnackbar } from "state/SnackbarContext";

if (typeof window !== "undefined" && typeof window.Buffer === "undefined") {
window.Buffer = Buffer;
Expand Down Expand Up @@ -46,6 +47,7 @@ export const BulkTrackUpload: React.FC<{
trackgroup: TrackGroup;
reload: () => Promise<unknown>;
}> = ({ trackgroup, reload }) => {
const snackbar = useSnackbar();
const { t } = useTranslation("translation", { keyPrefix: "manageAlbum" });
const methods = useForm<FormData>();
const { register, watch, reset } = methods;
Expand All @@ -65,10 +67,12 @@ export const BulkTrackUpload: React.FC<{
if (firstTrack) {
const packet = {
title: firstTrack.t.title,
metadata: pick(firstTrack.t.metadata, ["format", "common", "native"]),
metadata: pick(firstTrack.t.metadata, ["format", "common"]),
artistId: trackgroup.artistId,
isPreview: firstTrack.t.status === "preview",
order: firstTrack.order,
lyrics: firstTrack.t.lyrics,
isrc: firstTrack.t.isrc,
trackGroupId: trackgroup.id,
trackArtists: firstTrack.t.trackArtists.map((a) => ({
...a,
Expand All @@ -81,17 +85,25 @@ export const BulkTrackUpload: React.FC<{
produceNewStatus(queue, firstTrack.t.title, 15)
);

const response = await api.post<Partial<Track>, { result: Track }>(
`manage/tracks`,
packet
);

setUploadQueue((queue) =>
produceNewStatus(queue, firstTrack.t.title, 25)
);
await api.uploadFile(`manage/tracks/${response.result.id}/audio`, [
firstTrack.t.file,
]);
try {
const response = await api.post<Partial<Track>, { result: Track }>(
`manage/tracks`,
packet
);
setUploadQueue((queue) =>
produceNewStatus(queue, firstTrack.t.title, 25)
);
await api.uploadFile(`manage/tracks/${response.result.id}/audio`, [
firstTrack.t.file,
]);
} catch (e) {
snackbar(
`Something went wrong uploading track ${packet.title}. Please report this incident to [email protected]`,
{
type: "warning",
}
);
}

if (remainingTracks.length !== 0) {
setUploadQueue((queue) =>
Expand Down Expand Up @@ -194,7 +206,7 @@ export const BulkTrackUpload: React.FC<{
disabled={disableUploadButton}
multiple
{...register("trackFiles")}
accept="audio/flac,audio/wav,audio/x-flac,audio/aac,audio/aiff,audio/x-m4a"
accept="audio/flac,audio/wav,audio/x-wav,audio/x-flac,audio/aac,audio/aiff,audio/x-m4a"
/>
</UploadLabelWrapper>
</FormComponent>
Expand Down
5 changes: 5 additions & 0 deletions client/src/components/ManageArtist/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export interface TrackData {
title: string;
status: Track["status"];
order: string;
lyrics?: string;
isrc?: string;
metadata: { [key: string]: any };
trackArtists: {
artistName?: string;
Expand All @@ -75,6 +77,7 @@ export const convertMetaData = (
title = p.file.name ?? "";
title = title.replace(/\.wav$/, "");
}
console.log("title", title);

return {
metadata: p.metadata,
Expand All @@ -87,6 +90,8 @@ export const convertMetaData = (
file: p.file,
title: p.metadata.common.title,
status: "preview",
lyrics: p.metadata.common.lyricist,
isrc: p.metadata.common.isrc,
trackArtists:
p.metadata.common.artists?.map((artist) => ({
artistName: artist ?? "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import React from "react";
import { useTranslation } from "react-i18next";
import { FaChevronRight } from "react-icons/fa";
import { Link } from "react-router-dom";
import { getArtistUrl, getTrackGroupUrlReference } from "utils/artist";
import {
getArtistUrl,
getReleaseUrl,
getTrackGroupUrlReference,
} from "utils/artist";

const UserBoughtYourAlbum: React.FC<{ notification: Notification }> = ({
notification,
Expand All @@ -25,7 +29,10 @@ const UserBoughtYourAlbum: React.FC<{ notification: Notification }> = ({
: <strong>{notification.trackGroup.title}</strong>
</div>
<Link
to={getTrackGroupUrlReference(notification.trackGroup)}
to={getReleaseUrl(
notification.trackGroup.artist,
notification.trackGroup
)}
className={css`
display: flex;
align-items: center;
Expand Down
7 changes: 4 additions & 3 deletions client/src/components/common/AutoComplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ const AutoComplete: React.FC<{
val: string
) =>
| Promise<{ id: number | string; name: string; isNew?: boolean }[]>
| { id: number | string; name: string; isNew?: boolean }[];
| { id: number | string; name: string; isNew?: boolean }[]
| undefined;
resultsPrefix?: string;
onSelect?: (value: string | number) => void;
optionDisplay?: (result: {
Expand Down Expand Up @@ -133,14 +134,14 @@ const AutoComplete: React.FC<{
(result) =>
result.name.toLowerCase().replaceAll(/\-| /g, "") === searchString
);
if (allowNew && !searchResultsMatchSearch) {
if (allowNew && !searchResultsMatchSearch && results) {
results.push({
id: searchString,
name: searchString,
isNew: true,
});
}
setSearchResults(results);
setSearchResults(results ?? []);
setIsSearching(false);
setNavigationIndex(0);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/routers/v1/artists/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function () {
};

async function GET(req: Request, res: Response, next: NextFunction) {
const { skip: skipQuery, take, name } = req.query;
const { skip: skipQuery, take = 10, name } = req.query;

try {
let where: Prisma.ArtistWhereInput = {
Expand Down
9 changes: 8 additions & 1 deletion src/routers/v1/trackGroups/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ export default function () {
};

async function GET(req: Request, res: Response, next: NextFunction) {
const { skip: skipQuery, take, orderBy, tag, artistId, title } = req.query;
const {
skip: skipQuery,
take = 10,
orderBy,
tag,
artistId,
title,
} = req.query;
const distinctArtists = req.query.distinctArtists === "true";

try {
Expand Down
2 changes: 1 addition & 1 deletion src/routers/v1/tracks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function () {
};

async function GET(req: Request, res: Response, next: NextFunction) {
const { skip: skipQuery, take, title } = req.query;
const { skip: skipQuery, take = 10, title } = req.query;

try {
let where: Prisma.TrackWhereInput = {
Expand Down
Loading