feat(nodes): use send2trash to delete images, fix thumbnail_path

This commit is contained in:
psychedelicious 2023-04-27 12:36:06 +10:00
parent 0ab62b0343
commit 0cc739afc8

View File

@ -5,10 +5,11 @@ from glob import glob
from abc import ABC, abstractmethod
from pathlib import Path
from queue import Queue
from typing import Dict, List, Tuple
from typing import Dict, List
from PIL.Image import Image
import PIL.Image as PILImage
from send2trash import send2trash
from invokeai.app.api.models.images import (
ImageResponse,
ImageResponseMetadata,
@ -244,15 +245,15 @@ class DiskImageStorage(ImageStorageBase):
image_path = self.get_path(image_type, basename)
if os.path.exists(image_path):
os.remove(image_path)
send2trash(image_path)
if image_path in self.__cache:
del self.__cache[image_path]
thumbnail_name = get_thumbnail_name(image_name)
thumbnail_path = self.get_path(image_type, thumbnail_name, True)
if os.path.exists(image_path):
os.remove(thumbnail_path)
if os.path.exists(thumbnail_path):
send2trash(thumbnail_path)
if thumbnail_path in self.__cache:
del self.__cache[thumbnail_path]