From 03458db82937a260406d503977a0a4ffd57e33bf Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Thu, 9 May 2024 18:33:13 +0400 Subject: [PATCH] Fix: cover.download() - resp.read returns nothing, contents are already in resp.data - add mime type safety check --- backend/cover.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/cover.py b/backend/cover.py index 89465e2..4432a52 100644 --- a/backend/cover.py +++ b/backend/cover.py @@ -33,12 +33,14 @@ def download(url: str, album_path: Path) -> None: '''General cover art downloader''' resp = http_pool.get().request('GET', url) - ext = mimetypes.guess_extension(resp.headers['content-type']) or '.jpg' + ct = resp.headers['content-type'] + if not ct.startswith('image'): + raise ValueError('thumbnail is not an image') + ext = mimetypes.guess_extension(ct) or '.jpg' path = album_path / ('cover' + ext) if path.exists(): return - with (album_path / ('cover' + ext)).open('wb') as f: - for chunk in resp.read_chunked(): - f.write(chunk) + with path.open('wb') as f: + f.write(resp.data)