bugfix/youtube-embed #37
@ -181,12 +181,12 @@ def enrich_image_rendering(text):
 | 
			
		||||
    soup = BeautifulSoup(text, "html.parser")
 | 
			
		||||
    for element in soup.find_all("img"):
 | 
			
		||||
        if element.attrs["src"].startswith("/"):
 | 
			
		||||
            element.attrs["src"] += "?width=240&height=240&format=webp"
 | 
			
		||||
            element.attrs["src"] += "?width=240&height=240"
 | 
			
		||||
            picture_template = f'''
 | 
			
		||||
                                <picture>
 | 
			
		||||
                                    <source srcset="{element.attrs["src"]}" type="{mimetypes.guess_type(element.attrs["src"])[0]}" />
 | 
			
		||||
                                    <source srcset="{element.attrs["src"]}" type="image/webp" />
 | 
			
		||||
                                    <img src="{element.attrs["src"]}" title="{element.attrs["src"]}" alt="{element.attrs["src"]}" />
 | 
			
		||||
                                    <source srcset="{element.attrs["src"]}&format=webp" type="image/webp" />
 | 
			
		||||
                                    <img src="{element.attrs["src"]}&format=png" title="{element.attrs["src"]}" alt="{element.attrs["src"]}" />
 | 
			
		||||
                                </picture>'''
 | 
			
		||||
            element.replace_with(BeautifulSoup(picture_template, "html.parser"))
 | 
			
		||||
    return str(soup)
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,6 @@
 | 
			
		||||
import asyncio
 | 
			
		||||
import mimetypes
 | 
			
		||||
from os.path import isfile
 | 
			
		||||
 | 
			
		||||
from PIL import Image
 | 
			
		||||
import pillow_heif.HeifImagePlugin
 | 
			
		||||
@ -17,7 +18,7 @@ class ChannelAttachmentView(BaseView):
 | 
			
		||||
            relative_url=relative_path
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        if not channel_attachment:
 | 
			
		||||
        if not channel_attachment or not isfile(channel_attachment["path"]):
 | 
			
		||||
            return web.HTTPNotFound()
 | 
			
		||||
 | 
			
		||||
        original_format = mimetypes.guess_type(channel_attachment["path"])[0]
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user