Allow an image to be uploaded to the controller again even if it is already in the database
Some checks are pending
testing / build (ubuntu-latest, 3.10) (push) Waiting to run
testing / build (ubuntu-latest, 3.11) (push) Waiting to run
testing / build (ubuntu-latest, 3.12) (push) Waiting to run
testing / build (ubuntu-latest, 3.13) (push) Waiting to run
testing / build (ubuntu-latest, 3.9) (push) Waiting to run

This commit is contained in:
grossmj 2025-04-17 19:07:22 +07:00
parent 0826b9c259
commit aa8ccf4f82
No known key found for this signature in database
GPG Key ID: 1E7DD6DBB53FF3D7
2 changed files with 10 additions and 5 deletions

View File

@ -148,11 +148,6 @@ async def upload_image(
if os.path.commonprefix([base_images_directory, full_path]) != base_images_directory:
raise ControllerForbiddenError(f"Cannot write image, '{image_path}' is forbidden")
image = await images_repo.get_image(image_path)
if image:
log.warning(f"Image '{image_path}' already exists")
return image
try:
allow_raw_image = Config.instance().settings.Server.allow_raw_images
image = await write_image(image_path, full_path, request.stream(), images_repo, allow_raw_image=allow_raw_image)

View File

@ -342,6 +342,12 @@ async def write_image(
allow_raw_image=False
) -> models.Image:
db_image = await images_repo.get_image(image_path)
if db_image and os.path.exists(image_path):
# the image already exists in the database and on disk
log.info(f"Image {image_path} already exists")
return db_image
image_dir, image_name = os.path.split(image_filename)
log.info(f"Writing image file to '{image_path}'")
# Store the file under its final name only when the upload is completed
@ -381,6 +387,10 @@ async def write_image(
except OSError:
log.warning(f"Could not remove '{tmp_path}'")
if db_image:
# the image already exists in the database, no need to add it again
return db_image
return await images_repo.add_image(
image_name,
image_type,