diff --git a/backend/onyx/auth/email_utils.py b/backend/onyx/auth/email_utils.py index 8763115fd..b1eb54ca2 100644 --- a/backend/onyx/auth/email_utils.py +++ b/backend/onyx/auth/email_utils.py @@ -199,7 +199,7 @@ def send_subscription_cancellation_email(user_email: str) -> None: # Example usage of the reusable HTML try: load_runtime_settings_fn = fetch_versioned_implementation( - "ee.onyx.server.enterprise_settings.store", "load_runtime_settings" + "onyx.server.enterprise_settings.store", "load_runtime_settings" ) settings = load_runtime_settings_fn() application_name = settings.application_name @@ -208,7 +208,7 @@ def send_subscription_cancellation_email(user_email: str) -> None: with get_session_with_shared_schema() as db_session: get_onyx_file_store_fn = fetch_versioned_implementation( - "ee.onyx.file_store.onyx_file_store", "get_onyx_file_store" + "onyx.file_store.onyx_file_store", "get_onyx_file_store" ) file_store: OnyxFileStore = get_onyx_file_store_fn(db_session) onyx_file = file_store.get_logo() @@ -246,7 +246,7 @@ def send_user_email_invite( try: load_runtime_settings_fn = fetch_versioned_implementation( - "ee.onyx.server.enterprise_settings.store", "load_runtime_settings" + "onyx.server.enterprise_settings.store", "load_runtime_settings" ) settings = load_runtime_settings_fn() application_name = settings.application_name @@ -255,7 +255,7 @@ def send_user_email_invite( with get_session_with_shared_schema() as db_session: get_onyx_file_store_fn = fetch_versioned_implementation( - "ee.onyx.file_store.onyx_file_store", "get_onyx_file_store" + "onyx.file_store.onyx_file_store", "get_onyx_file_store" ) file_store: OnyxFileStore = get_onyx_file_store_fn(db_session) onyx_file = file_store.get_logo() @@ -323,7 +323,7 @@ def send_forgot_password_email( # Builds a forgot password email with or without fancy HTML try: load_runtime_settings_fn = fetch_versioned_implementation( - "ee.onyx.server.enterprise_settings.store", "load_runtime_settings" + "onyx.server.enterprise_settings.store", "load_runtime_settings" ) settings = load_runtime_settings_fn() application_name = settings.application_name @@ -332,7 +332,7 @@ def send_forgot_password_email( with get_session_with_shared_schema() as db_session: get_onyx_file_store_fn = fetch_versioned_implementation( - "ee.onyx.file_store.onyx_file_store", "get_onyx_file_store" + "onyx.file_store.onyx_file_store", "get_onyx_file_store" ) file_store: OnyxFileStore = get_onyx_file_store_fn(db_session) onyx_file = file_store.get_logo() @@ -361,7 +361,7 @@ def send_user_verification_email( # Builds a verification email try: load_runtime_settings_fn = fetch_versioned_implementation( - "ee.onyx.server.enterprise_settings.store", "load_runtime_settings" + "onyx.server.enterprise_settings.store", "load_runtime_settings" ) settings = load_runtime_settings_fn() application_name = settings.application_name @@ -370,7 +370,7 @@ def send_user_verification_email( with get_session_with_shared_schema() as db_session: get_onyx_file_store_fn = fetch_versioned_implementation( - "ee.onyx.file_store.onyx_file_store", "get_onyx_file_store" + "onyx.file_store.onyx_file_store", "get_onyx_file_store" ) file_store: OnyxFileStore = get_onyx_file_store_fn(db_session) onyx_file = file_store.get_logo() diff --git a/backend/onyx/file_store/onyx_file_store.py b/backend/onyx/file_store/onyx_file_store.py index 5d43c5092..01fcc707d 100644 --- a/backend/onyx/file_store/onyx_file_store.py +++ b/backend/onyx/file_store/onyx_file_store.py @@ -1,4 +1,6 @@ -import magic +from typing import cast + +import puremagic from onyx.file_store.file_store import PostgresBackedFileStore from onyx.utils.file import OnyxFile @@ -6,15 +8,22 @@ from onyx.utils.file import OnyxFile class OnyxFileStore(PostgresBackedFileStore): def get_static_image(self, filename: str) -> OnyxFile: - file_io = self.read_file(filename, mode="b") - file_content = file_io.read() - mime_type = magic.Magic(mime=True).from_buffer(file_content) + mime_type: str = "application/octet-stream" + with open(filename, "b") as f: + file_content = f.read() + matches = puremagic.magic_string(file_content) + if matches: + mime_type = cast(str, matches[0].mime_type) + return OnyxFile(data=file_content, mime_type=mime_type) def get_db_image(self, filename: str) -> OnyxFile: + mime_type: str = "application/octet-stream" file_io = self.read_file(filename, mode="b") file_content = file_io.read() - mime_type = magic.Magic(mime=True).from_buffer(file_content) + matches = puremagic.magic_string(file_content) + if matches: + mime_type = cast(str, matches[0].mime_type) return OnyxFile(data=file_content, mime_type=mime_type) def get_logo(self) -> OnyxFile: diff --git a/backend/requirements/default.txt b/backend/requirements/default.txt index 016d14c23..c08bc084a 100644 --- a/backend/requirements/default.txt +++ b/backend/requirements/default.txt @@ -52,6 +52,7 @@ openpyxl==3.1.2 playwright==1.41.2 psutil==5.9.5 psycopg2-binary==2.9.9 +puremagic==1.28 pyairtable==3.0.1 pycryptodome==3.19.1 pydantic==2.8.2