fix: Use a temporary directory with a simple filename for clipboard images

This commit is contained in:
Paul Gauthier (aider) 2024-08-09 08:00:36 -03:00
parent 27af9414d5
commit 604a1fcae4

View file

@ -902,11 +902,9 @@ class Commands:
image = ImageGrab.grabclipboard()
if isinstance(image, Image.Image):
basename = args.strip() if args.strip() else "clipboard_image"
with tempfile.NamedTemporaryFile(
prefix=f"{basename}_", suffix=".png", delete=False
) as temp_file:
image.save(temp_file.name, "PNG")
temp_file_path = temp_file.name
temp_dir = tempfile.mkdtemp()
temp_file_path = os.path.join(temp_dir, f"{basename}.png")
image.save(temp_file_path, "PNG")
abs_file_path = Path(temp_file_path).resolve()
self.coder.abs_fnames.add(str(abs_file_path))