import EightK from '@mui/icons-material/EightK'
import FourK from '@mui/icons-material/FourK'
import Hd from '@mui/icons-material/Hd'
import Sd from '@mui/icons-material/Sd'
import {
Button,
Card,
CardActionArea,
CardActions,
CardContent,
CardMedia,
Chip,
LinearProgress,
Skeleton,
Stack,
Typography
} from '@mui/material'
import { useCallback } from 'react'
import { useRecoilValue } from 'recoil'
import { serverURL } from '../atoms/settings'
import { RPCResult } from '../types'
import { base64URLEncode, ellipsis, formatSize, formatSpeedMiB, mapProcessStatus } from '../utils'
type Props = {
download: RPCResult
onStop: () => void
onCopy: () => void
}
const Resolution: React.FC<{ resolution?: string }> = ({ resolution }) => {
if (!resolution) return null
if (resolution.includes('4320')) return
if (resolution.includes('2160')) return
if (resolution.includes('1080')) return
if (resolution.includes('720')) return
return null
}
const DownloadCard: React.FC = ({ download, onStop, onCopy }) => {
const serverAddr = useRecoilValue(serverURL)
const isCompleted = useCallback(
() => download.progress.percentage === '-1',
[download.progress.percentage]
)
const percentageToNumber = useCallback(
() => isCompleted()
? 100
: Number(download.progress.percentage.replace('%', '')),
[download.progress.percentage, isCompleted]
)
const viewFile = (path: string) => {
const encoded = base64URLEncode(path)
window.open(`${serverAddr}/archive/v/${encoded}?token=${localStorage.getItem('token')}`)
}
const downloadFile = (path: string) => {
const encoded = base64URLEncode(path)
window.open(`${serverAddr}/archive/d/${encoded}?token=${localStorage.getItem('token')}`)
}
return (
{
navigator.clipboard.writeText(download.info.url)
onCopy()
}}>
{download.info.thumbnail !== '' ?
:
}
{download.progress.percentage ?
:
null
}
{download.info.title !== '' ?
{ellipsis(download.info.title, 100)}
:
}
{!isCompleted() ? download.progress.percentage : ''}
{!isCompleted() ? formatSpeedMiB(download.progress.speed) : ''}
{formatSize(download.info.filesize_approx ?? 0)}
{isCompleted() &&
<>
>
}
)
}
export default DownloadCard