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 = {
|
export const metadata: Metadata = {
|
||||||
title: 'MVK ID',
|
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 }>) {
|
export default function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) {
|
||||||
return (
|
return (
|
||||||
<html lang="ru">
|
<html lang="ru" suppressHydrationWarning>
|
||||||
<body>
|
<body suppressHydrationWarning>
|
||||||
<Providers>{children}</Providers>
|
<Providers>{children}</Providers>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import * as React from 'react';
|
|||||||
import { Loader2, Trash2 } from 'lucide-react';
|
import { Loader2, Trash2 } from 'lucide-react';
|
||||||
import { useAuth } from '@/components/id/auth-provider';
|
import { useAuth } from '@/components/id/auth-provider';
|
||||||
import { fetchDocumentPhotoUrl } from '@/lib/api';
|
import { fetchDocumentPhotoUrl } from '@/lib/api';
|
||||||
|
import { resolveBrowserMediaUrl } from '@/lib/resilient-media-fetch';
|
||||||
import { DocumentFullscreenViewer, DocumentPhotoThumbnail } from './document-photo-viewer';
|
import { DocumentFullscreenViewer, DocumentPhotoThumbnail } from './document-photo-viewer';
|
||||||
|
|
||||||
interface DocumentPhotoGalleryProps {
|
interface DocumentPhotoGalleryProps {
|
||||||
@@ -33,7 +34,7 @@ export function DocumentPhotoGallery({ userId, token, storageKeys, readOnly, onR
|
|||||||
storageKeys.map(async (storageKey) => {
|
storageKeys.map(async (storageKey) => {
|
||||||
try {
|
try {
|
||||||
const response = await fetchDocumentPhotoUrl(userId, storageKey, token);
|
const response = await fetchDocumentPhotoUrl(userId, storageKey, token);
|
||||||
return { storageKey, accessUrl: response.accessUrl };
|
return { storageKey, accessUrl: resolveBrowserMediaUrl(response.accessUrl) };
|
||||||
} catch {
|
} catch {
|
||||||
return { storageKey, accessUrl: '' };
|
return { storageKey, accessUrl: '' };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ import { useAuth } from '@/components/id/auth-provider';
|
|||||||
import { ensureApiGatewayReady, fetchUnreadNotificationCount, getWsUrl, type ChatMessage } from '@/lib/api';
|
import { ensureApiGatewayReady, fetchUnreadNotificationCount, getWsUrl, type ChatMessage } from '@/lib/api';
|
||||||
import { dispatchAvatarUpdated, dispatchChatRoomAvatarUpdated } from '@/lib/avatar-events';
|
import { dispatchAvatarUpdated, dispatchChatRoomAvatarUpdated } from '@/lib/avatar-events';
|
||||||
|
|
||||||
|
const WS_RECONNECT_BASE_MS = 2_000;
|
||||||
|
const WS_RECONNECT_MAX_MS = 30_000;
|
||||||
|
|
||||||
export interface RealtimeEvent {
|
export interface RealtimeEvent {
|
||||||
userId?: string;
|
userId?: string;
|
||||||
type: string;
|
type: string;
|
||||||
@@ -37,6 +40,7 @@ export function RealtimeProvider({ children }: { children: React.ReactNode }) {
|
|||||||
const listenersRef = React.useRef(new Set<Listener>());
|
const listenersRef = React.useRef(new Set<Listener>());
|
||||||
const socketRef = React.useRef<WebSocket | null>(null);
|
const socketRef = React.useRef<WebSocket | null>(null);
|
||||||
const reconnectTimer = React.useRef<ReturnType<typeof setTimeout> | null>(null);
|
const reconnectTimer = React.useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||||
|
const reconnectAttemptRef = React.useRef(0);
|
||||||
|
|
||||||
const subscribe = React.useCallback((listener: Listener) => {
|
const subscribe = React.useCallback((listener: Listener) => {
|
||||||
listenersRef.current.add(listener);
|
listenersRef.current.add(listener);
|
||||||
@@ -76,24 +80,35 @@ export function RealtimeProvider({ children }: { children: React.ReactNode }) {
|
|||||||
|
|
||||||
let cancelled = false;
|
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() {
|
async function connect() {
|
||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
try {
|
try {
|
||||||
await ensureApiGatewayReady();
|
await ensureApiGatewayReady();
|
||||||
} catch {
|
} catch {
|
||||||
// Пробуем подключиться даже если health не ответил в срок.
|
scheduleReconnect();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
const url = `${getWsUrl()}?token=${encodeURIComponent(token!)}`;
|
const url = `${getWsUrl()}?token=${encodeURIComponent(token!)}`;
|
||||||
const socket = new WebSocket(url);
|
const socket = new WebSocket(url);
|
||||||
socketRef.current = socket;
|
socketRef.current = socket;
|
||||||
|
|
||||||
socket.onopen = () => setConnected(true);
|
socket.onopen = () => {
|
||||||
|
reconnectAttemptRef.current = 0;
|
||||||
|
setConnected(true);
|
||||||
|
};
|
||||||
socket.onclose = () => {
|
socket.onclose = () => {
|
||||||
setConnected(false);
|
setConnected(false);
|
||||||
if (!cancelled) {
|
scheduleReconnect();
|
||||||
reconnectTimer.current = setTimeout(connect, 3000);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
socket.onerror = () => socket.close();
|
socket.onerror = () => socket.close();
|
||||||
socket.onmessage = (event) => {
|
socket.onmessage = (event) => {
|
||||||
@@ -136,6 +151,7 @@ export function RealtimeProvider({ children }: { children: React.ReactNode }) {
|
|||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
if (reconnectTimer.current) clearTimeout(reconnectTimer.current);
|
if (reconnectTimer.current) clearTimeout(reconnectTimer.current);
|
||||||
|
reconnectAttemptRef.current = 0;
|
||||||
socketRef.current?.close();
|
socketRef.current?.close();
|
||||||
socketRef.current = null;
|
socketRef.current = null;
|
||||||
setConnected(false);
|
setConnected(false);
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import { ensureApiGatewayReady } from '@/lib/api';
|
|||||||
const GATEWAY_RETRY_STATUS = new Set([502, 503, 504]);
|
const GATEWAY_RETRY_STATUS = new Set([502, 503, 504]);
|
||||||
const MEDIA_FETCH_MAX_ATTEMPTS = 8;
|
const MEDIA_FETCH_MAX_ATTEMPTS = 8;
|
||||||
const MEDIA_SLOW_LOAD_WARN_MS = 8_000;
|
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> {
|
function sleep(ms: number): Promise<void> {
|
||||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
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})`);
|
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(
|
export async function fetchMediaBlobWithRetry(
|
||||||
accessUrl: string,
|
accessUrl: string,
|
||||||
token: string,
|
token: string,
|
||||||
@@ -21,12 +40,13 @@ export async function fetchMediaBlobWithRetry(
|
|||||||
): Promise<Blob> {
|
): Promise<Blob> {
|
||||||
const startedAt = Date.now();
|
const startedAt = Date.now();
|
||||||
const label = options?.label ?? 'изображение';
|
const label = options?.label ?? 'изображение';
|
||||||
|
const mediaUrl = resolveBrowserMediaUrl(accessUrl);
|
||||||
let lastError: unknown;
|
let lastError: unknown;
|
||||||
|
|
||||||
for (let attempt = 0; attempt < MEDIA_FETCH_MAX_ATTEMPTS; attempt += 1) {
|
for (let attempt = 0; attempt < MEDIA_FETCH_MAX_ATTEMPTS; attempt += 1) {
|
||||||
try {
|
try {
|
||||||
await ensureApiGatewayReady();
|
await ensureApiGatewayReady();
|
||||||
const response = await fetch(accessUrl, {
|
const response = await fetch(mediaUrl, {
|
||||||
headers: { Authorization: `Bearer ${token}` },
|
headers: { Authorization: `Bearer ${token}` },
|
||||||
cache: 'no-store'
|
cache: 'no-store'
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2177,7 +2177,7 @@ render_proxy_idp_ws() {
|
|||||||
local up
|
local up
|
||||||
up="$(nginx_upstream ws)"
|
up="$(nginx_upstream ws)"
|
||||||
if [[ "$NGINX_MODE" == "docker" ]]; then
|
if [[ "$NGINX_MODE" == "docker" ]]; then
|
||||||
printf ' set $idp_up_ws %s;\n rewrite ^/idp-api/ws/?(.*)$ /ws/$1 break;\n proxy_pass $idp_up_ws;' "$up"
|
printf ' set $idp_up_ws %s;\n rewrite ^/idp-api/ws$ /ws break;\n rewrite ^/idp-api/ws/(.*)$ /ws/$1 break;\n proxy_pass $idp_up_ws;' "$up"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
printf ' proxy_pass %s/ws;' "$up"
|
printf ' proxy_pass %s/ws;' "$up"
|
||||||
|
|||||||
Reference in New Issue
Block a user