refactor(thumb): reset thumb status after renaming a file with no thumb available

This commit is contained in:
Aaron Liu
2023-04-07 19:09:13 +08:00
parent f36e39991d
commit ae118c337e
3 changed files with 15 additions and 10 deletions

View File

@@ -101,14 +101,14 @@ func (fs *FileSystem) GenerateThumbnail(ctx context.Context, file *model.File) {
defer w.Close()
errChan := make(chan error, 1)
go func() {
go func(errChan chan error) {
errChan <- fs.Handler.Put(newCtx, &fsctx.FileStream{
Mode: fsctx.Overwrite,
File: io.NopCloser(r),
Seeker: nil,
SavePath: file.SourceName + model.GetSettingByNameWithDefault("thumb_file_suffix", "._thumb"),
})
}()
}(errChan)
if err = thumb.Generators.Generate(source, w, file.Name, model.GetSettingByNames(
"thumb_width",
@@ -120,11 +120,9 @@ func (fs *FileSystem) GenerateThumbnail(ctx context.Context, file *model.File) {
"thumb_ffmpeg_path",
)); err != nil {
util.Log().Warning("Failed to generate thumb for %s: %s", file.Name, err)
if errors.Is(err, thumb.ErrNotAvailable) {
// Mark this file as no thumb available
_ = updateThumbStatus(file, model.ThumbStatusNotAvailable)
}
_ = updateThumbStatus(file, model.ThumbStatusNotAvailable)
w.Close()
<-errChan
return
}

View File

@@ -51,7 +51,7 @@ func NewThumbFromFile(file io.Reader, name string) (*Thumb, error) {
return nil, fmt.Errorf("unknown image format: %w", ErrPassThrough)
}
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to parse image: %w (%w)", err, ErrPassThrough)
}
return &Thumb{