1
0
mirror of https://github.com/enpaul/kodak.git synced 2024-11-23 15:07:13 +00:00

Fix handling of relative paths in image source field

This commit is contained in:
Ethan Paul 2021-11-22 17:34:07 -05:00
parent bbb7dec2b3
commit 5613f8287c
No known key found for this signature in database
GPG Key ID: D0E2CBF1245E92BF
2 changed files with 6 additions and 6 deletions

View File

@ -23,7 +23,7 @@ class Image(KodakResource):
# "original". This is because flask will serve the symlink file itself, not the linked file, # "original". This is because flask will serve the symlink file itself, not the linked file,
# to the browser. # to the browser.
resp = flask.send_file( resp = flask.send_file(
image.source, flask.current_app.appconfig.source_dir / image.source,
cache_timeout=int(datetime.timedelta(days=365).total_seconds()), cache_timeout=int(datetime.timedelta(days=365).total_seconds()),
add_etags=False, add_etags=False,
) )

View File

@ -21,7 +21,7 @@ def identify(config: configuration.KodakConfig) -> List[database.ImageRecord]:
for item in path.iterdir(): for item in path.iterdir():
if item.is_file() and item.suffix in constants.IMAGE_FILE_EXTENSIONS: if item.is_file() and item.suffix in constants.IMAGE_FILE_EXTENSIONS:
logger.debug(f"Including file {item}") logger.debug(f"Including file {item}")
identified.append(item) identified.append(item.resolve())
elif item.is_dir(): elif item.is_dir():
logger.debug(f"Entering subdirectory {item}") logger.debug(f"Entering subdirectory {item}")
identified += _identify(item) identified += _identify(item)
@ -49,7 +49,7 @@ def identify(config: configuration.KodakConfig) -> List[database.ImageRecord]:
results = [] results = []
for image in images: for image in images:
if image in existing: if image.relative_to(config.source_dir) in existing:
logger.debug(f"Skipping existing {image}") logger.debug(f"Skipping existing {image}")
else: else:
logger.debug(f"Including newly identified image {image}") logger.debug(f"Including newly identified image {image}")
@ -58,7 +58,7 @@ def identify(config: configuration.KodakConfig) -> List[database.ImageRecord]:
return results return results
def clean() -> List[database.ImageRecord]: def clean(config: configuration.KodakConfig) -> List[database.ImageRecord]:
"""Identify removed or changed source images and mark them as deleted """Identify removed or changed source images and mark them as deleted
:param config: Populated application configuration object :param config: Populated application configuration object
@ -78,7 +78,7 @@ def clean() -> List[database.ImageRecord]:
deleted = [] deleted = []
for item in existing: for item in existing:
if item.source.exists(): if (config.source_dir / item.source).exists():
logger.debug( logger.debug(
f"Image file exists, record will not be modified: {item.source}" f"Image file exists, record will not be modified: {item.source}"
) )
@ -108,7 +108,7 @@ def build(config: Optional[configuration.KodakConfig] = None) -> None:
batch_size=database.calc_batch_size(config.database.backend, new_images), batch_size=database.calc_batch_size(config.database.backend, new_images),
) )
removed_images = clean() removed_images = clean(config)
with database.interface.atomic(): with database.interface.atomic():
database.ImageRecord.bulk_update( database.ImageRecord.bulk_update(
removed_images, removed_images,