def remake_thumbnail()

in assets/assets/utils/minio_utils.py [0:0]


def remake_thumbnail(file_obj: db.models.FileObject, tenant: str) -> bool:
    storage = bd_storage.get_storage(tenant)
    with tempfile.TemporaryDirectory() as t_path:
        f_path = os.path.join(t_path, "file")
        try:
            storage.download(file_obj.path, f_path)
        except bd_storage.BadgerDocStorageError:
            logger_.warning("Original file %s was not found", file_obj.path)
            return False
        with open(f_path, "rb") as obj:
            file_data = obj.read()
    ext = file_obj.extension
    logger_.debug("Generate thumbnail from extension: %s", ext)

    if ext not in chem_utils.SUPPORTED_FORMATS:
        raise exceptions.AssetsUnsupportedFileFormat(
            "File extension %s is not supported", ext
        )

    if "chem" == chem_utils.SUPPORTED_FORMATS[ext]:
        file_bytes = chem_utils.make_thumbnail(file_data, ext)
    elif "pdf" == chem_utils.SUPPORTED_FORMATS[ext]:
        file_bytes = make_thumbnail_pdf(file_data)
    else:
        logger_.error("Unable to create thumbnail, unsupported extension")
        return False

    if file_bytes and isinstance(file_bytes, bytes):
        upload_thumbnail(storage, file_bytes, file_obj.thumb_path)
    image_bytes = make_thumbnail_images(obj.data)
    if image_bytes and isinstance(image_bytes, bytes):
        upload_thumbnail(storage, image_bytes, file_obj.thumb_path)
    if not file_bytes and not image_bytes:
        logger_.error("File is not an image")
        return False
    logger_.info("Successfully created thumbnail for %s", file_obj.path)
    return True