diff --git a/boards/models/attachment/downloaders.py b/boards/models/attachment/downloaders.py --- a/boards/models/attachment/downloaders.py +++ b/boards/models/attachment/downloaders.py @@ -19,6 +19,11 @@ FILE_DOWNLOAD_CHUNK_BYTES = 200000 YOUTUBE_URL = re.compile(r'https?://((www\.)?youtube\.com/watch\?v=|youtu.be/)[-\w]+') +TYPE_URL_ONLY = ( + 'application/xhtml+xml', + 'text/html', +) + class Downloader: @staticmethod @@ -77,3 +82,14 @@ class YouTubeDownloader(Downloader): def handles(url: str) -> bool: return YOUTUBE_URL.match(url) + +class NothingDownloader(Downloader): + @staticmethod + def handles(url: str) -> bool: + response_head = requests.head(url, verify=False) + content_type = response_head.headers[HEADER_CONTENT_TYPE].split(';')[0] + return content_type in TYPE_URL_ONLY + + @staticmethod + def download(url: str): + return None