feat(local): support both time and percent for video thumbnail (#7802)

* feat(local): support percent for video thumbnail

The percentage determines the point in the video (as a percentage of the total duration) at which the thumbnail will be generated.

* feat(local): support both time and percent for video thumbnail
This commit is contained in:
Lin Tianchuan
2025-01-10 20:48:45 +08:00
committed by GitHub
parent 687124c81d
commit 31a7470865
3 changed files with 77 additions and 4 deletions

View File

@ -79,6 +79,28 @@ func (d *Local) Init(ctx context.Context) error {
} else {
d.thumbTokenBucket = NewStaticTokenBucketWithMigration(d.thumbTokenBucket, d.thumbConcurrency)
}
// Check the VideoThumbPos value
if d.VideoThumbPos == "" {
d.VideoThumbPos = "20%"
}
if strings.HasSuffix(d.VideoThumbPos, "%") {
percentage := strings.TrimSuffix(d.VideoThumbPos, "%")
val, err := strconv.ParseFloat(percentage, 64)
if err != nil {
return fmt.Errorf("invalid video_thumb_pos value: %s, err: %s", d.VideoThumbPos, err)
}
if val < 0 || val > 100 {
return fmt.Errorf("invalid video_thumb_pos value: %s, the precentage must be a number between 0 and 100", d.VideoThumbPos)
}
} else {
val, err := strconv.ParseFloat(d.VideoThumbPos, 64)
if err != nil {
return fmt.Errorf("invalid video_thumb_pos value: %s, err: %s", d.VideoThumbPos, err)
}
if val < 0 {
return fmt.Errorf("invalid video_thumb_pos value: %s, the time must be a positive number", d.VideoThumbPos)
}
}
return nil
}