From b8edffb6e4f249c0c29d8d73e9924354c0e70089 Mon Sep 17 00:00:00 2001 From: Xsarz <88231084+xXxCLOTIxXx@users.noreply.github.com> Date: Wed, 1 May 2024 13:24:42 +0300 Subject: [PATCH] Update constants.py --- AminoLightPy/constants.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/AminoLightPy/constants.py b/AminoLightPy/constants.py index fc2ca18..81a2e05 100644 --- a/AminoLightPy/constants.py +++ b/AminoLightPy/constants.py @@ -4,6 +4,7 @@ from typing import BinaryIO from collections import OrderedDict from requests import Session +from mimetypes import guess_type from .lib.util.exceptions import SpecifyType from .lib.util import signature, gen_deviceId @@ -54,7 +55,7 @@ def request(self, method, url, *args, **kwargs): return response -def upload_media(self, file: BinaryIO, fileType: str) -> str: +def upload_media(self, file: BinaryIO) -> str: """ Upload file to the amino servers. @@ -71,15 +72,13 @@ def upload_media(self, file: BinaryIO, fileType: str) -> str: file_hash = sha1(data).hexdigest() if file_hash in cache: return cache[file_hash] - - if fileType == "audio": - t = "audio/aac" - elif fileType == "image": - t = "image/jpg" - elif fileType == "gif": - t = "image/gif" - else: raise SpecifyType(fileType) - + + fileType = guess_type(file.name)[0] + if fileType not in ( + "image/gif", "image/jpg", + "audio/aac", "audio/png" + ): raise SpecifyType(fileType) #but this check can be removed, I think + custom_headers = self.session.headers custom_headers["Content-Type"] = t @@ -95,4 +94,4 @@ def upload_media(self, file: BinaryIO, fileType: str) -> str: cache.popitem(last=False) return cache[file_hash] - \ No newline at end of file +