@@ -262,6 +262,7 @@ async def _do_preview(self, url: str, user: UserID, ts: int) -> bytes:
262
262
263
263
# The number of milliseconds that the response should be considered valid.
264
264
expiration_ms = media_info .expires
265
+ author_name : Optional [str ] = None
265
266
266
267
if _is_media (media_info .media_type ):
267
268
file_id = media_info .filesystem_id
@@ -297,7 +298,11 @@ async def _do_preview(self, url: str, user: UserID, ts: int) -> bytes:
297
298
og_from_oembed : JsonDict = {}
298
299
if oembed_url :
299
300
oembed_info = await self ._download_url (oembed_url , user )
300
- og_from_oembed , expiration_ms = await self ._handle_oembed_response (
301
+ (
302
+ og_from_oembed ,
303
+ author_name ,
304
+ expiration_ms ,
305
+ ) = await self ._handle_oembed_response (
301
306
url , oembed_info , expiration_ms
302
307
)
303
308
@@ -315,7 +320,7 @@ async def _do_preview(self, url: str, user: UserID, ts: int) -> bytes:
315
320
316
321
elif oembed_url :
317
322
# Handle the oEmbed information.
318
- og , expiration_ms = await self ._handle_oembed_response (
323
+ og , author_name , expiration_ms = await self ._handle_oembed_response (
319
324
url , media_info , expiration_ms
320
325
)
321
326
await self ._precache_image_url (user , media_info , og )
@@ -326,8 +331,8 @@ async def _do_preview(self, url: str, user: UserID, ts: int) -> bytes:
326
331
327
332
# If we don't have a title but we have author_name, copy it as
328
333
# title
329
- if not og .get ("og:title" ) and og . get ( "og: author_name" ) :
330
- og ["og:title" ] = og [ "og: author_name" ]
334
+ if not og .get ("og:title" ) and author_name :
335
+ og ["og:title" ] = author_name
331
336
332
337
# filter out any stupidly long values
333
338
keys_to_remove = []
@@ -492,7 +497,7 @@ async def _precache_image_url(
492
497
493
498
async def _handle_oembed_response (
494
499
self , url : str , media_info : MediaInfo , expiration_ms : int
495
- ) -> Tuple [JsonDict , int ]:
500
+ ) -> Tuple [JsonDict , Optional [ str ], int ]:
496
501
"""
497
502
Parse the downloaded oEmbed info.
498
503
@@ -509,7 +514,7 @@ async def _handle_oembed_response(
509
514
"""
510
515
# If JSON was not returned, there's nothing to do.
511
516
if not _is_json (media_info .media_type ):
512
- return {}, expiration_ms
517
+ return {}, None , expiration_ms
513
518
514
519
with open (media_info .filename , "rb" ) as file :
515
520
body = file .read ()
@@ -521,7 +526,7 @@ async def _handle_oembed_response(
521
526
if open_graph_result and oembed_response .cache_age is not None :
522
527
expiration_ms = oembed_response .cache_age
523
528
524
- return open_graph_result , expiration_ms
529
+ return open_graph_result , oembed_response . author_name , expiration_ms
525
530
526
531
def _start_expire_url_cache_data (self ) -> Deferred :
527
532
return run_as_background_process (
0 commit comments