From 8ba8bbe7bed2ecff97613ebaa42a49a662050353 Mon Sep 17 00:00:00 2001 From: Caleb Allen Date: Sat, 28 Feb 2026 13:53:21 -0500 Subject: [PATCH] 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 --- backend/playlist/playlist.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/backend/playlist/playlist.go b/backend/playlist/playlist.go index 51e099a..675e5fb 100644 --- a/backend/playlist/playlist.go +++ b/backend/playlist/playlist.go @@ -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,