diff --git a/ckanext/thumbnailer/logic/action.py b/ckanext/thumbnailer/logic/action.py index f592df3..af63b46 100644 --- a/ckanext/thumbnailer/logic/action.py +++ b/ckanext/thumbnailer/logic/action.py @@ -4,7 +4,9 @@ import os import logging import subprocess -from typing import Any, Callable +import datetime +from typing import Any +from ckanext.files.utils import contextlib from preview_generator.exception import UnsupportedMimeType from preview_generator.manager import PreviewManager from werkzeug.datastructures import FileStorage @@ -27,7 +29,6 @@ def resource_thumbnail_create(context, data_dict): preview = _get_preview(res) upload = open(preview, "rb") - existing = utils.resource_file(res["id"]) if existing: @@ -70,6 +71,11 @@ def _get_preview(res: dict[str, Any]): manager = PreviewManager(cache, create_folder=True) max_size = config.max_remote_size() + force = False + with contextlib.suppress(TypeError, KeyError): + uploaded_at = datetime.datetime.fromisoformat(res["last_modified"]) + age = datetime.datetime.now() - uploaded_at + force = age < datetime.timedelta(minutes=10) with path_to_resource(res, max_size) as path: if not path: @@ -79,6 +85,7 @@ def _get_preview(res: dict[str, Any]): path, width=config.width(), height=config.height(), + force=force, ) except (UnsupportedMimeType, subprocess.CalledProcessError) as e: log.error("Cannot extract thumbnail for resource %s: %s", res["id"], e) diff --git a/setup.cfg b/setup.cfg index a4012dd..bc90640 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = ckanext-thumbnailer -version = 0.1.2 +version = 0.1.3 description = long_description = file: README.md long_description_content_type = text/markdown