mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: add available generator amount flag (#1696)
This commit is contained in:
@@ -501,12 +501,22 @@ func replacePathTemplate(path string, filename string) string {
|
|||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var availableGeneratorAmount = 32
|
||||||
|
|
||||||
func getOrGenerateThumbnailImage(srcBlob []byte, dstPath string) ([]byte, error) {
|
func getOrGenerateThumbnailImage(srcBlob []byte, dstPath string) ([]byte, error) {
|
||||||
if _, err := os.Stat(dstPath); err != nil {
|
if _, err := os.Stat(dstPath); err != nil {
|
||||||
if !errors.Is(err, os.ErrNotExist) {
|
if !errors.Is(err, os.ErrNotExist) {
|
||||||
return nil, errors.Wrap(err, "failed to check thumbnail image stat")
|
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)
|
reader := bytes.NewReader(srcBlob)
|
||||||
src, err := imaging.Decode(reader)
|
src, err := imaging.Decode(reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user