fix keyerror when thumbnail isn't available
This commit is contained in:
parent
9e8a6bd123
commit
76e1c15b69
1 changed files with 10 additions and 4 deletions
|
@ -56,15 +56,21 @@ def on_receive_events(transaction):
|
|||
text = "* " + get_displayname(event["user_id"]) + " " + event['content']['body']
|
||||
elif event['content']['msgtype'] == 'm.image':
|
||||
imgurl = app.config['MATRIX_HOST'] + '/_matrix/media/r0/download/' + event['content']['url'][6:]
|
||||
thmburl = app.config['MATRIX_HOST'] + '/_matrix/media/r0/download/' + event['content']['info']['thumbnail_url'][6:]
|
||||
|
||||
value = {"type": "photo", "version": "1.0"}
|
||||
value["title"] = event['content']['body']
|
||||
value["url"] = imgurl
|
||||
value["width"] = event['content']['info']['w']
|
||||
value["height"] = event['content']['info']['h']
|
||||
if 'thumbnail_info' in event['content']['info']:
|
||||
thmburl = app.config['MATRIX_HOST'] + '/_matrix/media/r0/download/' + event['content']['info']['thumbnail_url'][6:]
|
||||
value["thumbnail_width"] = event['content']['info']['thumbnail_info']['w']
|
||||
value["thumbnail_height"] = event['content']['info']['thumbnail_info']['h']
|
||||
value["thumbnail_url"] = thmburl
|
||||
else:
|
||||
value["thumbnail_width"] = event['content']['info']['w']
|
||||
value["thumbnail_height"] = event['content']['info']['h']
|
||||
value["thumbnail_url"] = imgurl
|
||||
rawitem = {"type": "io.pnut.core.oembed", "value": value}
|
||||
embed = [rawitem]
|
||||
if user:
|
||||
|
|
Loading…
Reference in a new issue