modify avatar url..
This commit is contained in:
+17
-2
@@ -23,12 +23,27 @@ export type InstructorChatThread = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const CHAT_API_BASE_URL = (import.meta.env.VITE_API_BASE_URL ?? 'https://workspace.autonomystudio.net/lms-api/api').replace(/\/+$/, '');
|
const CHAT_API_BASE_URL = (import.meta.env.VITE_API_BASE_URL ?? 'https://workspace.autonomystudio.net/lms-api/api').replace(/\/+$/, '');
|
||||||
|
const AUTH_BASE_URL = (import.meta.env.VITE_ATNMY_AUTH_URL ?? import.meta.env.VITE_ADS_IDE_AUTH_URL ?? 'https://auth.autonomystudio.net').replace(/\/+$/, '');
|
||||||
export const CHAT_SOCKET_BASE_URL = CHAT_API_BASE_URL.replace(/\/api$/, '');
|
export const CHAT_SOCKET_BASE_URL = CHAT_API_BASE_URL.replace(/\/api$/, '');
|
||||||
const CHAT_SOCKET_URL = new URL(CHAT_SOCKET_BASE_URL || '/', window.location.origin);
|
const CHAT_SOCKET_URL = new URL(CHAT_SOCKET_BASE_URL || '/', window.location.origin);
|
||||||
const CHAT_SOCKET_PREFIX = CHAT_SOCKET_URL.pathname.replace(/\/+$/, '');
|
const CHAT_SOCKET_PREFIX = CHAT_SOCKET_URL.pathname.replace(/\/+$/, '');
|
||||||
export const CHAT_SOCKET_ORIGIN = CHAT_SOCKET_URL.origin;
|
export const CHAT_SOCKET_ORIGIN = CHAT_SOCKET_URL.origin;
|
||||||
export const CHAT_SOCKET_PATH = `${CHAT_SOCKET_PREFIX}/socket.io`;
|
export const CHAT_SOCKET_PATH = `${CHAT_SOCKET_PREFIX}/socket.io`;
|
||||||
|
|
||||||
|
function normalizeAvatarUrl(value: unknown): string | null {
|
||||||
|
if (typeof value !== 'string' || !value.trim()) return null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const url = new URL(value);
|
||||||
|
if (url.hostname === 'studio-auth-be.studio-system.svc.cluster.local') {
|
||||||
|
return `${AUTH_BASE_URL}${url.pathname}${url.search}`;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
} catch {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type ChatThreadsPayload = {
|
type ChatThreadsPayload = {
|
||||||
threads?: unknown[];
|
threads?: unknown[];
|
||||||
data?: unknown[];
|
data?: unknown[];
|
||||||
@@ -108,7 +123,7 @@ function normalizeThread(raw: unknown): InstructorChatThread | null {
|
|||||||
id: String(item.id ?? item.threadId ?? title),
|
id: String(item.id ?? item.threadId ?? title),
|
||||||
title: String(title),
|
title: String(title),
|
||||||
studentName: String(studentName),
|
studentName: String(studentName),
|
||||||
studentAvatarUrl: typeof item.studentAvatarUrl === 'string' ? item.studentAvatarUrl : null,
|
studentAvatarUrl: normalizeAvatarUrl(item.studentAvatarUrl),
|
||||||
groupName: item.group?.name ?? item.groupName ?? item.metadata?.groupName,
|
groupName: item.group?.name ?? item.groupName ?? item.metadata?.groupName,
|
||||||
week: weekValue ?? item.weekId ?? item.metadata?.week,
|
week: weekValue ?? item.weekId ?? item.metadata?.week,
|
||||||
status: String(item.status ?? 'WAITING_INSTRUCTOR'),
|
status: String(item.status ?? 'WAITING_INSTRUCTOR'),
|
||||||
@@ -126,7 +141,7 @@ function normalizeMessage(raw: unknown): InstructorChatMessage | null {
|
|||||||
id: String(item.id ?? `${item.senderType ?? 'MESSAGE'}-${item.createdAt ?? item.content ?? 'unknown'}`),
|
id: String(item.id ?? `${item.senderType ?? 'MESSAGE'}-${item.createdAt ?? item.content ?? 'unknown'}`),
|
||||||
senderType: String(item.senderType ?? 'STUDENT'),
|
senderType: String(item.senderType ?? 'STUDENT'),
|
||||||
senderName: item.senderName ?? item.sender?.name,
|
senderName: item.senderName ?? item.sender?.name,
|
||||||
senderAvatarUrl: typeof item.senderAvatarUrl === 'string' ? item.senderAvatarUrl : null,
|
senderAvatarUrl: normalizeAvatarUrl(item.senderAvatarUrl),
|
||||||
content: String(item.content ?? ''),
|
content: String(item.content ?? ''),
|
||||||
createdAt: item.createdAt,
|
createdAt: item.createdAt,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user