diff --git a/backend/src/controllers/supportController.ts b/backend/src/controllers/supportController.ts index 71cdde3d..983bc6c5 100644 --- a/backend/src/controllers/supportController.ts +++ b/backend/src/controllers/supportController.ts @@ -175,6 +175,8 @@ export async function getAttachment(req: AuthRequest, res: Response): Promise senderType == 'user' || senderType == 'visitor'; - bool get isImage => attachmentMime?.startsWith('image/') == true; + bool get isImage { + if (attachmentMime?.startsWith('image/') == true) return true; + final name = (attachmentName ?? attachmentUrl ?? '').toLowerCase(); + return name.endsWith('.jpg') || + name.endsWith('.jpeg') || + name.endsWith('.png') || + name.endsWith('.gif') || + name.endsWith('.webp') || + name.endsWith('.heic') || + name.endsWith('.bmp'); + } SupportMessageModel copyWith({String? readAt}) { return SupportMessageModel( diff --git a/prediqo_mobile/lib/data/repositories/support_repository.dart b/prediqo_mobile/lib/data/repositories/support_repository.dart index fd0c706c..4f47fcb9 100644 --- a/prediqo_mobile/lib/data/repositories/support_repository.dart +++ b/prediqo_mobile/lib/data/repositories/support_repository.dart @@ -85,8 +85,20 @@ class SupportRepository { Future sendImage(String? conversationId, String filePath) async { try { + final name = filePath.replaceAll('\\', '/').split('/').last; + final ext = name.contains('.') ? name.split('.').last.toLowerCase() : 'jpg'; + final mimeSubtype = switch (ext) { + 'png' => 'png', + 'gif' => 'gif', + 'webp' => 'webp', + _ => 'jpeg', + }; final form = FormData.fromMap({ - 'file': await MultipartFile.fromFile(filePath), + 'file': await MultipartFile.fromFile( + filePath, + filename: name, + contentType: DioMediaType('image', mimeSubtype), + ), }); final uploadPath = conversationId == null || conversationId.isEmpty ? '/api/v1/support/conversations/current/upload' diff --git a/prediqo_web/src/features/support/SupportAdminPage.tsx b/prediqo_web/src/features/support/SupportAdminPage.tsx index d0e34b0d..356fb4cc 100644 --- a/prediqo_web/src/features/support/SupportAdminPage.tsx +++ b/prediqo_web/src/features/support/SupportAdminPage.tsx @@ -35,6 +35,7 @@ import { adminUpdateConversation, adminUploadFile, attachmentFullUrl, + isSupportImage, } from './api/supportApi'; import { useSupportSocket } from './hooks/useSupportSocket'; import { notifySupportMessage, requestSupportNotificationPermission } from './utils/notifications'; @@ -84,18 +85,39 @@ function AdminMessageList({ {msg.body} )} - {msg.attachmentUrl && ( - - 📎 {msg.attachmentName} - - )} + {msg.attachmentUrl && + (isSupportImage(msg) ? ( + + + + ) : ( + + 📎 {msg.attachmentName} + + ))} {new Date(msg.createdAt).toLocaleString()} {msg.readAt ? t('admin.supportAdmin.read') : ''} diff --git a/prediqo_web/src/features/support/api/supportApi.ts b/prediqo_web/src/features/support/api/supportApi.ts index 280b429b..0e787b18 100644 --- a/prediqo_web/src/features/support/api/supportApi.ts +++ b/prediqo_web/src/features/support/api/supportApi.ts @@ -182,3 +182,14 @@ export function attachmentFullUrl(relativeUrl: string): string { if (relativeUrl.startsWith('http')) return relativeUrl; return `${base.replace(/\/$/, '')}${relativeUrl}`; } + +const IMAGE_EXT = /\.(jpe?g|png|gif|webp|bmp|heic)$/i; + +export function isSupportImage(msg: { + attachmentMime?: string | null; + attachmentName?: string | null; + attachmentUrl?: string | null; +}): boolean { + if (msg.attachmentMime?.startsWith('image/')) return true; + return IMAGE_EXT.test(msg.attachmentName ?? '') || IMAGE_EXT.test(msg.attachmentUrl ?? ''); +} diff --git a/prediqo_web/src/features/support/components/SupportChatPanel.tsx b/prediqo_web/src/features/support/components/SupportChatPanel.tsx index 65c838c3..3aab1cc1 100644 --- a/prediqo_web/src/features/support/components/SupportChatPanel.tsx +++ b/prediqo_web/src/features/support/components/SupportChatPanel.tsx @@ -17,6 +17,7 @@ import { useCallback, useEffect, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { attachmentFullUrl, + isSupportImage, fetchCurrentConversation, fetchMessages, sendSupportAttachmentMessage, @@ -60,7 +61,7 @@ function MessageBubble({ isMine: boolean; t: (key: string) => string; }) { - const isImage = msg.attachmentMime?.startsWith('image/'); + const isImage = isSupportImage(msg); return (