справлена проблема с проксированием изображений: добавлена функция normalizeImageUrl для преобразования URL с IP-адресами в URL с доменом
This commit is contained in:
parent
8ece58d7d9
commit
8f31c6371b
71
src/assets/index.ts
Normal file
71
src/assets/index.ts
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
import ahareBot from './ahare_bot250.png';
|
||||||
|
import faq from './faq250.png';
|
||||||
|
import shorts from './shorts250.png';
|
||||||
|
import balerina from './balerina250x.png';
|
||||||
|
import emotions from './emotions_promo250x.png';
|
||||||
|
import realism from './realism_promo250x.png';
|
||||||
|
import prompt from './prompt.png';
|
||||||
|
import onboard1 from './onboard1.png';
|
||||||
|
import santa from './250x_santa.png';
|
||||||
|
import balloon from './balloon250x.png';
|
||||||
|
import bicycle from './bicecle250x.png';
|
||||||
|
import book from './book250x.png';
|
||||||
|
import cocktail from './coctail250x.png';
|
||||||
|
import coffee from './coffee250x.png';
|
||||||
|
import cook from './cook250x.png';
|
||||||
|
import cowboy from './cowboy250x.png';
|
||||||
|
import detective from './detektiv250x.png';
|
||||||
|
import dog from './dog250x.png';
|
||||||
|
import fairy from './fairy250x.png';
|
||||||
|
import fire from './fire250x.png';
|
||||||
|
import flowers from './flowers250x.png';
|
||||||
|
import gift from './gift250x.png';
|
||||||
|
import icecream from './icecream250x.png';
|
||||||
|
import knight from './knight250x.png';
|
||||||
|
import moto from './moto250x.png';
|
||||||
|
import newspaper from './newspaper250x.png';
|
||||||
|
import skateboard from './scateboard250x.png';
|
||||||
|
import science from './sience250x.png';
|
||||||
|
import sportcar from './sportcar250x.png';
|
||||||
|
import surfing from './surfing250x.png';
|
||||||
|
import umbrella from './umbrella250x.png';
|
||||||
|
import defaultAvatar from './default-avatar.svg';
|
||||||
|
import shieldIcon from './shield-icon.png';
|
||||||
|
import reactLogo from './react.svg';
|
||||||
|
|
||||||
|
export const images = {
|
||||||
|
ahareBot,
|
||||||
|
faq,
|
||||||
|
shorts,
|
||||||
|
balerina,
|
||||||
|
emotions,
|
||||||
|
realism,
|
||||||
|
prompt,
|
||||||
|
onboard1,
|
||||||
|
santa,
|
||||||
|
balloon,
|
||||||
|
bicycle,
|
||||||
|
book,
|
||||||
|
cocktail,
|
||||||
|
coffee,
|
||||||
|
cook,
|
||||||
|
cowboy,
|
||||||
|
detective,
|
||||||
|
dog,
|
||||||
|
fairy,
|
||||||
|
fire,
|
||||||
|
flowers,
|
||||||
|
gift,
|
||||||
|
icecream,
|
||||||
|
knight,
|
||||||
|
moto,
|
||||||
|
newspaper,
|
||||||
|
skateboard,
|
||||||
|
science,
|
||||||
|
sportcar,
|
||||||
|
surfing,
|
||||||
|
umbrella,
|
||||||
|
defaultAvatar,
|
||||||
|
shieldIcon,
|
||||||
|
reactLogo
|
||||||
|
};
|
||||||
@ -1,4 +1,5 @@
|
|||||||
import { AppConfig } from '../types/blocks';
|
import { AppConfig } from '../types/blocks';
|
||||||
|
import { images } from '../assets';
|
||||||
|
|
||||||
export const homeScreenConfig: AppConfig = {
|
export const homeScreenConfig: AppConfig = {
|
||||||
homeScreen: {
|
homeScreen: {
|
||||||
@ -15,7 +16,7 @@ export const homeScreenConfig: AppConfig = {
|
|||||||
colors: ['#FF69B4', '#FF1493']
|
colors: ['#FF69B4', '#FF1493']
|
||||||
},
|
},
|
||||||
title: 'Поделиться',
|
title: 'Поделиться',
|
||||||
imageUrl: '/src/assets/ahare_bot250.png',
|
imageUrl: images.ahareBot,
|
||||||
action: {
|
action: {
|
||||||
type: 'function',
|
type: 'function',
|
||||||
value: 'inviteFriends'
|
value: 'inviteFriends'
|
||||||
@ -29,7 +30,7 @@ export const homeScreenConfig: AppConfig = {
|
|||||||
colors: ['#2B9CFF', '#1E88E5']
|
colors: ['#2B9CFF', '#1E88E5']
|
||||||
},
|
},
|
||||||
title: 'Инструкция',
|
title: 'Инструкция',
|
||||||
imageUrl: '/src/assets/faq250.png',
|
imageUrl: images.faq,
|
||||||
action: {
|
action: {
|
||||||
type: 'route',
|
type: 'route',
|
||||||
value: '/onboarding/welcome'
|
value: '/onboarding/welcome'
|
||||||
@ -43,7 +44,7 @@ export const homeScreenConfig: AppConfig = {
|
|||||||
colors: ['#8A2BE2', '#9400D3']
|
colors: ['#8A2BE2', '#9400D3']
|
||||||
},
|
},
|
||||||
title: 'ShortsLoader',
|
title: 'ShortsLoader',
|
||||||
imageUrl: '/src/assets/shorts250.png',
|
imageUrl: images.shorts,
|
||||||
action: {
|
action: {
|
||||||
type: 'function',
|
type: 'function',
|
||||||
value: 'openTelegramBot'
|
value: 'openTelegramBot'
|
||||||
@ -94,7 +95,7 @@ export const homeScreenConfig: AppConfig = {
|
|||||||
colors: ['#FF69B4', '#FF1493']
|
colors: ['#FF69B4', '#FF1493']
|
||||||
},
|
},
|
||||||
title: 'Чиби',
|
title: 'Чиби',
|
||||||
imageUrl: '/src/assets/balerina250x.png',
|
imageUrl: images.balerina,
|
||||||
action: {
|
action: {
|
||||||
type: 'selectStyle',
|
type: 'selectStyle',
|
||||||
value: 'chibi'
|
value: 'chibi'
|
||||||
@ -108,7 +109,7 @@ export const homeScreenConfig: AppConfig = {
|
|||||||
colors: ['#2B9CFF', '#1E88E5']
|
colors: ['#2B9CFF', '#1E88E5']
|
||||||
},
|
},
|
||||||
title: 'Эмоции',
|
title: 'Эмоции',
|
||||||
imageUrl: '/src/assets/emotions_promo250x.png',
|
imageUrl: images.emotions,
|
||||||
action: {
|
action: {
|
||||||
type: 'selectStyle',
|
type: 'selectStyle',
|
||||||
value: 'emotions'
|
value: 'emotions'
|
||||||
@ -123,7 +124,7 @@ export const homeScreenConfig: AppConfig = {
|
|||||||
colors: ['#4CAF50', '#45A049']
|
colors: ['#4CAF50', '#45A049']
|
||||||
},
|
},
|
||||||
title: 'Реализм',
|
title: 'Реализм',
|
||||||
imageUrl: '/src/assets/realism_promo250x.png',
|
imageUrl: images.realism,
|
||||||
action: {
|
action: {
|
||||||
type: 'selectStyle',
|
type: 'selectStyle',
|
||||||
value: 'realism'
|
value: 'realism'
|
||||||
@ -162,7 +163,7 @@ export const homeScreenConfig: AppConfig = {
|
|||||||
colors: ['#2196F3', '#1976D2']
|
colors: ['#2196F3', '#1976D2']
|
||||||
},
|
},
|
||||||
title: 'Свой промпт',
|
title: 'Свой промпт',
|
||||||
imageUrl: '/src/assets/prompt.png',
|
imageUrl: images.prompt,
|
||||||
action: {
|
action: {
|
||||||
type: 'function',
|
type: 'function',
|
||||||
value: 'toggleInput'
|
value: 'toggleInput'
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import OnboardingLayout from '../../components/shared/OnboardingLayout';
|
import OnboardingLayout from '../../components/shared/OnboardingLayout';
|
||||||
import onboardImage from '../../assets/onboard1.png';
|
import { images } from '../../assets';
|
||||||
|
|
||||||
const OnboardingWelcome: React.FC = () => {
|
const OnboardingWelcome: React.FC = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@ -18,7 +18,7 @@ const OnboardingWelcome: React.FC = () => {
|
|||||||
return (
|
return (
|
||||||
<OnboardingLayout
|
<OnboardingLayout
|
||||||
title="Добро пожаловать в Sticker Generator"
|
title="Добро пожаловать в Sticker Generator"
|
||||||
image={onboardImage}
|
image={images.onboard1}
|
||||||
description="Создавайте уникальные стикеры из ваших фотографий с помощью искусственного интеллекта"
|
description="Создавайте уникальные стикеры из ваших фотографий с помощью искусственного интеллекта"
|
||||||
currentStep={1}
|
currentStep={1}
|
||||||
totalSteps={3}
|
totalSteps={3}
|
||||||
|
|||||||
@ -6,6 +6,34 @@ import { DEFAULT_USER_ID } from '../constants/user';
|
|||||||
|
|
||||||
const API_BASE_URL = 'https://stickerserver.gymnasticstuff.uk';
|
const API_BASE_URL = 'https://stickerserver.gymnasticstuff.uk';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Нормализует URL изображения, заменяя IP-адрес на домен, если необходимо.
|
||||||
|
* Если URL уже содержит домен, оставляет его без изменений.
|
||||||
|
* @param url URL изображения
|
||||||
|
* @returns Нормализованный URL
|
||||||
|
*/
|
||||||
|
export const normalizeImageUrl = (url: string): string => {
|
||||||
|
if (!url) return url;
|
||||||
|
|
||||||
|
// Если URL уже содержит домен, оставляем его без изменений
|
||||||
|
if (url.includes('stickerserver.gymnasticstuff.uk')) {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверяем, содержит ли URL IP-адрес (простая проверка на наличие цифр и точек)
|
||||||
|
const ipRegex = /\d+\.\d+\.\d+\.\d+/;
|
||||||
|
if (ipRegex.test(url)) {
|
||||||
|
// Заменяем IP-адрес на домен
|
||||||
|
// Извлекаем путь из URL (все, что после IP-адреса и порта, если есть)
|
||||||
|
const pathMatch = url.match(/https?:\/\/\d+\.\d+\.\d+\.\d+(:\d+)?(\/.*)/);
|
||||||
|
if (pathMatch && pathMatch[2]) {
|
||||||
|
return `${API_BASE_URL}${pathMatch[2]}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return url;
|
||||||
|
};
|
||||||
|
|
||||||
// Маппинг стилей к тегам для определения, какой тег использовать для каждого стиля
|
// Маппинг стилей к тегам для определения, какой тег использовать для каждого стиля
|
||||||
const styleToTagMap: Record<string, string> = {
|
const styleToTagMap: Record<string, string> = {
|
||||||
'chibi': 'image_generation',
|
'chibi': 'image_generation',
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { getUserIdString } from '../constants/user';
|
import { getUserIdString } from '../constants/user';
|
||||||
import { StickerPack, StickerSetResponse } from '../types/api';
|
import { StickerPack, StickerSetResponse } from '../types/api';
|
||||||
|
import { normalizeImageUrl } from './api';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Сервис для работы со стикерпаками через Sticker API.
|
* Сервис для работы со стикерпаками через Sticker API.
|
||||||
@ -43,7 +44,17 @@ export class StickerService {
|
|||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`Ошибка при получении стикерпака: ${response.statusText}`);
|
throw new Error(`Ошибка при получении стикерпака: ${response.statusText}`);
|
||||||
}
|
}
|
||||||
return await response.json();
|
const packData = await response.json();
|
||||||
|
|
||||||
|
// Нормализуем URL для каждого стикера
|
||||||
|
if (packData.stickers && Array.isArray(packData.stickers)) {
|
||||||
|
packData.stickers = packData.stickers.map((sticker: { file_url: string; [key: string]: any }) => ({
|
||||||
|
...sticker,
|
||||||
|
file_url: normalizeImageUrl(sticker.file_url)
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
return packData;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Ошибка при получении стикерпака:', error);
|
console.error('Ошибка при получении стикерпака:', error);
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user