Filter library tracks on the server and add track publishing, bulk delete and album types

This commit is contained in:
2026-09-25 01:49:44 +02:00
parent 93d7a23c53
commit 9f592cfdb8
21 changed files with 505 additions and 204 deletions
@@ -12,11 +12,19 @@ describe('parseAlbumForm', () => {
it('parses a valid form and trims values', () => {
expect(
parseAlbumForm(form({ title: ' Title ', description: ' d ', releaseYear: '2020' }))
).toEqual({ body: { title: 'Title', description: 'd', releaseYear: 2020 } });
).toEqual({ body: { title: 'Title', description: 'd', releaseYear: 2020, type: 'Album' } });
});
it('turns empty optional fields into null', () => {
expect(parseAlbumForm(form({ title: 'T' }))).toEqual({
body: { title: 'T', description: null, releaseYear: null }
body: { title: 'T', description: null, releaseYear: null, type: 'Album' }
});
});
it('maps the album type', () => {
expect(parseAlbumForm(form({ title: 'T', type: 'ep' }))).toMatchObject({
body: { type: 'EP' }
});
expect(parseAlbumForm(form({ title: 'T', type: 'x' }))).toMatchObject({
body: { type: 'Album' }
});
});
it('rejects empty or too long titles', () => {
+9 -1
View File
@@ -5,8 +5,15 @@ export interface AlbumFormBody {
title: string;
description: string | null;
releaseYear: number | null;
type: 'Album' | 'EP' | 'Single';
}
const ALBUM_TYPES: Record<string, AlbumFormBody['type']> = {
album: 'Album',
ep: 'EP',
single: 'Single'
};
export function parseAlbumForm(form: FormData): { body: AlbumFormBody } | { failMessage: string } {
const title = formString(form, 'title').trim();
if (title === '' || title.length > LIMITS.albumTitle) {
@@ -36,7 +43,8 @@ export function parseAlbumForm(form: FormData): { body: AlbumFormBody } | { fail
body: {
title,
description: description === '' ? null : description,
releaseYear
releaseYear,
type: ALBUM_TYPES[formString(form, 'type')] ?? 'Album'
}
};
}