feat: use jpg for system notifications

This commit is contained in:
Zamitto
2025-11-12 08:17:53 -03:00
parent f84917a00b
commit c2216bbf95
5 changed files with 17 additions and 12 deletions

View File

@@ -153,8 +153,11 @@ def profile_image():
data = request.get_json() data = request.get_json()
image_path = data.get('image_path') image_path = data.get('image_path')
# use webp as default value for target_extension
target_extension = data.get('target_extension') or 'webp'
try: try:
processed_image_path, mime_type = ProfileImageProcessor.process_image(image_path) processed_image_path, mime_type = ProfileImageProcessor.process_image(image_path, target_extension)
return jsonify({'imagePath': processed_image_path, 'mimeType': mime_type}), 200 return jsonify({'imagePath': processed_image_path, 'mimeType': mime_type}), 200
except Exception as e: except Exception as e:
return jsonify({"error": str(e)}), 400 return jsonify({"error": str(e)}), 400

View File

@@ -4,7 +4,7 @@ import os, uuid, tempfile
class ProfileImageProcessor: class ProfileImageProcessor:
@staticmethod @staticmethod
def get_parsed_image_data(image_path): def get_parsed_image_data(image_path, target_extension):
Image.MAX_IMAGE_PIXELS = 933120000 Image.MAX_IMAGE_PIXELS = 933120000
image = Image.open(image_path) image = Image.open(image_path)
@@ -16,7 +16,7 @@ class ProfileImageProcessor:
return image_path, mime_type return image_path, mime_type
else: else:
new_uuid = str(uuid.uuid4()) new_uuid = str(uuid.uuid4())
new_image_path = os.path.join(tempfile.gettempdir(), new_uuid) + ".webp" new_image_path = os.path.join(tempfile.gettempdir(), new_uuid) + "." + target_extension
image.save(new_image_path) image.save(new_image_path)
new_image = Image.open(new_image_path) new_image = Image.open(new_image_path)
@@ -26,5 +26,5 @@ class ProfileImageProcessor:
@staticmethod @staticmethod
def process_image(image_path): def process_image(image_path, target_extension):
return ProfileImageProcessor.get_parsed_image_data(image_path) return ProfileImageProcessor.get_parsed_image_data(image_path, target_extension)

View File

@@ -5,15 +5,15 @@ const processProfileImageEvent = async (
_event: Electron.IpcMainInvokeEvent, _event: Electron.IpcMainInvokeEvent,
path: string path: string
) => { ) => {
return processProfileImage(path); return processProfileImage(path, "webp");
}; };
export const processProfileImage = async (path: string) => { export const processProfileImage = async (path: string, extension?: string) => {
return PythonRPC.rpc return PythonRPC.rpc
.post<{ .post<{
imagePath: string; imagePath: string;
mimeType: string; mimeType: string;
}>("/profile-image", { image_path: path }) }>("/profile-image", { image_path: path, target_extension: extension })
.then((response) => response.data); .then((response) => response.data);
}; };

View File

@@ -18,7 +18,7 @@ import { getThemeSoundPath } from "@main/helpers";
import { processProfileImage } from "@main/events/profile/process-profile-image"; import { processProfileImage } from "@main/events/profile/process-profile-image";
const getStaticImage = async (path: string) => { const getStaticImage = async (path: string) => {
return processProfileImage(path) return processProfileImage(path, "jpg")
.then((response) => response.imagePath) .then((response) => response.imagePath)
.catch(() => path); .catch(() => path);
}; };

View File

@@ -8,9 +8,11 @@ export const friendRequestEvent = async (payload: FriendRequest) => {
friendRequestCount: payload.friendRequestCount, friendRequestCount: payload.friendRequestCount,
}); });
if (payload.senderId) {
const user = await HydraApi.get(`/users/${payload.senderId}`); const user = await HydraApi.get(`/users/${payload.senderId}`);
if (user) { if (user) {
publishNewFriendRequestNotification(user); publishNewFriendRequestNotification(user);
} }
}
}; };