mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-04 15:10:56 +08:00
feat: complete music entity workflows
This commit is contained in:
@@ -10,6 +10,8 @@ describe('media source identity utils', () => {
|
||||
expect(isValidMediaSourceId('977e6978-139d-425c-bb98-6b0c62d1e45e', 'musicbrainz')).toBe(true)
|
||||
expect(isValidMediaSourceId('32793500', 'theaudiodb')).toBe(true)
|
||||
expect(isValidMediaSourceId('1401853', 'doubanmusic')).toBe(true)
|
||||
expect(isValidMediaSourceId('1401853:3', 'doubanmusic')).toBe(true)
|
||||
expect(isValidMediaSourceId('1401853:track', 'doubanmusic')).toBe(false)
|
||||
expect(isValidMediaSourceId('not-a-number', 'theaudiodb')).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -77,7 +77,12 @@ describe('music utils', () => {
|
||||
),
|
||||
).toMatchObject({
|
||||
path: '/resource',
|
||||
query: { keyword: 'musicbrainz:recording-1', sites: '11,12', type: '音乐' },
|
||||
query: {
|
||||
keyword: 'musicbrainz:recording-1',
|
||||
music_type: 'recording',
|
||||
sites: '11,12',
|
||||
type: '音乐',
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ export function isMusicMediaSource(source?: MediaDataSource): boolean {
|
||||
return MUSIC_MEDIA_SOURCES.includes(source as (typeof MUSIC_MEDIA_SOURCES)[number])
|
||||
}
|
||||
|
||||
/** 按媒体数据源校验原生 ID,MusicBrainz 使用 UUID,其它内置来源使用数字 ID。 */
|
||||
/** 按媒体数据源校验原生 ID,并兼容豆瓣音乐的曲目复合 ID。 */
|
||||
export function isValidMediaSourceId(value: string | number | null | undefined, source?: MediaDataSource): boolean {
|
||||
const normalized = value?.toString().trim()
|
||||
if (!normalized) return true
|
||||
@@ -16,5 +16,8 @@ export function isValidMediaSourceId(value: string | number | null | undefined,
|
||||
if (source === 'musicbrainz' || MUSICBRAINZ_ID_PATTERN.test(normalized)) {
|
||||
return MUSICBRAINZ_ID_PATTERN.test(normalized)
|
||||
}
|
||||
if (source === 'doubanmusic' && normalized.includes(':')) {
|
||||
return /^\d+:\d+$/.test(normalized)
|
||||
}
|
||||
return /^\d+$/.test(normalized)
|
||||
}
|
||||
|
||||
@@ -122,6 +122,7 @@ export function buildMusicResourceRoute(
|
||||
query: {
|
||||
keyword: `${source}:${item.media_id}`,
|
||||
type: '音乐',
|
||||
music_type: (item as MusicRouteTarget).music_type || 'recording',
|
||||
title: item.title,
|
||||
year: item.year,
|
||||
area: 'title',
|
||||
|
||||
Reference in New Issue
Block a user