Mercurial > libervia-web
changeset 1325:009542289bc9
pages (files/list): removed/updated code to download thumbnails and sort them as it is now done by the backend
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 14 Aug 2020 09:09:03 +0200 |
parents | 898442c4ff68 |
children | 089742e065e3 |
files | libervia/pages/files/list/page_meta.py |
diffstat | 1 files changed, 7 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- 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"])