chore: add available generator amount flag (#1696)

This commit is contained in:
boojack 2023-05-21 11:50:57 +08:00 committed by GitHub
parent 467f9080a1
commit ba8e1e5dc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -501,12 +501,22 @@ func replacePathTemplate(path string, filename string) string {
return path
}
var availableGeneratorAmount = 32
func getOrGenerateThumbnailImage(srcBlob []byte, dstPath string) ([]byte, error) {
if _, err := os.Stat(dstPath); err != nil {
if !errors.Is(err, os.ErrNotExist) {
return nil, errors.Wrap(err, "failed to check thumbnail image stat")
}
if availableGeneratorAmount <= 0 {
return nil, errors.New("not enough available generator amount")
}
availableGeneratorAmount--
defer func() {
availableGeneratorAmount++
}()
reader := bytes.NewReader(srcBlob)
src, err := imaging.Decode(reader)
if err != nil {