refactor: reduce cyclomatic complexity of UpsertSkipSegmentOverride
This commit is contained in:
@@ -398,6 +398,17 @@ func (s *playbackService) SaveProgress(ctx context.Context, userID string, anime
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func normalizeSkipType(skipType string) (string, error) {
|
||||||
|
switch strings.ToLower(strings.TrimSpace(skipType)) {
|
||||||
|
case "op", "opening", "intro":
|
||||||
|
return "op", nil
|
||||||
|
case "ed", "ending", "outro":
|
||||||
|
return "ed", nil
|
||||||
|
default:
|
||||||
|
return "", fmt.Errorf("invalid skip_type")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *playbackService) UpsertSkipSegmentOverride(ctx context.Context, userID string, animeID int64, episode int, skipType string, startTime, endTime float64) error {
|
func (s *playbackService) UpsertSkipSegmentOverride(ctx context.Context, userID string, animeID int64, episode int, skipType string, startTime, endTime float64) error {
|
||||||
if userID == "" {
|
if userID == "" {
|
||||||
return fmt.Errorf("not authenticated")
|
return fmt.Errorf("not authenticated")
|
||||||
@@ -405,14 +416,9 @@ func (s *playbackService) UpsertSkipSegmentOverride(ctx context.Context, userID
|
|||||||
if animeID <= 0 || episode <= 0 {
|
if animeID <= 0 || episode <= 0 {
|
||||||
return fmt.Errorf("invalid anime/episode")
|
return fmt.Errorf("invalid anime/episode")
|
||||||
}
|
}
|
||||||
t := strings.ToLower(strings.TrimSpace(skipType))
|
t, err := normalizeSkipType(skipType)
|
||||||
switch t {
|
if err != nil {
|
||||||
case "op", "opening", "intro":
|
return err
|
||||||
t = "op"
|
|
||||||
case "ed", "ending", "outro":
|
|
||||||
t = "ed"
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("invalid skip_type")
|
|
||||||
}
|
}
|
||||||
if !(startTime >= 0) || !(endTime > startTime) {
|
if !(startTime >= 0) || !(endTime > startTime) {
|
||||||
return fmt.Errorf("invalid interval")
|
return fmt.Errorf("invalid interval")
|
||||||
|
|||||||
Reference in New Issue
Block a user