import DeleteIcon from '@mui/icons-material/Delete'
import DownloadIcon from '@mui/icons-material/Download'
import DownloadDoneIcon from '@mui/icons-material/DownloadDone'
import FileDownloadIcon from '@mui/icons-material/FileDownload'
import SmartDisplayIcon from '@mui/icons-material/SmartDisplay'
import StopCircleIcon from '@mui/icons-material/StopCircle'
import {
Box,
ButtonGroup,
IconButton,
LinearProgress,
LinearProgressProps,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
Typography
} from "@mui/material"
import { useRecoilValue } from 'recoil'
import { activeDownloadsState } from '../atoms/downloads'
import { serverURL } from '../atoms/settings'
import { useRPC } from '../hooks/useRPC'
import { base64URLEncode, formatSize, formatSpeedMiB } from "../utils"
function LinearProgressWithLabel(props: LinearProgressProps & { value: number }) {
return (
{`${Math.round(
props.value,
)}%`}
)
}
const DownloadsTableView: React.FC = () => {
const serverAddr = useRecoilValue(serverURL)
const downloads = useRecoilValue(activeDownloadsState)
const { client } = useRPC()
const abort = (id: string) => client.kill(id)
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 (
Status
Title
Speed
Progress
Size
Added on
Actions
{
downloads.map(download => (
{download.progress.percentage === '-1'
?
:
}
{download.info.title}
{formatSpeedMiB(download.progress.speed)}
{formatSize(download.info.filesize_approx ?? 0)}
{new Date(download.info.created_at).toLocaleString()}
abort(download.id)}
>
{download.progress.percentage === '-1' ? : }
{download.progress.percentage === '-1' &&
<>
viewFile(download.output.savedFilePath)}
>
downloadFile(download.output.savedFilePath)}
>
>
}
))
}
)
}
export default DownloadsTableView