Skip to content

Commit

Permalink
feat: refresh thumbnailers for fresh files
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Aug 31, 2024
1 parent 59e2eac commit e2b09a7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions ckanext/thumbnailer/logic/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit e2b09a7

Please sign in to comment.