feat(thumb): use ffmpeg to generate thumb

This commit is contained in:
Aaron Liu
2023-04-07 19:30:41 +08:00
parent b55344459d
commit 98b86b37de
6 changed files with 112 additions and 8 deletions

View File

@@ -13,7 +13,9 @@ import (
// Generator generates a thumbnail for a given reader.
type Generator interface {
Generate(ctx context.Context, file io.Reader, name string, options map[string]string) (string, error)
// Generate generates a thumbnail for a given reader. Src is the original file path, only provided
// for local policy files.
Generate(ctx context.Context, file io.Reader, src string, name string, options map[string]string) (string, error)
// Priority of execution order, smaller value means higher priority.
Priority() int
@@ -52,10 +54,10 @@ func RegisterGenerator(generator Generator) {
sort.Sort(Generators)
}
func (p GeneratorList) Generate(ctx context.Context, file io.Reader, name string, options map[string]string) (string, error) {
func (p GeneratorList) Generate(ctx context.Context, file io.Reader, src, name string, options map[string]string) (string, error) {
for _, generator := range p {
if model.IsTrueVal(options[generator.EnableFlag()]) {
res, err := generator.Generate(ctx, file, name, options)
res, err := generator.Generate(ctx, file, src, name, options)
if errors.Is(err, ErrPassThrough) {
util.Log().Debug("Failed to generate thumbnail for %s: %s, passing through to next generator.", name, err)
continue