mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
* Add stash-id to existing when linking tag * Validate id list for duplicates in find queries * Filter out duplicate ids after linking tag
36 lines
871 B
Go
36 lines
871 B
Go
package api
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/stashapp/stash/pkg/sliceutil/stringslice"
|
|
)
|
|
|
|
// TODO - apply handleIDs to other resolvers that accept ID lists
|
|
|
|
// handleIDList validates and converts a list of string IDs to integers
|
|
func handleIDList(idList []string, field string) ([]int, error) {
|
|
if err := validateIDList(idList); err != nil {
|
|
return nil, fmt.Errorf("validating %s: %w", field, err)
|
|
}
|
|
|
|
ids, err := stringslice.StringSliceToIntSlice(idList)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("converting %s: %w", field, err)
|
|
}
|
|
|
|
return ids, nil
|
|
}
|
|
|
|
// validateIDList returns an error if there are any duplicate ids in the list
|
|
func validateIDList(ids []string) error {
|
|
seen := make(map[string]struct{})
|
|
for _, id := range ids {
|
|
if _, exists := seen[id]; exists {
|
|
return fmt.Errorf("duplicate id found: %s", id)
|
|
}
|
|
seen[id] = struct{}{}
|
|
}
|
|
return nil
|
|
}
|