fix(#3080): aws server for web logos

keep-around/9d11a525a1ee745f785976389c40d7a0601133e1
Rakov Roman 3 years ago
parent 41d7131610
commit 7b417df0c2
  1. 2
      src/config/profileTypes.tsx
  2. 3
      src/features/Common/Image/index.tsx
  3. 2
      src/features/HomePage/components/HeaderFilters/index.tsx
  4. 2
      src/features/MatchCard/CardFrontside/MatchCardMobile/index.tsx
  5. 2
      src/features/MatchCard/CardFrontside/index.tsx
  6. 15
      src/features/ProfileLink/index.tsx
  7. 88
      src/features/ProfileLogo/index.tsx
  8. 8
      src/features/TournamentList/components/CollapseTournament/index.tsx
  9. 2
      src/features/UserFavorites/hooks/index.tsx
  10. 1
      src/features/UserFavorites/index.tsx
  11. 1
      src/helpers/getProfileFallbackLogo/index.tsx
  12. 6
      src/helpers/getProfileLogo/__tests__/index.tsx
  13. 26
      src/helpers/getProfileLogo/index.tsx
  14. 27
      src/requests/getMatches/getPlayerMatches.tsx
  15. 23
      src/requests/getMatches/getTeamMatches.tsx
  16. 23
      src/requests/getMatches/getTournamentMatches.tsx
  17. 12
      src/requests/getMatches/types.tsx
  18. 1
      src/requests/getProfileColor.tsx
  19. 1
      src/requests/search.tsx

@ -3,6 +3,7 @@ export enum ProfileTypes {
TEAMS = 2, TEAMS = 2,
PLAYERS = 3, PLAYERS = 3,
MATCHES = 4, MATCHES = 4,
SUPERTOURNAMENTS = 5
} }
export const PROFILE_NAMES = { export const PROFILE_NAMES = {
@ -10,4 +11,5 @@ export const PROFILE_NAMES = {
[ProfileTypes.TEAMS]: 'teams', [ProfileTypes.TEAMS]: 'teams',
[ProfileTypes.PLAYERS]: 'players', [ProfileTypes.PLAYERS]: 'players',
[ProfileTypes.MATCHES]: 'matches', [ProfileTypes.MATCHES]: 'matches',
[ProfileTypes.SUPERTOURNAMENTS]: 'supertournaments',
} as const } as const

@ -8,7 +8,6 @@ const ImageStyled = styled.img``
type Props = { type Props = {
alt?: string, alt?: string,
className?: string, className?: string,
dataSrc?: string,
fallbackSrc?: string, fallbackSrc?: string,
onLoad?: () => void, onLoad?: () => void,
src: string, src: string,
@ -18,7 +17,6 @@ type Props = {
export const Image = ({ export const Image = ({
alt, alt,
className, className,
dataSrc,
fallbackSrc = '', fallbackSrc = '',
onLoad, onLoad,
src, src,
@ -35,7 +33,6 @@ export const Image = ({
<ImageStyled <ImageStyled
alt={alt} alt={alt}
src={src} src={src}
data-src={dataSrc}
className={className} className={className}
onError={onError} onError={onError}
onLoad={onLoad} onLoad={onLoad}

@ -55,6 +55,8 @@ export const HeaderFilters = () => {
onClick={() => handleClickBack()} onClick={() => handleClickBack()}
/> />
<ProfileLink <ProfileLink
// страницы супертурнира не существует, возможно появится
disabled={selectTournament.is_super_tournament}
id={selectTournament.id} id={selectTournament.id}
sportType={selectTournament.sportType} sportType={selectTournament.sportType}
profileType={ProfileTypes.TOURNAMENTS} profileType={ProfileTypes.TOURNAMENTS}

@ -112,6 +112,7 @@ export const CardFrontsideMobile = ({
<TeamLogos> <TeamLogos>
<TeamLogo <TeamLogo
id={team1.id} id={team1.id}
logoUrl={team1.media?.logo_url}
nameAsTitle nameAsTitle
altNameObj={team1} altNameObj={team1}
sportType={sportType} sportType={sportType}
@ -119,6 +120,7 @@ export const CardFrontsideMobile = ({
/> />
<TeamLogo <TeamLogo
id={team2.id} id={team2.id}
logoUrl={team2.media?.logo_url}
nameAsTitle nameAsTitle
altNameObj={team2} altNameObj={team2}
sportType={sportType} sportType={sportType}

@ -128,6 +128,7 @@ export const CardFrontside = ({
<TeamLogos isMatchPage={isMatchPage}> <TeamLogos isMatchPage={isMatchPage}>
<TeamLogo <TeamLogo
id={team1.id} id={team1.id}
logoUrl={team1.media?.logo_url}
nameAsTitle nameAsTitle
altNameObj={team1} altNameObj={team1}
sportType={sportType} sportType={sportType}
@ -135,6 +136,7 @@ export const CardFrontside = ({
/> />
<TeamLogo <TeamLogo
id={team2.id} id={team2.id}
logoUrl={team2.media?.logo_url}
nameAsTitle nameAsTitle
altNameObj={team2} altNameObj={team2}
sportType={sportType} sportType={sportType}

@ -1,6 +1,8 @@
import type { ReactNode, MouseEvent } from 'react' import type { ReactNode, MouseEvent } from 'react'
import { Link } from 'react-router-dom' import { Link } from 'react-router-dom'
import styled, { css } from 'styled-components'
import { ProfileTypes, SportTypes } from 'config' import { ProfileTypes, SportTypes } from 'config'
import { getProfileUrl } from './helpers' import { getProfileUrl } from './helpers'
@ -8,6 +10,7 @@ import { getProfileUrl } from './helpers'
type Props = { type Props = {
children: ReactNode, children: ReactNode,
className?: string, className?: string,
disabled?: boolean,
id: number, id: number,
onClick?: (e: MouseEvent<HTMLAnchorElement>) => void, onClick?: (e: MouseEvent<HTMLAnchorElement>) => void,
profileType: ProfileTypes, profileType: ProfileTypes,
@ -15,9 +18,16 @@ type Props = {
target?: string, target?: string,
} }
const ScLink = styled(Link)<{disabled?: boolean}>`
${({ disabled }) => disabled && css`
pointer-events: none;
`}
`
export const ProfileLink = ({ export const ProfileLink = ({
children, children,
className, className,
disabled,
id, id,
onClick, onClick,
profileType, profileType,
@ -30,13 +40,14 @@ export const ProfileLink = ({
sportType, sportType,
}) })
return ( return (
<Link <ScLink
disabled={disabled}
to={url} to={url}
className={className} className={className}
target={target} target={target}
onClick={onClick} onClick={onClick}
> >
{children} {children}
</Link> </ScLink>
) )
} }

@ -1,5 +1,16 @@
import {
Fragment,
useEffect,
useState,
} from 'react'
import { ProfileTypes, SportTypes } from 'config' import { ProfileTypes, SportTypes } from 'config'
import { getProfileFallbackLogo, getProfileLogo } from 'helpers'
import {
getProfileFallbackLogo,
getProfileLogo,
readToken,
} from 'helpers'
import { Image } from 'features/Common' import { Image } from 'features/Common'
import type { ObjectWithName } from 'features/Name' import type { ObjectWithName } from 'features/Name'
@ -10,8 +21,7 @@ type ProfileImageProps = {
altNameObj?: ObjectWithName, altNameObj?: ObjectWithName,
className?: string, className?: string,
id: number, id: number,
isTournamentSuper?: boolean, logoUrl?: string | null,
lazy?: boolean,
nameAsTitle?: boolean, nameAsTitle?: boolean,
onLoad?: () => void, onLoad?: () => void,
prefix?: string, prefix?: string,
@ -21,13 +31,19 @@ type ProfileImageProps = {
title?: string, title?: string,
} }
type AwsMediaFlags = {
cover_url: 'string' | null,
landing_mobile_url: 'string' | null,
landing_url: 'string' | null,
logo_url: 'string' | null,
}
export const ProfileLogo = ({ export const ProfileLogo = ({
alt, alt,
altNameObj, altNameObj,
className, className,
id, id,
isTournamentSuper, logoUrl,
lazy = false,
nameAsTitle, nameAsTitle,
onLoad, onLoad,
prefix, prefix,
@ -36,26 +52,66 @@ export const ProfileLogo = ({
sportType, sportType,
title, title,
}: ProfileImageProps) => { }: ProfileImageProps) => {
const [imageSource, setImageSource] = useState('')
const altName = useName(altNameObj || {}, prefix) const altName = useName(altNameObj || {}, prefix)
const titleText = nameAsTitle ? altName : title const titleText = nameAsTitle ? altName : title
const src = getProfileLogo({ const awsSrc = getProfileLogo({
awsInError: false,
id,
profileType,
size,
sportType,
})
const scoutSrc = getProfileLogo({
awsInError: true,
id, id,
isTournamentSuper,
profileType, profileType,
size, size,
sportType, sportType,
}) })
const fallbackSrc = getProfileFallbackLogo(profileType) const fallbackSrc = getProfileFallbackLogo(profileType)
useEffect(() => {
(async () => {
if (!logoUrl) {
setImageSource(scoutSrc)
return
}
if (logoUrl) {
setImageSource(logoUrl)
return
}
try {
const { logo_url }: AwsMediaFlags = await (await fetch(awsSrc, {
headers: { Authorization: `Bearer ${readToken()}` },
})).json()
if (logo_url) {
setImageSource(logo_url)
return
}
setImageSource(scoutSrc)
} catch (error) {
setImageSource(scoutSrc)
}
})()
}, [awsSrc, logoUrl, scoutSrc])
return ( return (
<Image <Fragment>
alt={alt || altName} {Boolean(imageSource) && (
src={lazy ? '' : src} <Image
dataSrc={lazy ? src : ''} alt={alt || altName}
fallbackSrc={fallbackSrc} src={imageSource}
className={className} fallbackSrc={fallbackSrc}
onLoad={onLoad} className={className}
title={titleText} onLoad={onLoad}
/> title={titleText}
/>
)}
</Fragment>
) )
} }

@ -59,11 +59,15 @@ export const CollapseTournament = ({
<PreviewWrapper> <PreviewWrapper>
<TournamentLogo <TournamentLogo
id={tournament.id} id={tournament.id}
isTournamentSuper={tournament.is_super_tournament} logoUrl={tournament.media?.logo_url}
nameAsTitle nameAsTitle
altNameObj={tournament} altNameObj={tournament}
sportType={sportType} sportType={sportType}
profileType={ProfileTypes.TOURNAMENTS} profileType={
tournament.is_super_tournament
? ProfileTypes.SUPERTOURNAMENTS
: ProfileTypes.TOURNAMENTS
}
/> />
<MatchTimeInfo> <MatchTimeInfo>
{live && ( {live && (

@ -63,7 +63,7 @@ export const useUserFavorites = () => {
acc.push({ acc.push({
...item.info.super_tournament, ...item.info.super_tournament,
sport: item.sport, sport: item.sport,
type: item.type, type: ProfileTypes.SUPERTOURNAMENTS,
}) })
} }
return acc return acc

@ -73,7 +73,6 @@ export const UserFavorites = ({ marginTop }: Props) => {
/> />
</UserSportFavXWrapper> </UserSportFavXWrapper>
<UserSportFavImgWrapper <UserSportFavImgWrapper
isTournamentSuper
id={item.id} id={item.id}
altNameObj={item} altNameObj={item}
sportType={item.sport} sportType={item.sport}

@ -4,6 +4,7 @@ const FALLBACK_LOGOS = {
[ProfileTypes.PLAYERS]: '/images/player-fallback.png', [ProfileTypes.PLAYERS]: '/images/player-fallback.png',
[ProfileTypes.TEAMS]: '/images/team-fallback.png', [ProfileTypes.TEAMS]: '/images/team-fallback.png',
[ProfileTypes.TOURNAMENTS]: '/images/tournament-fallback.png', [ProfileTypes.TOURNAMENTS]: '/images/tournament-fallback.png',
[ProfileTypes.SUPERTOURNAMENTS]: '/images/tournament-fallback.png',
} }
export const getProfileFallbackLogo = (profileType: ProfileTypes) => { export const getProfileFallbackLogo = (profileType: ProfileTypes) => {

@ -8,18 +8,18 @@ describe('getLogo helper', () => {
id: 1, id: 1,
profileType: ProfileTypes.PLAYERS, profileType: ProfileTypes.PLAYERS,
sportType: SportTypes.FOOTBALL, sportType: SportTypes.FOOTBALL,
})).toBe('https://instatscout.com/images/players/180/1.png') })).toBe('https://api.test.insports.tv/v1/players/1/1/media')
expect(getProfileLogo({ expect(getProfileLogo({
id: 1, id: 1,
profileType: ProfileTypes.TEAMS, profileType: ProfileTypes.TEAMS,
sportType: SportTypes.BASKETBALL, sportType: SportTypes.BASKETBALL,
})).toBe('https://basketball.instatscout.com/images/teams/180/1.png') })).toBe('https://api.test.insports.tv/v1/teams/3/1/media')
expect(getProfileLogo({ expect(getProfileLogo({
id: 1, id: 1,
profileType: ProfileTypes.TOURNAMENTS, profileType: ProfileTypes.TOURNAMENTS,
sportType: SportTypes.HOCKEY, sportType: SportTypes.HOCKEY,
})).toBe('https://hockey.instatscout.com/images/tournaments/180/1.png') })).toBe('https://api.test.insports.tv/v1/tournaments/2/1/media')
}) })
}) })

@ -2,13 +2,12 @@ import {
SportTypes, SportTypes,
ProfileTypes, ProfileTypes,
PROFILE_NAMES, PROFILE_NAMES,
API_ROOT,
} from 'config' } from 'config'
import { readToken, readSelectedApi } from 'helpers'
const IMAGES_URLS = { const IMAGES_URLS = {
[SportTypes.BASKETBALL]: 'https://basketball.instatscout.com/images', [SportTypes.BASKETBALL]: 'https://basketball.instatscout.com/images',
[SportTypes.BOXING]: '', [SportTypes.BOXING]: 'https://boxing.instatscout.com/images',
[SportTypes.FOOTBALL]: 'https://instatscout.com/images', [SportTypes.FOOTBALL]: 'https://instatscout.com/images',
[SportTypes.HOCKEY]: 'https://hockey.instatscout.com/images', [SportTypes.HOCKEY]: 'https://hockey.instatscout.com/images',
[SportTypes.HANDBALL]: 'https://handball.instatscout.com/images', [SportTypes.HANDBALL]: 'https://handball.instatscout.com/images',
@ -16,34 +15,23 @@ const IMAGES_URLS = {
[SportTypes.VOLLEYBALL]: 'https://volleyball.instatscout.com/images', [SportTypes.VOLLEYBALL]: 'https://volleyball.instatscout.com/images',
} }
enum MediaType {
cover = 'cover',
landing = 'landing',
landing_mobile = 'landing_mobile',
logo = 'logo'
}
type GetLogoArgs = { type GetLogoArgs = {
awsInError?: boolean,
id: number, id: number,
isTournamentSuper?: boolean,
profileType: ProfileTypes, profileType: ProfileTypes,
size?: number, size?: number,
sportType: SportTypes, sportType: SportTypes,
} }
export const getProfileLogo = ({ export const getProfileLogo = ({
awsInError,
id, id,
isTournamentSuper,
profileType, profileType,
size = 180, size = 180,
sportType, sportType,
}: GetLogoArgs) => { }: GetLogoArgs) => {
switch (true) { if (awsInError) {
case isTournamentSuper: return `${IMAGES_URLS[sportType]}/${PROFILE_NAMES[profileType]}/${size}/${id}.png`
return `https://cf-aws${readSelectedApi() === 'staging' ? '-staging' : ''}.insports.tv/media/supertournaments/${sportType}/${id}/${MediaType.logo}.jpg?access_token=${readToken()}`
case sportType === SportTypes.BOXING:
return `https://images.insports.tv/${sportType}/${PROFILE_NAMES[profileType]}/${id}.png`
default:
return `${IMAGES_URLS[sportType]}/${PROFILE_NAMES[profileType]}/${size}/${id}.png`
} }
return `${API_ROOT}/v1/${PROFILE_NAMES[profileType]}/${sportType}/${id}/media`
} }

@ -1,4 +1,8 @@
import { PROCEDURES, SportTypes } from 'config' import {
API_ROOT,
PROCEDURES,
SportTypes,
} from 'config'
import { client } from 'config/clients' import { client } from 'config/clients'
@ -27,22 +31,21 @@ export const getPlayerMatches = async ({
sportType, sportType,
sub_only, sub_only,
}: Args): Promise<MatchesBySection> => { }: Args): Promise<MatchesBySection> => {
const url = `${API_ROOT}/v1/data/get-player-matches`
const config = { const config = {
body: { body: {
params: { limit,
_p_limit: limit, match_completed: p_match_completed,
_p_match_completed: p_match_completed, offset,
_p_offset: offset, player_id: playerId,
_p_player_id: playerId, sport: sportType,
_p_sport: sportType, sub_only,
_p_sub_only: sub_only, ...client.requests?.[proc],
...client.requests?.[proc],
},
proc,
}, },
} }
return requestMatches(config) return requestMatches(config, url)
.then((matches) => addSportType(matches, sportType)) .then((matches) => addSportType(matches, sportType))
.then(getMatchesPreviews) .then(getMatchesPreviews)
} }

@ -1,4 +1,8 @@
import { PROCEDURES, SportTypes } from 'config' import {
API_ROOT,
PROCEDURES,
SportTypes,
} from 'config'
import { client } from 'config/clients' import { client } from 'config/clients'
@ -23,20 +27,19 @@ export const getTeamMatches = async ({
sportType, sportType,
teamId, teamId,
}: Args): Promise<MatchesBySection> => { }: Args): Promise<MatchesBySection> => {
const url = `${API_ROOT}/v1/data/get-team-matches`
const config = { const config = {
body: { body: {
params: { limit,
_p_limit: limit, offset,
_p_offset: offset, sport: sportType,
_p_sport: sportType, team_id: teamId,
_p_team_id: teamId, ...client.requests?.[proc],
...client.requests?.[proc],
},
proc,
}, },
} }
return requestMatches(config) return requestMatches(config, url)
.then((matches) => addSportType(matches, sportType)) .then((matches) => addSportType(matches, sportType))
.then(getMatchesPreviews) .then(getMatchesPreviews)
} }

@ -1,4 +1,8 @@
import { PROCEDURES, SportTypes } from 'config' import {
API_ROOT,
PROCEDURES,
SportTypes,
} from 'config'
import { client } from 'config/clients' import { client } from 'config/clients'
@ -23,20 +27,19 @@ export const getTournamentMatches = async ({
sportType, sportType,
tournamentId, tournamentId,
}: Args): Promise<MatchesBySection> => { }: Args): Promise<MatchesBySection> => {
const url = `${API_ROOT}/v1/data/get-tournament-matches`
const config = { const config = {
body: { body: {
params: { limit,
_p_limit: limit, offset,
_p_offset: offset, sport: sportType,
_p_sport: sportType, tournament_id: tournamentId,
_p_tournament_id: tournamentId, ...client.requests?.[proc],
...client.requests?.[proc],
},
proc,
}, },
} }
return requestMatches(config) return requestMatches(config, url)
.then((matches) => addSportType(matches, sportType)) .then((matches) => addSportType(matches, sportType))
.then(getMatchesPreviews) .then(getMatchesPreviews)
} }

@ -1,8 +1,19 @@
import { SportTypes } from 'config' import { SportTypes } from 'config'
type AwsTeamMedia = {
cover_url: string | null,
logo_url: string | null,
}
type AwsTournamentMedia = AwsTeamMedia & {
landing_mobile_url: string | null,
landing_url: string | null,
}
export type TournamentType = { export type TournamentType = {
id: number, id: number,
is_super_tournament?: boolean, is_super_tournament?: boolean,
media?: AwsTournamentMedia,
name_eng: string, name_eng: string,
name_rus: string, name_rus: string,
sportType: SportTypes, sportType: SportTypes,
@ -10,6 +21,7 @@ export type TournamentType = {
type Team = { type Team = {
id: number, id: number,
media?: AwsTeamMedia,
name_eng: string, name_eng: string,
name_rus: string, name_rus: string,
score?: number | null, score?: number | null,

@ -10,6 +10,7 @@ const profiles = {
[ProfileTypes.TOURNAMENTS]: 'tournament', [ProfileTypes.TOURNAMENTS]: 'tournament',
[ProfileTypes.PLAYERS]: 'team', [ProfileTypes.PLAYERS]: 'team',
[ProfileTypes.MATCHES]: '', [ProfileTypes.MATCHES]: '',
[ProfileTypes.SUPERTOURNAMENTS]: '',
} }
type Response = { type Response = {

@ -46,6 +46,7 @@ const filterResults = ({
const filteredResults = { const filteredResults = {
players: filter(results.players, filterFunc), players: filter(results.players, filterFunc),
supertournaments: '',
teams: filter(results.teams, filterFunc), teams: filter(results.teams, filterFunc),
tournaments: filter(results.tournaments, filterFunc), tournaments: filter(results.tournaments, filterFunc),
} }

Loading…
Cancel
Save