refactor: move AddTorrentRequest to shared library for type safety
All checks were successful
Build MIPS Binary / build (push) Successful in 4m28s
All checks were successful
Build MIPS Binary / build (push) Successful in 4m28s
This commit is contained in:
@@ -11,12 +11,10 @@ use axum::{
|
|||||||
BoxError,
|
BoxError,
|
||||||
};
|
};
|
||||||
use rust_embed::RustEmbed;
|
use rust_embed::RustEmbed;
|
||||||
use serde::Deserialize;
|
|
||||||
use shared::{
|
use shared::{
|
||||||
GlobalLimitRequest, SetFilePriorityRequest, SetLabelRequest, TorrentActionRequest, TorrentFile,
|
AddTorrentRequest, GlobalLimitRequest, SetFilePriorityRequest, SetLabelRequest, TorrentActionRequest,
|
||||||
TorrentPeer, TorrentTracker,
|
TorrentFile, TorrentPeer, TorrentTracker,
|
||||||
};
|
};
|
||||||
use utoipa::ToSchema;
|
|
||||||
|
|
||||||
pub mod auth;
|
pub mod auth;
|
||||||
pub mod setup;
|
pub mod setup;
|
||||||
@@ -25,13 +23,6 @@ pub mod setup;
|
|||||||
#[folder = "../frontend/dist"]
|
#[folder = "../frontend/dist"]
|
||||||
pub struct Asset;
|
pub struct Asset;
|
||||||
|
|
||||||
#[derive(Deserialize, ToSchema)]
|
|
||||||
pub struct AddTorrentRequest {
|
|
||||||
/// Magnet link or Torrent file URL
|
|
||||||
#[schema(example = "magnet:?xt=urn:btih:...")]
|
|
||||||
uri: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn static_handler(uri: Uri) -> impl IntoResponse {
|
pub async fn static_handler(uri: Uri) -> impl IntoResponse {
|
||||||
let mut path = uri.path().trim_start_matches('/').to_string();
|
let mut path = uri.path().trim_start_matches('/').to_string();
|
||||||
|
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ struct Args {
|
|||||||
),
|
),
|
||||||
components(
|
components(
|
||||||
schemas(
|
schemas(
|
||||||
handlers::AddTorrentRequest,
|
shared::AddTorrentRequest,
|
||||||
shared::TorrentActionRequest,
|
shared::TorrentActionRequest,
|
||||||
shared::Torrent,
|
shared::Torrent,
|
||||||
shared::TorrentStatus,
|
shared::TorrentStatus,
|
||||||
@@ -172,7 +172,7 @@ struct ApiDoc;
|
|||||||
),
|
),
|
||||||
components(
|
components(
|
||||||
schemas(
|
schemas(
|
||||||
handlers::AddTorrentRequest,
|
shared::AddTorrentRequest,
|
||||||
shared::TorrentActionRequest,
|
shared::TorrentActionRequest,
|
||||||
shared::Torrent,
|
shared::Torrent,
|
||||||
shared::TorrentStatus,
|
shared::TorrentStatus,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use leptos::*;
|
use leptos::*;
|
||||||
use leptos::html::Dialog;
|
use leptos::html::Dialog;
|
||||||
use crate::store::{show_toast_with_signal, TorrentStore};
|
use crate::store::{show_toast_with_signal, TorrentStore};
|
||||||
use shared::NotificationLevel;
|
use shared::{AddTorrentRequest, NotificationLevel};
|
||||||
|
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
@@ -36,9 +36,7 @@ pub fn AddTorrentModal(
|
|||||||
set_error_msg.set(None);
|
set_error_msg.set(None);
|
||||||
|
|
||||||
spawn_local(async move {
|
spawn_local(async move {
|
||||||
let req_body = serde_json::json!({
|
let req_body = AddTorrentRequest { uri: uri_val };
|
||||||
"uri": uri_val
|
|
||||||
});
|
|
||||||
|
|
||||||
match gloo_net::http::Request::post("/api/torrents/add")
|
match gloo_net::http::Request::post("/api/torrents/add")
|
||||||
.json(&req_body)
|
.json(&req_body)
|
||||||
|
|||||||
@@ -130,3 +130,9 @@ pub struct SetLabelRequest {
|
|||||||
pub hash: String,
|
pub hash: String,
|
||||||
pub label: String,
|
pub label: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone, ToSchema)]
|
||||||
|
pub struct AddTorrentRequest {
|
||||||
|
#[schema(example = "magnet:?xt=urn:btih:...")]
|
||||||
|
pub uri: String,
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user