Support new backend contracts: single-flight refresh, ad impression tokens, error handling

- apiFetch: proactive refresh, cross-tab single-flight via Web Locks, no logout on transient errors
- AuthContext: save tokens returned on own login change, revoke refresh on logout, sync tabs
- Ads: X-Session-Id, impressionToken in impression/click, IAB viewability, safe http(s) targetUrl
- STOMP: refresh before CONNECT, stop reconnect loop on dead session, /user/queue/errors behind flag
- Auth form: password 8 chars / 72 bytes; 429/413 messages via describeApiError
- My posts with auth + moderation badges; post form step validation and field limits
- Map: escape user text in Yandex hint/template

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SlimusMinus
2026-10-20 02:03:42 +03:00
parent 67de963d6d
commit db37befb8d
34 changed files with 1005 additions and 260 deletions

View File

@@ -1,7 +1,5 @@
import { useEffect, useRef, useState } from 'react';
import { API_URL } from '../config/authConstants';
import { getAccessToken } from '../api/apiClient';
import { normalizeMediaUrl } from '../api/adsApi';
import { getNextAd } from '../api/adsApi';
import AdCard from './AdCard';
export default function AdSlot() {
@@ -17,29 +15,20 @@ export default function AdSlot() {
if (!node) return;
let cancelled = false;
const controller = new AbortController();
const observer = new IntersectionObserver(
([entry]) => {
if (!entry.isIntersecting) return;
observer.disconnect();
const token = getAccessToken();
fetch(`${API_URL}/api/ads/next`, {
headers: token ? { Authorization: `Bearer ${token}` } : undefined,
})
.then((res) => {
// 204 No Content — свободных объявлений нет
if (res.status === 204) return null;
if (!res.ok) throw new Error(`Error ${res.status}`);
return res.json();
})
// Выдача — ещё не показ: показ засчитывается в AdCard, когда
// баннер реально виден (useAdViewability).
getNextAd(controller.signal)
.then((data) => {
if (cancelled) return;
if (!data) {
setEmpty(true);
return;
}
if (data.mediaUrl) data.mediaUrl = normalizeMediaUrl(data.mediaUrl);
setAd(data);
// null — 204 (нет кандидатов, лимит, пауза между показами) или 429
if (!data) setEmpty(true);
else setAd(data);
})
.catch(() => {
if (!cancelled) setEmpty(true);
@@ -51,6 +40,7 @@ export default function AdSlot() {
observer.observe(node);
return () => {
cancelled = true;
controller.abort();
observer.disconnect();
};
}, [closed]);