After correcting the chat issue2
This commit is contained in:
parent
f25d004007
commit
66a5ac6050
@ -175,6 +175,8 @@ export async function getAttachment(req: AuthRequest, res: Response): Promise<vo
|
||||
res.status(404).json({ error: 'File not found' });
|
||||
return;
|
||||
}
|
||||
// Helmet defaults to CORP same-origin; the web app is on another port/origin.
|
||||
res.setHeader('Cross-Origin-Resource-Policy', 'cross-origin');
|
||||
res.sendFile(filePath);
|
||||
} catch (e) {
|
||||
handleError(res, e);
|
||||
|
||||
@ -44,7 +44,17 @@ class SupportMessageModel {
|
||||
final String? readAt;
|
||||
|
||||
bool get isMine => 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(
|
||||
|
||||
@ -85,8 +85,20 @@ class SupportRepository {
|
||||
|
||||
Future<SupportMessageModel> 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'
|
||||
|
||||
@ -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}
|
||||
</Typography>
|
||||
)}
|
||||
{msg.attachmentUrl && (
|
||||
<Typography
|
||||
component="a"
|
||||
href={attachmentFullUrl(msg.attachmentUrl)}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
variant="body2"
|
||||
sx={{ display: 'block', mt: 0.5 }}
|
||||
>
|
||||
📎 {msg.attachmentName}
|
||||
</Typography>
|
||||
)}
|
||||
{msg.attachmentUrl &&
|
||||
(isSupportImage(msg) ? (
|
||||
<Box
|
||||
component="a"
|
||||
href={attachmentFullUrl(msg.attachmentUrl)}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
sx={{ display: 'block', mt: msg.body ? 0.5 : 0 }}
|
||||
>
|
||||
<Box
|
||||
component="img"
|
||||
src={attachmentFullUrl(msg.attachmentUrl)}
|
||||
alt={msg.attachmentName ?? t('admin.supportAdmin.visitor')}
|
||||
sx={{
|
||||
maxWidth: '100%',
|
||||
maxHeight: 280,
|
||||
borderRadius: 1.5,
|
||||
display: 'block',
|
||||
}}
|
||||
/>
|
||||
</Box>
|
||||
) : (
|
||||
<Typography
|
||||
component="a"
|
||||
href={attachmentFullUrl(msg.attachmentUrl)}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
variant="body2"
|
||||
sx={{ display: 'block', mt: 0.5 }}
|
||||
>
|
||||
📎 {msg.attachmentName}
|
||||
</Typography>
|
||||
))}
|
||||
<Typography variant="caption" sx={{ opacity: 0.6, display: 'block', textAlign: 'right' }}>
|
||||
{new Date(msg.createdAt).toLocaleString()}
|
||||
{msg.readAt ? t('admin.supportAdmin.read') : ''}
|
||||
|
||||
@ -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 ?? '');
|
||||
}
|
||||
|
||||
@ -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 (
|
||||
<Box
|
||||
sx={{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user