diff --git a/atproto.py b/atproto.py index 556f7313..c2537bae 100644 --- a/atproto.py +++ b/atproto.py @@ -739,10 +739,10 @@ def _convert(cls, obj, fetch_blobs=False, from_user=None): blobs = {} # maps str URL to dict blob object if fetch_blobs: - def fetch_blob(url, blob_field, name, check_size=True): + def fetch_blob(url, blob_field, name, check_size=True, check_type=True): if url and url not in blobs: max_size = blob_field[name].get('maxSize') if check_size else None - accept = blob_field[name].get('accept') + accept = blob_field[name].get('accept') if check_type else None try: blob = AtpRemoteBlob.get_or_create( url=url, get_fn=util.requests_get, max_size=max_size, @@ -753,19 +753,19 @@ def fetch_blob(url, blob_field, name, check_size=True): for o in obj.as1, as1.get_object(obj.as1): for url in util.get_urls(o, 'image'): - # TODO: maybe eventually check size? the current + # TODO: maybe eventually check size and type? the current # 1MB limit feels too small though, and the AppView doesn't # seem to validate, it's happily allowing bigger image blobs - # as of 9/29/2024: + # and different types as of 9/29/2024: # https://github.com/snarfed/bridgy-fed/issues/1348#issuecomment-2381056468 fetch_blob(url, appview.defs['app.bsky.embed.images#image']['properties'], - name='image', check_size=False) + name='image', check_size=False, check_type=False) for att in util.get_list(o, 'attachments'): if isinstance(att, dict): fetch_blob(att.get('stream', {}).get('url'), appview.defs['app.bsky.embed.video']['properties'], - name='video') + name='video', check_size=True, check_type=True) inner_obj = as1.get_object(obj.as1) or obj.as1 orig_url = as1.get_url(inner_obj) or inner_obj.get('id')