feat(#168): add video download process
parent
93e2716817
commit
9271894154
@ -1,8 +1,12 @@ |
||||
export const matchDownload = { |
||||
can_close: 20238, |
||||
choose_what_to_download: 20193, |
||||
download_files_for_periods: 20197, |
||||
download_full_match: 20198, |
||||
download_single_file: 20196, |
||||
entire_record: 20195, |
||||
error_message: 20240, |
||||
in_game_time_only: 20194, |
||||
processed: 20200, |
||||
will_notified: 20239, |
||||
} |
||||
|
||||
@ -0,0 +1,62 @@ |
||||
import { useQueryClient } from 'react-query' |
||||
|
||||
import { T9n } from 'features/T9n' |
||||
|
||||
import { querieKeys } from 'config' |
||||
|
||||
import { DownloadResponse } from 'requests/downloadPlaylist' |
||||
|
||||
import { |
||||
Container, |
||||
Description, |
||||
Title, |
||||
CloseBtn, |
||||
Header, |
||||
MainContainer, |
||||
Error, |
||||
} from './styled' |
||||
|
||||
type TDownloadNotification = { |
||||
close: () => void, |
||||
} |
||||
|
||||
export const DownloadNotification = ({ close }:TDownloadNotification) => { |
||||
const client = useQueryClient() |
||||
|
||||
const data = client.getQueryData<DownloadResponse>(querieKeys.downloadPlaylist) |
||||
|
||||
if (!data) { |
||||
return null |
||||
} |
||||
|
||||
return ( |
||||
<Container> |
||||
<Header> |
||||
<CloseBtn |
||||
onClick={close} |
||||
/> |
||||
</Header> |
||||
<MainContainer> |
||||
<Title> |
||||
<T9n t='processed' /> |
||||
</Title> |
||||
<Description> |
||||
{data?.status === 'ERROR' |
||||
? ( |
||||
<Error> |
||||
<T9n t='error_message' /> |
||||
</Error> |
||||
) : ( |
||||
<> |
||||
<T9n t='can_close' /> |
||||
<T9n t='will_notified' /> |
||||
{/* <LinkToDownload href='/useraccount/downloads'> */} |
||||
{/* My Videos */} |
||||
{/* </LinkToDownload> */} |
||||
</> |
||||
)} |
||||
</Description> |
||||
</MainContainer> |
||||
</Container> |
||||
) |
||||
} |
||||
@ -0,0 +1,48 @@ |
||||
import styled from 'styled-components/macro' |
||||
|
||||
import { CloseButton } from 'features/PopupComponents' |
||||
|
||||
export const Container = styled.section` |
||||
width: 100%; |
||||
border-radius: 0.125rem; |
||||
background: #333; |
||||
padding: 0.5rem 0.5rem ; |
||||
color: #FFF; |
||||
font-weight: 400; |
||||
line-height: normal; |
||||
font-size: 0.75rem; |
||||
margin-bottom: 0.45rem; |
||||
` |
||||
|
||||
export const Title = styled.h3` |
||||
font-size: 0.875rem; |
||||
font-style: normal; |
||||
font-weight: 700; |
||||
margin-bottom: 0.56rem; |
||||
` |
||||
|
||||
export const Description = styled.span` |
||||
` |
||||
|
||||
export const CloseBtn = styled(CloseButton)` |
||||
padding: 4px; |
||||
` |
||||
|
||||
export const Header = styled.header` |
||||
display: flex; |
||||
justify-content: end; |
||||
` |
||||
|
||||
export const MainContainer = styled.main` |
||||
padding: 0.4rem 1.1rem 2rem 1.3rem; |
||||
` |
||||
|
||||
export const LinkToDownload = styled.a` |
||||
text-decoration: underline; |
||||
cursor: pointer; |
||||
color: white; |
||||
font-weight: 600; |
||||
` |
||||
export const Error = styled.span` |
||||
color: red; |
||||
` |
||||
@ -0,0 +1,19 @@ |
||||
/* скачивание файлов без клика */ |
||||
|
||||
export const downloadFile = (urls: Array<string>) => { |
||||
if (!urls.length) return |
||||
|
||||
urls.forEach((url) => { |
||||
const link = document.createElement('a') |
||||
|
||||
link.href = url |
||||
link.download = 'video.mp4' |
||||
link.target = '_blank' |
||||
|
||||
document.body.appendChild(link) |
||||
|
||||
link.click() |
||||
|
||||
document.body.removeChild(link) |
||||
}) |
||||
} |
||||
@ -0,0 +1,38 @@ |
||||
import { API_ROOT } from 'config' |
||||
import { callApi } from 'helpers' |
||||
|
||||
export type DownloadPlaylistProps = { |
||||
ball_in_play: boolean, |
||||
concat?: boolean, |
||||
match_id: number, |
||||
sport_id: number, |
||||
} |
||||
|
||||
type Status = 'COMPLETED' | 'IN PROGRESS' | 'ERROR' |
||||
|
||||
export type DownloadResponse = { |
||||
status:Status, |
||||
urls?: Array<string>, |
||||
} |
||||
|
||||
export const downloadPlaylist = async ( |
||||
{ |
||||
ball_in_play, |
||||
concat, |
||||
match_id, |
||||
sport_id, |
||||
}: DownloadPlaylistProps, |
||||
) |
||||
: Promise<DownloadResponse> => { |
||||
const config = { |
||||
body: { |
||||
ball_in_play, |
||||
concat, |
||||
}, |
||||
} |
||||
|
||||
return callApi({ |
||||
config, |
||||
url: `${API_ROOT}/v1/matches/${sport_id}/${match_id}/download`, |
||||
}) |
||||
} |
||||
Loading…
Reference in new issue