Skip to content

Reuse and clean up temporary thumbnail files #6

Description

@LostOne1000

Priority

Medium

Summary

The plug-in creates uniquely named temporary JPEG files but never deletes them.

The current workflow also exports the selected photo more than once:

  1. When the dialog opens.
  2. Every time Generate is clicked.

Repeated use leaves orphaned files in the system temporary directory.

Relevant code

lightroom-llama.lrplugin/LrLlama.lua

local tempPath =
    LrFileUtils.chooseUniqueFileName(
        LrPathUtils.getStandardFilePath("temp")
            .. "/thumbnail.jpg"
    )

The dialog stores one thumbnail:

local thumbnailPath = exportThumbnail(selectedPhoto)

The Ollama request generates another:

local encodedImage =
    base64EncodeImage(exportThumbnail(photo))

Expected behavior

One generated thumbnail should be reused for the preview and Ollama request, then removed when the dialog context ends.

Implementation notes

  • Generate the thumbnail once.
  • Pass the path or JPEG data into sendDataToApi().
  • Register cleanup through the Lightroom function context.
  • Remove the temporary file when:
    • The dialog is saved.
    • The dialog is canceled.
    • An error occurs.
  • Log cleanup failures without interrupting the user workflow.

Acceptance criteria

  • Opening the dialog creates no more than one temporary thumbnail.
  • Repeated Generate operations reuse the existing thumbnail.
  • The temporary file is removed when the dialog closes.
  • The temporary file is removed following recoverable failures.
  • Cleanup errors do not cause metadata loss or dialog failure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions