Other changes for Tauri

This commit is contained in:
Igor Katson 2023-12-02 15:59:20 +00:00
parent 99db087cf1
commit fe04e17d63
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
6 changed files with 16 additions and 23 deletions

View file

@ -11,6 +11,14 @@ pub struct ApiError {
}
impl ApiError {
pub fn new_from_string(status: StatusCode, text: String) -> Self {
Self {
status: Some(status),
kind: ApiErrorKind::Other(anyhow::anyhow!("{}", text)),
plaintext: false,
}
}
pub const fn torrent_not_found(torrent_id: usize) -> Self {
Self {
status: Some(StatusCode::NOT_FOUND),

View file

@ -185,10 +185,13 @@ fn compute_only_files<ByteBuf: AsRef<[u8]>>(
#[serde_as]
#[derive(Default, Clone, Serialize, Deserialize)]
pub struct AddTorrentOptions {
#[serde(default)]
pub paused: bool,
pub only_files_regex: Option<String>,
pub only_files: Option<Vec<usize>>,
#[serde(default)]
pub overwrite: bool,
#[serde(default)]
pub list_only: bool,
pub output_folder: Option<String>,
pub sub_folder: Option<String>,

File diff suppressed because one or more lines are too long

View file

@ -4,7 +4,7 @@
"src": "assets/logo.svg"
},
"index.html": {
"file": "assets/index-c6a3908d.js",
"file": "assets/index-386e9e08.js",
"isEntry": true,
"src": "index.html"
}

View file

@ -26,19 +26,6 @@ export interface ListTorrentsResponse {
torrents: Array<TorrentId>;
}
export interface TorrentAddQueryParams {
overwrite?: boolean | null;
output_folder?: string | null;
sub_folder?: string | null;
only_files_regex?: string | null;
only_files?: string,
peer_connect_timeout?: number | null;
peer_read_write_timeout?: number | null;
initial_peers?: string | null;
is_url?: boolean | null;
list_only?: boolean | null;
}
// Interface for the Torrent Stats API response
export interface LiveTorrentStats {
snapshot: {

View file

@ -1,6 +1,6 @@
import { MouseEventHandler, RefObject, createContext, useContext, useEffect, useRef, useState } from 'react';
import { ProgressBar, Button, Container, Row, Col, Alert, Modal, Form, Spinner } from 'react-bootstrap';
import { AddTorrentResponse, TorrentDetails, TorrentId, TorrentStats, ErrorDetails as ApiErrorDetails, STATE_INITIALIZING, STATE_LIVE, STATE_PAUSED, STATE_ERROR, RqbitAPI, ErrorDetails, ListTorrentsResponse, AddTorrentOptions } from './api-types';
import { AddTorrentResponse, TorrentDetails, TorrentId, TorrentStats, ErrorDetails as ApiErrorDetails, STATE_INITIALIZING, STATE_LIVE, STATE_PAUSED, STATE_ERROR, RqbitAPI, AddTorrentOptions } from './api-types';
interface Error {
text: string,
@ -318,7 +318,7 @@ const Torrent: React.FC<{
return liveInterval;
}
return nonLiveInterval;
}, (e) => {
}, () => {
return errorInterval;
});
}), 0), [forceStatsRefresh]);
@ -442,7 +442,7 @@ const UploadButton: React.FC<{
const response = await API.uploadTorrent(data, { list_only: true });
setListTorrentResponse(response);
} catch (e) {
setListTorrentError({ text: 'Error listing torrent files', details: e as ErrorDetails });
setListTorrentError({ text: 'Error listing torrent files', details: e as ApiErrorDetails });
} finally {
setLoading(false);
}
@ -511,11 +511,6 @@ const MagnetInput = () => {
let [showModal, setShowModal] = useState(false);
const onClick = () => {
const m = prompt('Enter magnet link or HTTP(s) URL');
setMagnet(m === '' ? null : m);
};
return (
<>
<UploadButton