⏪ Откат: initData обратно в query (Cloudflare Free блокирует Authorization)
Причина: 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.
This commit is contained in:
+11
-20
@@ -5,17 +5,15 @@ const API_BASE = 'https://api.filwordspl.com';
|
|||||||
const fetchAPI = async (endpoint: string, options: RequestInit = {}) => {
|
const fetchAPI = async (endpoint: string, options: RequestInit = {}) => {
|
||||||
const initData = getInitData();
|
const initData = getInitData();
|
||||||
|
|
||||||
// 🔧 ФИКС (23.09.2026): INIT_DATA_IN_URL — initData теперь в заголовке Authorization,
|
// 🔧 ОТКАТ (23.09.2026): временно возвращаем initData в query —
|
||||||
// а не в query-строке. Токен больше не попадает в логи сервера, Referer,
|
// Cloudflare Free блокирует Authorization в preflight (1728000/Content-Type).
|
||||||
// историю браузера и кеш Cloudflare.
|
// TODO: вернуть Authorization, когда разберёмся с Cloudflare.
|
||||||
// Формат "tma <initData>" — стандарт Telegram Mini Apps.
|
const url = `${API_BASE}${endpoint}${endpoint.includes('?') ? '&' : '?'}initData=${encodeURIComponent(initData)}`;
|
||||||
const url = `${API_BASE}${endpoint}`;
|
|
||||||
|
|
||||||
const res = await fetch(url, {
|
const res = await fetch(url, {
|
||||||
...options,
|
...options,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': `tma ${initData}`,
|
|
||||||
...options.headers,
|
...options.headers,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -176,15 +174,12 @@ export const getNextPronunciationWord = () =>
|
|||||||
export const getTTS = (text: string, voice: string = 'female'): Promise<Blob> => {
|
export const getTTS = (text: string, voice: string = 'female'): Promise<Blob> => {
|
||||||
const initData = getInitData();
|
const initData = getInitData();
|
||||||
|
|
||||||
// 🔧 ФИКС (23.09.2026): INIT_DATA_IN_URL — initData в заголовке.
|
// 🔧 ОТКАТ (23.09.2026): initData обратно в query (см. fetchAPI).
|
||||||
// Заодно: voice теперь кодируется через encodeURIComponent (TTS_VOICE_NOT_ENCODED).
|
// voice всё ещё кодируется через encodeURIComponent (TTS_VOICE_NOT_ENCODED оставляем).
|
||||||
const url = `${API_BASE}/tts?text=${encodeURIComponent(text)}&voice=${encodeURIComponent(voice)}`;
|
const url = `${API_BASE}/tts?text=${encodeURIComponent(text)}&voice=${encodeURIComponent(voice)}&initData=${encodeURIComponent(initData)}`;
|
||||||
|
|
||||||
return fetch(url, {
|
return fetch(url, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
|
||||||
'Authorization': `tma ${initData}`,
|
|
||||||
},
|
|
||||||
}).then(async (res) => {
|
}).then(async (res) => {
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
const errorText = await res.text();
|
const errorText = await res.text();
|
||||||
@@ -703,10 +698,9 @@ export const translateFeedPreview = (payload: {
|
|||||||
* Blob в FormData и отправляем — WebView его не «съест», потому что это
|
* Blob в FormData и отправляем — WebView его не «съест», потому что это
|
||||||
* уже in-memory объект.
|
* уже in-memory объект.
|
||||||
*
|
*
|
||||||
* 🔧 ФИКС (23.09.2026): INIT_DATA_IN_URL — initData в заголовке.
|
* 🔧 ОТКАТ (23.09.2026): initData обратно в query, потому что с Authorization-
|
||||||
* Content-Type НЕ ставим — браузер сам добавит multipart/form-data + boundary.
|
* заголовком полетит preflight, который Cloudflare Free блокирует (1728000).
|
||||||
* Authorization — не simple header, preflight полетит, но Cloudflare его не кеширует
|
* См. общий откат в fetchAPI.
|
||||||
* для admin-эндпоинтов (проверено).
|
|
||||||
*
|
*
|
||||||
* @param postId ID поста, к которому привязать картинку
|
* @param postId ID поста, к которому привязать картинку
|
||||||
* @param blob Готовый Blob с байтами (создан из arrayBuffer() в UI)
|
* @param blob Готовый Blob с байтами (создан из arrayBuffer() в UI)
|
||||||
@@ -724,7 +718,7 @@ export const uploadFeedImage = async (
|
|||||||
order_number: number;
|
order_number: number;
|
||||||
}> => {
|
}> => {
|
||||||
const initData = getInitData();
|
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';
|
const extFromType = (mimeType || 'image/jpeg').split('/')[1] || 'jpg';
|
||||||
@@ -737,9 +731,6 @@ export const uploadFeedImage = async (
|
|||||||
|
|
||||||
const res = await fetch(url, {
|
const res = await fetch(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
|
||||||
'Authorization': `tma ${initData}`,
|
|
||||||
},
|
|
||||||
body: formData,
|
body: formData,
|
||||||
// ❌ НЕ ставим Content-Type — браузер сам поставит multipart/form-data + boundary
|
// ❌ НЕ ставим Content-Type — браузер сам поставит multipart/form-data + boundary
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user