changeset 3326:9e1ba1e1179f

plugin identity: added "filename" metadata for avatar
author Goffi <goffi@goffi.org>
date Sun, 02 Aug 2020 17:40:07 +0200
parents 7ebda4b54170
children ddc10f76fb7e
files sat/plugins/plugin_misc_identity.py sat/plugins/plugin_xep_0054.py
diffstat 2 files changed, 9 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_misc_identity.py	Sat Aug 01 16:25:50 2020 +0200
+++ b/sat/plugins/plugin_misc_identity.py	Sun Aug 02 17:40:07 2020 +0200
@@ -145,6 +145,9 @@
                         cache_uid = value['cache_uid']
                         if not cache_uid:
                             raise ValueError
+                        filename = value['filename']
+                        if not filename:
+                            raise ValueError
                     except (ValueError, KeyError):
                         log.warning(
                             f"invalid data for {entity} avatar, it will be deleted: "
@@ -464,6 +467,7 @@
             raise ValueError(f"There is no file at {file_path} to use as avatar")
         avatar_data = {
             'path': file_path,
+            'filename': file_path.name,
             'media_type': image.guess_type(file_path),
         }
         media_type = avatar_data['media_type']
@@ -499,6 +503,7 @@
 
             return {
                 "path": path,
+                "filename": path.name,
                 "media_type": media_type,
                 "cache_uid": cache_uid,
             }
@@ -509,7 +514,7 @@
     async def avatarUpdateDataFilter(self, client, entity, data):
         if not isinstance(data, dict):
             raise ValueError(f"Invalid data type ({type(data)}), a dict is expected")
-        mandatory_keys = {'path', 'cache_uid'}
+        mandatory_keys = {'path', 'filename', 'cache_uid'}
         if not data.keys() >= mandatory_keys:
             raise ValueError(f"missing avatar data keys: {mandatory_keys - data.keys()}")
         return data
--- a/sat/plugins/plugin_xep_0054.py	Sat Aug 01 16:25:50 2020 +0200
+++ b/sat/plugins/plugin_xep_0054.py	Sun Aug 02 17:40:07 2020 +0200
@@ -211,6 +211,7 @@
                             "avatar",
                             {
                                 'path': avatar_cache['path'],
+                                'filename': avatar_cache['filename'],
                                 'media_type': avatar_cache['mime_type'],
                                 'cache_uid': avatar_hash
                             },
@@ -364,6 +365,7 @@
         ) as f:
             f.write(img_buf.read())
             avatar_data['path'] = Path(f.name)
+            avatar_data['filename'] = avatar_data['path'].name
         avatar_data['cache_uid'] = image_hash
         return image_hash
 
@@ -512,6 +514,7 @@
                 IMPORT_NAME, "avatar",
                 {
                     'path': avatar_cache['path'],
+                    'filename': avatar_cache['filename'],
                     'media_type': avatar_cache['mime_type'],
                     'cache_uid': new_hash,
                 },