From c9b6e4adeb0e777956c6729e2cf860d2d6ab8a4c Mon Sep 17 00:00:00 2001 From: Drobysh Date: Wed, 23 Sep 2026 16:23:27 +0300 Subject: [PATCH] =?UTF-8?q?=E2=8F=AA=20=D0=9E=D1=82=D0=BA=D0=B0=D1=82:=20i?= =?UTF-8?q?nitData=20=D0=BE=D0=B1=D1=80=D0=B0=D1=82=D0=BD=D0=BE=20=D0=B2?= =?UTF-8?q?=20query=20(Cloudflare=20Free=20=D0=B1=D0=BB=D0=BE=D0=BA=D0=B8?= =?UTF-8?q?=D1=80=D1=83=D0=B5=D1=82=20Authorization)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Причина: Cloudflare Free для api.filwordspl.com подменяет preflight-ответ на 1728000 / Content-Type, не пропуская Authorization. Workers Routes, Page Rules, Transform Rules — пусто. DNS правильный, Tunnel нет. Похоже на недокументированное поведение Cloudflare Free для preflight. Бэк (auth.py) принимает оба способа (Authorization + query) — регрессии нет. Бонус: TTS_VOICE_NOT_ENCODED фикс сохранён. ADMIN_FLAG_FROM_LOCALSTORAGE (MenuPage.tsx) — тоже остался. TODO: вернуть Authorization через Cloudflare Worker или DNS only. --- src/api.ts | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/src/api.ts b/src/api.ts index 5155d4d..0e7a95d 100644 --- a/src/api.ts +++ b/src/api.ts @@ -5,17 +5,15 @@ const API_BASE = 'https://api.filwordspl.com'; const fetchAPI = async (endpoint: string, options: RequestInit = {}) => { const initData = getInitData(); - // 🔧 ФИКС (23.09.2026): INIT_DATA_IN_URL — initData теперь в заголовке Authorization, - // а не в query-строке. Токен больше не попадает в логи сервера, Referer, - // историю браузера и кеш Cloudflare. - // Формат "tma " — стандарт Telegram Mini Apps. - const url = `${API_BASE}${endpoint}`; + // 🔧 ОТКАТ (23.09.2026): временно возвращаем initData в query — + // Cloudflare Free блокирует Authorization в preflight (1728000/Content-Type). + // TODO: вернуть Authorization, когда разберёмся с Cloudflare. + const url = `${API_BASE}${endpoint}${endpoint.includes('?') ? '&' : '?'}initData=${encodeURIComponent(initData)}`; const res = await fetch(url, { ...options, headers: { 'Content-Type': 'application/json', - 'Authorization': `tma ${initData}`, ...options.headers, }, }); @@ -176,15 +174,12 @@ export const getNextPronunciationWord = () => export const getTTS = (text: string, voice: string = 'female'): Promise => { const initData = getInitData(); - // 🔧 ФИКС (23.09.2026): INIT_DATA_IN_URL — initData в заголовке. - // Заодно: voice теперь кодируется через encodeURIComponent (TTS_VOICE_NOT_ENCODED). - const url = `${API_BASE}/tts?text=${encodeURIComponent(text)}&voice=${encodeURIComponent(voice)}`; + // 🔧 ОТКАТ (23.09.2026): initData обратно в query (см. fetchAPI). + // voice всё ещё кодируется через encodeURIComponent (TTS_VOICE_NOT_ENCODED оставляем). + const url = `${API_BASE}/tts?text=${encodeURIComponent(text)}&voice=${encodeURIComponent(voice)}&initData=${encodeURIComponent(initData)}`; return fetch(url, { method: 'GET', - headers: { - 'Authorization': `tma ${initData}`, - }, }).then(async (res) => { if (!res.ok) { const errorText = await res.text(); @@ -703,10 +698,9 @@ export const translateFeedPreview = (payload: { * Blob в FormData и отправляем — WebView его не «съест», потому что это * уже in-memory объект. * - * 🔧 ФИКС (23.09.2026): INIT_DATA_IN_URL — initData в заголовке. - * Content-Type НЕ ставим — браузер сам добавит multipart/form-data + boundary. - * Authorization — не simple header, preflight полетит, но Cloudflare его не кеширует - * для admin-эндпоинтов (проверено). + * 🔧 ОТКАТ (23.09.2026): initData обратно в query, потому что с Authorization- + * заголовком полетит preflight, который Cloudflare Free блокирует (1728000). + * См. общий откат в fetchAPI. * * @param postId ID поста, к которому привязать картинку * @param blob Готовый Blob с байтами (создан из arrayBuffer() в UI) @@ -724,7 +718,7 @@ export const uploadFeedImage = async ( order_number: number; }> => { const initData = getInitData(); - const url = `${API_BASE}/admin/feed/upload-image`; + const url = `${API_BASE}/admin/feed/upload-image?initData=${encodeURIComponent(initData)}`; // Определяем имя с правильным расширением const extFromType = (mimeType || 'image/jpeg').split('/')[1] || 'jpg'; @@ -737,9 +731,6 @@ export const uploadFeedImage = async ( const res = await fetch(url, { method: 'POST', - headers: { - 'Authorization': `tma ${initData}`, - }, body: formData, // ❌ НЕ ставим Content-Type — браузер сам поставит multipart/form-data + boundary });