@@ -291,10 +291,8 @@ def _run_bg_render(
291291 raise RuntimeError (f"BG render failed (script={ script_name } , ret={ ret } )" )
292292
293293
294- def _maybe_preview_and_return (result_filepath : str ) -> bool :
295- """Preview result and return True when SKIP_UPDATE is enabled."""
296- if not SKIP_UPDATE :
297- return False
294+ def _preview_and_return (result_filepath : str ) -> bool :
295+ """Preview result and return True is enabled."""
298296 try :
299297 from PIL import Image # lazy import
300298
@@ -304,6 +302,7 @@ def _maybe_preview_and_return(result_filepath: str) -> bool:
304302 opened = utils .open_folder (result_filepath )
305303 if not opened :
306304 logger .error ("Failed to open folder %s" , os .path .dirname (result_filepath ))
305+ return False
307306 return True
308307
309308
@@ -361,8 +360,16 @@ def render_thumbnail_thread(asset_data: dict[str, Any], api_key: str) -> None:
361360
362361 # Render and upload
363362 _run_bg_render (asset_data , asset_file_path , template_path , result_filepath , script_name )
364- if _maybe_preview_and_return (result_filepath ):
363+
364+ if SKIP_UPDATE :
365+ was_opened = _preview_and_return (result_filepath )
366+ if not was_opened :
367+ # clear temp folder if we failed to open it
368+ if asset_file_path and os .path .isfile (asset_file_path ):
369+ os .remove (asset_file_path )
370+ utils .cleanup_temp (temp_folder )
365371 return
372+
366373 _upload_and_clear (asset_data , api_key , result_filepath )
367374
368375 except Exception :
0 commit comments