feat(quick-002): add uniquePlaylistName helper and wire into ImportPlaylist

- Add uniquePlaylistName method to auto-rename duplicate names with (1), (2), etc.
- Call uniquePlaylistName only from ImportPlaylist, not CreatePlaylist
This commit is contained in:
2026-02-28 13:53:21 -05:00
parent 04b2088b28
commit 8ba8bbe7be
+19
View File
@@ -681,6 +681,23 @@ func (s *Service) RenamePlaylist(
return nil
}
// uniquePlaylistName returns a name that doesn't collide with existing
// playlists. If "Chill Vibes" exists, returns "Chill Vibes (1)".
// If that also exists, returns "Chill Vibes (2)", etc.
func (s *Service) uniquePlaylistName(name string) string {
count, err := s.db.Queries.CountPlaylistsByName(s.db.Ctx, name)
if err != nil || count == 0 {
return name
}
for i := 1; ; i++ {
candidate := fmt.Sprintf("%s (%d)", name, i)
c, err := s.db.Queries.CountPlaylistsByName(s.db.Ctx, candidate)
if err != nil || c == 0 {
return candidate
}
}
}
// ImportPlaylist imports a playlist from an external M3U/M3U8
// file. It creates a new playlist in the DB, resolves tracks
// against the library, and saves an M3U8 file.
@@ -714,6 +731,8 @@ func (s *Service) ImportPlaylist(
)
}
playlistName = s.uniquePlaylistName(playlistName)
// Create playlist in DB.
created, err := s.db.Queries.CreatePlaylist(
s.db.Ctx, playlistName,