fix and update
This commit is contained in:
4
apps/frontend/app/icon.svg
Normal file
4
apps/frontend/app/icon.svg
Normal file
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
|
||||
<rect width="64" height="64" rx="18" fill="#111827"/>
|
||||
<path d="M18 45V19h7l7 12 7-12h7v26h-7V31.5L34.8 38h-5.6L25 31.5V45h-7z" fill="#fff"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 213 B |
@@ -4,13 +4,18 @@ import './globals.css';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: 'MVK ID',
|
||||
description: 'Единый аккаунт для сервисов Lendry'
|
||||
description: 'Единый аккаунт для сервисов Lendry',
|
||||
icons: {
|
||||
icon: '/icon.svg',
|
||||
shortcut: '/icon.svg',
|
||||
apple: '/icon.svg'
|
||||
}
|
||||
};
|
||||
|
||||
export default function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) {
|
||||
return (
|
||||
<html lang="ru">
|
||||
<body>
|
||||
<html lang="ru" suppressHydrationWarning>
|
||||
<body suppressHydrationWarning>
|
||||
<Providers>{children}</Providers>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -4,6 +4,7 @@ import * as React from 'react';
|
||||
import { Loader2, Trash2 } from 'lucide-react';
|
||||
import { useAuth } from '@/components/id/auth-provider';
|
||||
import { fetchDocumentPhotoUrl } from '@/lib/api';
|
||||
import { resolveBrowserMediaUrl } from '@/lib/resilient-media-fetch';
|
||||
import { DocumentFullscreenViewer, DocumentPhotoThumbnail } from './document-photo-viewer';
|
||||
|
||||
interface DocumentPhotoGalleryProps {
|
||||
@@ -33,7 +34,7 @@ export function DocumentPhotoGallery({ userId, token, storageKeys, readOnly, onR
|
||||
storageKeys.map(async (storageKey) => {
|
||||
try {
|
||||
const response = await fetchDocumentPhotoUrl(userId, storageKey, token);
|
||||
return { storageKey, accessUrl: response.accessUrl };
|
||||
return { storageKey, accessUrl: resolveBrowserMediaUrl(response.accessUrl) };
|
||||
} catch {
|
||||
return { storageKey, accessUrl: '' };
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ import { useAuth } from '@/components/id/auth-provider';
|
||||
import { ensureApiGatewayReady, fetchUnreadNotificationCount, getWsUrl, type ChatMessage } from '@/lib/api';
|
||||
import { dispatchAvatarUpdated, dispatchChatRoomAvatarUpdated } from '@/lib/avatar-events';
|
||||
|
||||
const WS_RECONNECT_BASE_MS = 2_000;
|
||||
const WS_RECONNECT_MAX_MS = 30_000;
|
||||
|
||||
export interface RealtimeEvent {
|
||||
userId?: string;
|
||||
type: string;
|
||||
@@ -37,6 +40,7 @@ export function RealtimeProvider({ children }: { children: React.ReactNode }) {
|
||||
const listenersRef = React.useRef(new Set<Listener>());
|
||||
const socketRef = React.useRef<WebSocket | null>(null);
|
||||
const reconnectTimer = React.useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
const reconnectAttemptRef = React.useRef(0);
|
||||
|
||||
const subscribe = React.useCallback((listener: Listener) => {
|
||||
listenersRef.current.add(listener);
|
||||
@@ -76,24 +80,35 @@ export function RealtimeProvider({ children }: { children: React.ReactNode }) {
|
||||
|
||||
let cancelled = false;
|
||||
|
||||
function scheduleReconnect() {
|
||||
if (cancelled) return;
|
||||
if (reconnectTimer.current) clearTimeout(reconnectTimer.current);
|
||||
const attempt = reconnectAttemptRef.current;
|
||||
const delay = Math.min(WS_RECONNECT_MAX_MS, WS_RECONNECT_BASE_MS * 2 ** Math.min(attempt, 4));
|
||||
reconnectAttemptRef.current = attempt + 1;
|
||||
reconnectTimer.current = setTimeout(connect, delay);
|
||||
}
|
||||
|
||||
async function connect() {
|
||||
if (cancelled) return;
|
||||
try {
|
||||
await ensureApiGatewayReady();
|
||||
} catch {
|
||||
// Пробуем подключиться даже если health не ответил в срок.
|
||||
scheduleReconnect();
|
||||
return;
|
||||
}
|
||||
if (cancelled) return;
|
||||
const url = `${getWsUrl()}?token=${encodeURIComponent(token!)}`;
|
||||
const socket = new WebSocket(url);
|
||||
socketRef.current = socket;
|
||||
|
||||
socket.onopen = () => setConnected(true);
|
||||
socket.onopen = () => {
|
||||
reconnectAttemptRef.current = 0;
|
||||
setConnected(true);
|
||||
};
|
||||
socket.onclose = () => {
|
||||
setConnected(false);
|
||||
if (!cancelled) {
|
||||
reconnectTimer.current = setTimeout(connect, 3000);
|
||||
}
|
||||
scheduleReconnect();
|
||||
};
|
||||
socket.onerror = () => socket.close();
|
||||
socket.onmessage = (event) => {
|
||||
@@ -136,6 +151,7 @@ export function RealtimeProvider({ children }: { children: React.ReactNode }) {
|
||||
return () => {
|
||||
cancelled = true;
|
||||
if (reconnectTimer.current) clearTimeout(reconnectTimer.current);
|
||||
reconnectAttemptRef.current = 0;
|
||||
socketRef.current?.close();
|
||||
socketRef.current = null;
|
||||
setConnected(false);
|
||||
|
||||
@@ -3,6 +3,8 @@ import { ensureApiGatewayReady } from '@/lib/api';
|
||||
const GATEWAY_RETRY_STATUS = new Set([502, 503, 504]);
|
||||
const MEDIA_FETCH_MAX_ATTEMPTS = 8;
|
||||
const MEDIA_SLOW_LOAD_WARN_MS = 8_000;
|
||||
const MEDIA_STREAM_PATH = '/media/stream/';
|
||||
const SAME_ORIGIN_API_PREFIX = '/idp-api';
|
||||
|
||||
function sleep(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
@@ -14,6 +16,23 @@ function warnSlowMediaLoad(label: string, startedAt: number, error: unknown) {
|
||||
console.warn(`[media] ${label}: не удалось загрузить за ${Math.round((Date.now() - startedAt) / 1000)} с (${detail})`);
|
||||
}
|
||||
|
||||
export function resolveBrowserMediaUrl(accessUrl: string): string {
|
||||
if (typeof window === 'undefined') return accessUrl;
|
||||
|
||||
try {
|
||||
const url = new URL(accessUrl, window.location.origin);
|
||||
const streamIndex = url.pathname.indexOf(MEDIA_STREAM_PATH);
|
||||
if (streamIndex === -1) {
|
||||
return accessUrl;
|
||||
}
|
||||
|
||||
const streamPath = url.pathname.slice(streamIndex);
|
||||
return `${window.location.origin}${SAME_ORIGIN_API_PREFIX}${streamPath}${url.search}`;
|
||||
} catch {
|
||||
return accessUrl;
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchMediaBlobWithRetry(
|
||||
accessUrl: string,
|
||||
token: string,
|
||||
@@ -21,12 +40,13 @@ export async function fetchMediaBlobWithRetry(
|
||||
): Promise<Blob> {
|
||||
const startedAt = Date.now();
|
||||
const label = options?.label ?? 'изображение';
|
||||
const mediaUrl = resolveBrowserMediaUrl(accessUrl);
|
||||
let lastError: unknown;
|
||||
|
||||
for (let attempt = 0; attempt < MEDIA_FETCH_MAX_ATTEMPTS; attempt += 1) {
|
||||
try {
|
||||
await ensureApiGatewayReady();
|
||||
const response = await fetch(accessUrl, {
|
||||
const response = await fetch(mediaUrl, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
cache: 'no-store'
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user