plugin identity: added "filename" metadata for avatar
This commit is contained in:
parent
81a11ba6d6
commit
92aa584e4c
2 changed files with 9 additions and 1 deletions
|
|
@ -145,6 +145,9 @@ class Identity:
|
||||||
cache_uid = value['cache_uid']
|
cache_uid = value['cache_uid']
|
||||||
if not cache_uid:
|
if not cache_uid:
|
||||||
raise ValueError
|
raise ValueError
|
||||||
|
filename = value['filename']
|
||||||
|
if not filename:
|
||||||
|
raise ValueError
|
||||||
except (ValueError, KeyError):
|
except (ValueError, KeyError):
|
||||||
log.warning(
|
log.warning(
|
||||||
f"invalid data for {entity} avatar, it will be deleted: "
|
f"invalid data for {entity} avatar, it will be deleted: "
|
||||||
|
|
@ -464,6 +467,7 @@ class Identity:
|
||||||
raise ValueError(f"There is no file at {file_path} to use as avatar")
|
raise ValueError(f"There is no file at {file_path} to use as avatar")
|
||||||
avatar_data = {
|
avatar_data = {
|
||||||
'path': file_path,
|
'path': file_path,
|
||||||
|
'filename': file_path.name,
|
||||||
'media_type': image.guess_type(file_path),
|
'media_type': image.guess_type(file_path),
|
||||||
}
|
}
|
||||||
media_type = avatar_data['media_type']
|
media_type = avatar_data['media_type']
|
||||||
|
|
@ -499,6 +503,7 @@ class Identity:
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"path": path,
|
"path": path,
|
||||||
|
"filename": path.name,
|
||||||
"media_type": media_type,
|
"media_type": media_type,
|
||||||
"cache_uid": cache_uid,
|
"cache_uid": cache_uid,
|
||||||
}
|
}
|
||||||
|
|
@ -509,7 +514,7 @@ class Identity:
|
||||||
async def avatarUpdateDataFilter(self, client, entity, data):
|
async def avatarUpdateDataFilter(self, client, entity, data):
|
||||||
if not isinstance(data, dict):
|
if not isinstance(data, dict):
|
||||||
raise ValueError(f"Invalid data type ({type(data)}), a dict is expected")
|
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:
|
if not data.keys() >= mandatory_keys:
|
||||||
raise ValueError(f"missing avatar data keys: {mandatory_keys - data.keys()}")
|
raise ValueError(f"missing avatar data keys: {mandatory_keys - data.keys()}")
|
||||||
return data
|
return data
|
||||||
|
|
|
||||||
|
|
@ -211,6 +211,7 @@ class XEP_0054(object):
|
||||||
"avatar",
|
"avatar",
|
||||||
{
|
{
|
||||||
'path': avatar_cache['path'],
|
'path': avatar_cache['path'],
|
||||||
|
'filename': avatar_cache['filename'],
|
||||||
'media_type': avatar_cache['mime_type'],
|
'media_type': avatar_cache['mime_type'],
|
||||||
'cache_uid': avatar_hash
|
'cache_uid': avatar_hash
|
||||||
},
|
},
|
||||||
|
|
@ -364,6 +365,7 @@ class XEP_0054(object):
|
||||||
) as f:
|
) as f:
|
||||||
f.write(img_buf.read())
|
f.write(img_buf.read())
|
||||||
avatar_data['path'] = Path(f.name)
|
avatar_data['path'] = Path(f.name)
|
||||||
|
avatar_data['filename'] = avatar_data['path'].name
|
||||||
avatar_data['cache_uid'] = image_hash
|
avatar_data['cache_uid'] = image_hash
|
||||||
return image_hash
|
return image_hash
|
||||||
|
|
||||||
|
|
@ -512,6 +514,7 @@ class XEP_0054_handler(XMPPHandler):
|
||||||
IMPORT_NAME, "avatar",
|
IMPORT_NAME, "avatar",
|
||||||
{
|
{
|
||||||
'path': avatar_cache['path'],
|
'path': avatar_cache['path'],
|
||||||
|
'filename': avatar_cache['filename'],
|
||||||
'media_type': avatar_cache['mime_type'],
|
'media_type': avatar_cache['mime_type'],
|
||||||
'cache_uid': new_hash,
|
'cache_uid': new_hash,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue