mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-07 22:34:58 -04:00
Sanitize the optional dependencies for spider API
This commit is contained in:
parent
10ebbaea2e
commit
d0633e6dbe
4 changed files with 32 additions and 39 deletions
|
@ -40,33 +40,11 @@ import ujson as json
|
|||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
try:
|
||||
from lxml import html
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
class PreviewUrlResource(BaseMediaResource):
|
||||
isLeaf = True
|
||||
|
||||
def __init__(self, hs, filepaths):
|
||||
try:
|
||||
if html:
|
||||
pass
|
||||
except:
|
||||
raise RuntimeError("Disabling PreviewUrlResource as lxml not available")
|
||||
|
||||
if not hasattr(hs.config, "url_preview_ip_range_blacklist"):
|
||||
logger.warn(
|
||||
"For security, you must specify an explicit target IP address "
|
||||
"blacklist in url_preview_ip_range_blacklist for url previewing "
|
||||
"to work"
|
||||
)
|
||||
raise RuntimeError(
|
||||
"Disabling PreviewUrlResource as "
|
||||
"url_preview_ip_range_blacklist not specified"
|
||||
)
|
||||
|
||||
BaseMediaResource.__init__(self, hs, filepaths)
|
||||
self.client = SpiderHttpClient(hs)
|
||||
if hasattr(hs.config, "url_preview_url_blacklist"):
|
||||
|
@ -201,6 +179,8 @@ class PreviewUrlResource(BaseMediaResource):
|
|||
elif self._is_html(media_info['media_type']):
|
||||
# TODO: somehow stop a big HTML tree from exploding synapse's RAM
|
||||
|
||||
from lxml import html
|
||||
|
||||
try:
|
||||
tree = html.parse(media_info['filename'])
|
||||
og = yield self._calc_og(tree, media_info, requester)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue