mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-12-30 03:36:12 -05:00
more PR feedback
This commit is contained in:
parent
fb83f6a1fc
commit
1ccabe2965
@ -124,12 +124,10 @@ class PreviewUrlResource(BaseMediaResource):
|
|||||||
|
|
||||||
# first check the memory cache - good to handle all the clients on this
|
# first check the memory cache - good to handle all the clients on this
|
||||||
# HS thundering away to preview the same URL at the same time.
|
# HS thundering away to preview the same URL at the same time.
|
||||||
try:
|
og = self.cache.get(url)
|
||||||
og = self.cache[url]
|
if og:
|
||||||
respond_with_json_bytes(request, 200, json.dumps(og), send_cors=True)
|
respond_with_json_bytes(request, 200, json.dumps(og), send_cors=True)
|
||||||
return
|
return
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# then check the URL cache in the DB (which will also provide us with
|
# then check the URL cache in the DB (which will also provide us with
|
||||||
# historical previews, if we have any)
|
# historical previews, if we have any)
|
||||||
@ -197,6 +195,12 @@ class PreviewUrlResource(BaseMediaResource):
|
|||||||
og = yield self._calc_og(tree, media_info, requester)
|
og = yield self._calc_og(tree, media_info, requester)
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
# XXX: evil evil bodge
|
# XXX: evil evil bodge
|
||||||
|
# Empirically, sites like google.com mix Latin-1 and utf-8
|
||||||
|
# encodings in the same page. The rogue Latin-1 characters
|
||||||
|
# cause lxml to choke with a UnicodeDecodeError, so if we
|
||||||
|
# see this we go and do a manual decode of the HTML before
|
||||||
|
# handing it to lxml as utf-8 encoding, counter-intuitively,
|
||||||
|
# which seems to make it happier...
|
||||||
file = open(media_info['filename'])
|
file = open(media_info['filename'])
|
||||||
body = file.read()
|
body = file.read()
|
||||||
file.close()
|
file.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user