feat(webp): add partial success to conversion

So we only keep images that couldn't be optimized and return the chapter
This commit is contained in:
Antoine Aflalo
2024-08-28 13:49:14 -04:00
parent d7f55fa886
commit ad35e2655f
6 changed files with 117 additions and 30 deletions

View File

@@ -1,9 +1,11 @@
package utils
import (
"errors"
"fmt"
"github.com/belphemur/CBZOptimizer/cbz"
"github.com/belphemur/CBZOptimizer/converter"
errors2 "github.com/belphemur/CBZOptimizer/converter/errors"
"log"
"strings"
)
@@ -38,8 +40,15 @@ func Optimize(options *OptimizeOptions) error {
}
})
if err != nil {
return fmt.Errorf("failed to convert chapter: %v", err)
var pageIgnoredError *errors2.PageIgnoredError
if !errors.As(err, &pageIgnoredError) {
return fmt.Errorf("failed to convert chapter: %v", err)
}
}
if convertedChapter == nil {
return fmt.Errorf("failed to convert chapter")
}
convertedChapter.SetConverted()
// Write the converted chapter back to a CBZ file