@@ -4,6 +4,7 @@ import { activeDownloadsState } from '../atoms/downloads'
|
|||||||
import { useToast } from '../hooks/toast'
|
import { useToast } from '../hooks/toast'
|
||||||
import { useI18n } from '../hooks/useI18n'
|
import { useI18n } from '../hooks/useI18n'
|
||||||
import { useRPC } from '../hooks/useRPC'
|
import { useRPC } from '../hooks/useRPC'
|
||||||
|
import { ProcessStatus, RPCResult } from '../types'
|
||||||
import DownloadCard from './DownloadCard'
|
import DownloadCard from './DownloadCard'
|
||||||
|
|
||||||
const DownloadsGridView: React.FC = () => {
|
const DownloadsGridView: React.FC = () => {
|
||||||
@@ -13,6 +14,10 @@ const DownloadsGridView: React.FC = () => {
|
|||||||
const { client } = useRPC()
|
const { client } = useRPC()
|
||||||
const { pushMessage } = useToast()
|
const { pushMessage } = useToast()
|
||||||
|
|
||||||
|
const stop = (r: RPCResult) => r.progress.process_status === ProcessStatus.Completed
|
||||||
|
? client.clear(r.id)
|
||||||
|
: client.kill(r.id)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid container spacing={{ xs: 2, md: 2 }} columns={{ xs: 4, sm: 8, md: 12, xl: 12 }} pt={2}>
|
<Grid container spacing={{ xs: 2, md: 2 }} columns={{ xs: 4, sm: 8, md: 12, xl: 12 }} pt={2}>
|
||||||
{
|
{
|
||||||
@@ -20,7 +25,7 @@ const DownloadsGridView: React.FC = () => {
|
|||||||
<Grid item xs={4} sm={8} md={6} xl={4} key={download.id}>
|
<Grid item xs={4} sm={8} md={6} xl={4} key={download.id}>
|
||||||
<DownloadCard
|
<DownloadCard
|
||||||
download={download}
|
download={download}
|
||||||
onStop={() => client.kill(download.id)}
|
onStop={() => stop(download)}
|
||||||
onCopy={() => pushMessage(i18n.t('clipboardAction'), 'info')}
|
onCopy={() => pushMessage(i18n.t('clipboardAction'), 'info')}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import { useRecoilValue } from 'recoil'
|
|||||||
import { activeDownloadsState } from '../atoms/downloads'
|
import { activeDownloadsState } from '../atoms/downloads'
|
||||||
import { serverURL } from '../atoms/settings'
|
import { serverURL } from '../atoms/settings'
|
||||||
import { useRPC } from '../hooks/useRPC'
|
import { useRPC } from '../hooks/useRPC'
|
||||||
import { RPCResult } from '../types'
|
import { ProcessStatus, RPCResult } from '../types'
|
||||||
import { base64URLEncode, formatSize, formatSpeedMiB } from "../utils"
|
import { base64URLEncode, formatSize, formatSpeedMiB } from "../utils"
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
@@ -133,6 +133,11 @@ const DownloadsTableView: React.FC = () => {
|
|||||||
window.open(`${serverAddr}/archive/d/${encoded}?token=${localStorage.getItem('token')}`)
|
window.open(`${serverAddr}/archive/d/${encoded}?token=${localStorage.getItem('token')}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const stop = (r: RPCResult) => r.progress.process_status === ProcessStatus.Completed
|
||||||
|
? client.clear(r.id)
|
||||||
|
: client.kill(r.id)
|
||||||
|
|
||||||
|
|
||||||
function rowContent(_index: number, download: RPCResult) {
|
function rowContent(_index: number, download: RPCResult) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -168,7 +173,7 @@ const DownloadsTableView: React.FC = () => {
|
|||||||
<ButtonGroup>
|
<ButtonGroup>
|
||||||
<IconButton
|
<IconButton
|
||||||
size="small"
|
size="small"
|
||||||
onClick={() => client.kill(download.id)}
|
onClick={() => stop(download)}
|
||||||
>
|
>
|
||||||
{download.progress.percentage === '-1' ? <DeleteIcon /> : <StopCircleIcon />}
|
{download.progress.percentage === '-1' ? <DeleteIcon /> : <StopCircleIcon />}
|
||||||
|
|
||||||
|
|||||||
@@ -132,6 +132,13 @@ export class RPCClient {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public clear(id: string) {
|
||||||
|
this.sendHTTP({
|
||||||
|
method: 'Service.Clear',
|
||||||
|
params: [id],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
public killAll() {
|
public killAll() {
|
||||||
this.sendHTTP({
|
this.sendHTTP({
|
||||||
method: 'Service.KillAll',
|
method: 'Service.KillAll',
|
||||||
|
|||||||
@@ -34,11 +34,18 @@ type DownloadInfo = {
|
|||||||
created_at: string
|
created_at: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum ProcessStatus {
|
||||||
|
Pending = 0,
|
||||||
|
Downloading,
|
||||||
|
Completed,
|
||||||
|
Errored,
|
||||||
|
}
|
||||||
|
|
||||||
type DownloadProgress = {
|
type DownloadProgress = {
|
||||||
speed: number
|
speed: number
|
||||||
eta: number
|
eta: number
|
||||||
percentage: string
|
percentage: string
|
||||||
process_status: number
|
process_status: ProcessStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
export type RPCResult = Readonly<{
|
export type RPCResult = Readonly<{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { pipe } from 'fp-ts/lib/function'
|
import { pipe } from 'fp-ts/lib/function'
|
||||||
import type { RPCResponse } from "./types"
|
import type { RPCResponse } from "./types"
|
||||||
|
import { ProcessStatus } from './types'
|
||||||
|
|
||||||
export function validateIP(ipAddr: string): boolean {
|
export function validateIP(ipAddr: string): boolean {
|
||||||
let ipRegex = /^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/gm
|
let ipRegex = /^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/gm
|
||||||
@@ -53,15 +54,15 @@ export function isRPCResponse(object: any): object is RPCResponse<any> {
|
|||||||
return 'result' in object && 'id' in object
|
return 'result' in object && 'id' in object
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mapProcessStatus(status: number) {
|
export function mapProcessStatus(status: ProcessStatus) {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case 0:
|
case ProcessStatus.Pending:
|
||||||
return 'Pending'
|
return 'Pending'
|
||||||
case 1:
|
case ProcessStatus.Downloading:
|
||||||
return 'Downloading'
|
return 'Downloading'
|
||||||
case 2:
|
case ProcessStatus.Completed:
|
||||||
return 'Completed'
|
return 'Completed'
|
||||||
case 3:
|
case ProcessStatus.Errored:
|
||||||
return 'Error'
|
return 'Error'
|
||||||
default:
|
default:
|
||||||
return 'Pending'
|
return 'Pending'
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ func (s *Service) Kill(args string, killed *string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := proc.Kill(); err != nil {
|
if err := proc.Kill(); err != nil {
|
||||||
s.logger.Info("failed killing process", slog.String("id", proc.Id))
|
s.logger.Info("failed killing process", slog.String("id", proc.Id), slog.Any("err", err))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user