# HG changeset patch # User Goffi # Date 1597388943 -7200 # Node ID 009542289bc9146a875457b16af45461f11ad63d # Parent 898442c4ff681ee3ec9e38eedb6f25369073de81 pages (files/list): removed/updated code to download thumbnails and sort them as it is now done by the backend diff -r 898442c4ff68 -r 009542289bc9 libervia/pages/files/list/page_meta.py --- a/libervia/pages/files/list/page_meta.py Fri Aug 14 09:06:56 2020 +0200 +++ b/libervia/pages/files/list/page_meta.py Fri Aug 14 09:09:03 2020 +0200 @@ -3,7 +3,6 @@ import json import os from pathlib import Path -from sat.core.i18n import _ from sat.core.log import getLogger from sat.tools.common import uri from sat_frontends.bridge.bridge_frontend import BridgeException @@ -58,36 +57,20 @@ elif file_data["type"] == C.FILE_TYPE_FILE: page = self.getPageByName("files_view") - ## thumbnails ## + # we set URL for the last thumbnail which has a size below thumb_limit try: thumbnails = file_data["extra"]["thumbnails"] - if not thumbnails: - raise KeyError - except KeyError: - pass - else: - thumbnails.sort(key=lambda t: t["size"]) thumb = thumbnails[0] for thumb_data in thumbnails: if thumb_data["size"][0] > thumb_limit: break thumb = thumb_data - if "url" in thumb: - file_data["thumb_url"] = thumb["url"] - elif "id" in thumb: - try: - thumb_path = await self.host.bridgeCall( - "bobGetFile", service.full(), thumb["id"], profile - ) - except Exception as e: - log.warning( - _("Can't retrieve thumbnail: {reason}").format(reason=e) - ) - else: - filename = os.path.basename(thumb_path) - file_data["thumb_url"] = os.path.join( - session_data.cache_dir, filename - ) + file_data["thumb_url"] = ( + thumb.get("url") + or os.path.join(session_data.cache_dir, thumb["filename"]) + ) + except (KeyError, IndexError): + pass else: raise ValueError( "unexpected file type: {file_type}".format(file_type=file_data["type"])