Compare commits
7 Commits
release-20
...
release-20
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
518af10cd7 | ||
|
|
0304c5cb7d | ||
|
|
cee609700a | ||
|
|
a9de8aeb5a | ||
|
|
79a88306c3 | ||
|
|
96ca09b9bd | ||
|
|
4d88660d91 |
@@ -25,9 +25,7 @@ pub fn App() -> impl IntoView {
|
|||||||
match setup_res {
|
match setup_res {
|
||||||
Ok(status) => {
|
Ok(status) => {
|
||||||
if !status.completed {
|
if !status.completed {
|
||||||
log::info!("Setup not completed, redirecting to /setup");
|
log::info!("Setup not completed");
|
||||||
let navigate = use_navigate();
|
|
||||||
navigate("/setup", Default::default());
|
|
||||||
is_loading.1.set(false);
|
is_loading.1.set(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -48,27 +46,12 @@ pub fn App() -> impl IntoView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
is_authenticated.1.set(true);
|
is_authenticated.1.set(true);
|
||||||
|
|
||||||
let pathname = window().location().pathname().unwrap_or_default();
|
|
||||||
if pathname == "/login" || pathname == "/setup" {
|
|
||||||
log::info!("Already authenticated, redirecting to home");
|
|
||||||
let navigate = use_navigate();
|
|
||||||
navigate("/", Default::default());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(false) => {
|
Ok(false) => {
|
||||||
log::info!("Not authenticated");
|
log::info!("Not authenticated");
|
||||||
|
|
||||||
let pathname = window().location().pathname().unwrap_or_default();
|
|
||||||
if pathname != "/login" && pathname != "/setup" {
|
|
||||||
let navigate = use_navigate();
|
|
||||||
navigate("/login", Default::default());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("Auth check failed: {:?}", e);
|
log::error!("Auth check failed: {:?}", e);
|
||||||
let navigate = use_navigate();
|
|
||||||
navigate("/login", Default::default());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,10 +75,39 @@ pub fn App() -> impl IntoView {
|
|||||||
<div class="relative w-full h-screen" style="height: 100dvh;">
|
<div class="relative w-full h-screen" style="height: 100dvh;">
|
||||||
<Router>
|
<Router>
|
||||||
<Routes fallback=|| view! { <div class="p-4">"404 Not Found"</div> }>
|
<Routes fallback=|| view! { <div class="p-4">"404 Not Found"</div> }>
|
||||||
<Route path=leptos_router::path!("/login") view=move || view! { <Login /> } />
|
<Route path=leptos_router::path!("/login") view=move || {
|
||||||
<Route path=leptos_router::path!("/setup") view=move || view! { <Setup /> } />
|
let authenticated = is_authenticated.0.get();
|
||||||
|
|
||||||
|
Effect::new(move |_| {
|
||||||
|
if authenticated {
|
||||||
|
log::info!("Already authenticated, redirecting to home");
|
||||||
|
let navigate = use_navigate();
|
||||||
|
navigate("/", Default::default());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
view! { <Login /> }
|
||||||
|
} />
|
||||||
|
<Route path=leptos_router::path!("/setup") view=move || {
|
||||||
|
Effect::new(move |_| {
|
||||||
|
if is_authenticated.0.get() {
|
||||||
|
let navigate = use_navigate();
|
||||||
|
navigate("/", Default::default());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
view! { <Setup /> }
|
||||||
|
} />
|
||||||
|
|
||||||
<Route path=leptos_router::path!("/") view=move || {
|
<Route path=leptos_router::path!("/") view=move || {
|
||||||
|
Effect::new(move |_| {
|
||||||
|
if !is_loading.0.get() && !is_authenticated.0.get() {
|
||||||
|
log::info!("Not authenticated, redirecting to login");
|
||||||
|
let navigate = use_navigate();
|
||||||
|
navigate("/login", Default::default());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
<Show when=move || !is_loading.0.get() fallback=|| view! {
|
<Show when=move || !is_loading.0.get() fallback=|| view! {
|
||||||
<div class="flex items-center justify-center h-screen bg-base-100">
|
<div class="flex items-center justify-center h-screen bg-base-100">
|
||||||
@@ -112,6 +124,13 @@ pub fn App() -> impl IntoView {
|
|||||||
}/>
|
}/>
|
||||||
|
|
||||||
<Route path=leptos_router::path!("/settings") view=move || {
|
<Route path=leptos_router::path!("/settings") view=move || {
|
||||||
|
Effect::new(move |_| {
|
||||||
|
if !is_authenticated.0.get() {
|
||||||
|
let navigate = use_navigate();
|
||||||
|
navigate("/login", Default::default());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
<Show when=move || !is_loading.0.get() fallback=|| ()>
|
<Show when=move || !is_loading.0.get() fallback=|| ()>
|
||||||
<Show when=move || is_authenticated.0.get() fallback=|| ()>
|
<Show when=move || is_authenticated.0.get() fallback=|| ()>
|
||||||
@@ -128,4 +147,4 @@ pub fn App() -> impl IntoView {
|
|||||||
<ToastContainer />
|
<ToastContainer />
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,44 +51,49 @@ pub fn TorrentTable() -> impl IntoView {
|
|||||||
let sort_dir = signal(SortDirection::Descending);
|
let sort_dir = signal(SortDirection::Descending);
|
||||||
|
|
||||||
let filtered_hashes = move || {
|
let filtered_hashes = move || {
|
||||||
store.torrents.with(|map| {
|
let torrents_map = store.torrents.get();
|
||||||
let mut torrents: Vec<&shared::Torrent> = map.values().filter(|t| {
|
log::debug!("TorrentTable: store.torrents has {} entries", torrents_map.len());
|
||||||
let filter = store.filter.get();
|
|
||||||
let search = store.search_query.get().to_lowercase();
|
let filter = store.filter.get();
|
||||||
let matches_filter = match filter {
|
let search = store.search_query.get();
|
||||||
crate::store::FilterStatus::All => true,
|
let search_lower = search.to_lowercase();
|
||||||
crate::store::FilterStatus::Downloading => t.status == shared::TorrentStatus::Downloading,
|
|
||||||
crate::store::FilterStatus::Seeding => t.status == shared::TorrentStatus::Seeding,
|
let mut torrents: Vec<&shared::Torrent> = torrents_map.values().filter(|t| {
|
||||||
crate::store::FilterStatus::Completed => t.status == shared::TorrentStatus::Seeding || (t.status == shared::TorrentStatus::Paused && t.percent_complete >= 100.0),
|
let matches_filter = match filter {
|
||||||
crate::store::FilterStatus::Paused => t.status == shared::TorrentStatus::Paused,
|
crate::store::FilterStatus::All => true,
|
||||||
crate::store::FilterStatus::Inactive => t.status == shared::TorrentStatus::Paused || t.status == shared::TorrentStatus::Error,
|
crate::store::FilterStatus::Downloading => t.status == shared::TorrentStatus::Downloading,
|
||||||
_ => true,
|
crate::store::FilterStatus::Seeding => t.status == shared::TorrentStatus::Seeding,
|
||||||
};
|
crate::store::FilterStatus::Completed => t.status == shared::TorrentStatus::Seeding || (t.status == shared::TorrentStatus::Paused && t.percent_complete >= 100.0),
|
||||||
let matches_search = if search.is_empty() { true } else { t.name.to_lowercase().contains(&search) };
|
crate::store::FilterStatus::Paused => t.status == shared::TorrentStatus::Paused,
|
||||||
matches_filter && matches_search
|
crate::store::FilterStatus::Inactive => t.status == shared::TorrentStatus::Paused || t.status == shared::TorrentStatus::Error,
|
||||||
}).collect();
|
_ => true,
|
||||||
|
};
|
||||||
|
let matches_search = if search_lower.is_empty() { true } else { t.name.to_lowercase().contains(&search_lower) };
|
||||||
|
matches_filter && matches_search
|
||||||
|
}).collect();
|
||||||
|
|
||||||
torrents.sort_by(|a, b| {
|
log::debug!("TorrentTable: {} torrents after filtering", torrents.len());
|
||||||
let col = sort_col.0.get();
|
|
||||||
let dir = sort_dir.0.get();
|
torrents.sort_by(|a, b| {
|
||||||
let cmp = match col {
|
let col = sort_col.0.get();
|
||||||
SortColumn::Name => a.name.to_lowercase().cmp(&b.name.to_lowercase()),
|
let dir = sort_dir.0.get();
|
||||||
SortColumn::Size => a.size.cmp(&b.size),
|
let cmp = match col {
|
||||||
SortColumn::Progress => a.percent_complete.partial_cmp(&b.percent_complete).unwrap_or(std::cmp::Ordering::Equal),
|
SortColumn::Name => a.name.to_lowercase().cmp(&b.name.to_lowercase()),
|
||||||
SortColumn::Status => format!("{:?}", a.status).cmp(&format!("{:?}", b.status)),
|
SortColumn::Size => a.size.cmp(&b.size),
|
||||||
SortColumn::DownSpeed => a.down_rate.cmp(&b.down_rate),
|
SortColumn::Progress => a.percent_complete.partial_cmp(&b.percent_complete).unwrap_or(std::cmp::Ordering::Equal),
|
||||||
SortColumn::UpSpeed => a.up_rate.cmp(&b.up_rate),
|
SortColumn::Status => format!("{:?}", a.status).cmp(&format!("{:?}", b.status)),
|
||||||
SortColumn::ETA => {
|
SortColumn::DownSpeed => a.down_rate.cmp(&b.down_rate),
|
||||||
let a_eta = if a.eta <= 0 { i64::MAX } else { a.eta };
|
SortColumn::UpSpeed => a.up_rate.cmp(&b.up_rate),
|
||||||
let b_eta = if b.eta <= 0 { i64::MAX } else { b.eta };
|
SortColumn::ETA => {
|
||||||
a_eta.cmp(&b_eta)
|
let a_eta = if a.eta <= 0 { i64::MAX } else { a.eta };
|
||||||
}
|
let b_eta = if b.eta <= 0 { i64::MAX } else { b.eta };
|
||||||
SortColumn::AddedDate => a.added_date.cmp(&b.added_date),
|
a_eta.cmp(&b_eta)
|
||||||
};
|
}
|
||||||
if dir == SortDirection::Descending { cmp.reverse() } else { cmp }
|
SortColumn::AddedDate => a.added_date.cmp(&b.added_date),
|
||||||
});
|
};
|
||||||
torrents.into_iter().map(|t| t.hash.clone()).collect::<Vec<String>>()
|
if dir == SortDirection::Descending { cmp.reverse() } else { cmp }
|
||||||
})
|
});
|
||||||
|
torrents.into_iter().map(|t| t.hash.clone()).collect::<Vec<String>>()
|
||||||
};
|
};
|
||||||
|
|
||||||
let handle_sort = move |col: SortColumn| {
|
let handle_sort = move |col: SortColumn| {
|
||||||
|
|||||||
@@ -114,7 +114,9 @@ pub fn provide_torrent_store() {
|
|||||||
|
|
||||||
Effect::new(move |_| {
|
Effect::new(move |_| {
|
||||||
let user_val = user.get();
|
let user_val = user.get();
|
||||||
|
log::debug!("SSE Effect: user = {:?}", user_val);
|
||||||
if user_val.is_none() {
|
if user_val.is_none() {
|
||||||
|
log::debug!("SSE Effect: user is None, skipping connection");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,12 +133,16 @@ pub fn provide_torrent_store() {
|
|||||||
let mut disconnect_notified = false;
|
let mut disconnect_notified = false;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
log::debug!("SSE: Creating EventSource...");
|
||||||
let es_result = EventSource::new("/api/events");
|
let es_result = EventSource::new("/api/events");
|
||||||
match es_result {
|
match es_result {
|
||||||
Ok(mut es) => {
|
Ok(mut es) => {
|
||||||
|
log::debug!("SSE: EventSource created, subscribing to message channel...");
|
||||||
if let Ok(mut stream) = es.subscribe("message") {
|
if let Ok(mut stream) = es.subscribe("message") {
|
||||||
|
log::debug!("SSE: Subscribed to message channel");
|
||||||
let mut got_first_message = false;
|
let mut got_first_message = false;
|
||||||
while let Some(Ok((_, msg))) = stream.next().await {
|
while let Some(Ok((_, msg))) = stream.next().await {
|
||||||
|
log::debug!("SSE: Received message: {:?}", msg.data());
|
||||||
if !got_first_message {
|
if !got_first_message {
|
||||||
got_first_message = true;
|
got_first_message = true;
|
||||||
backoff_ms = 1000;
|
backoff_ms = 1000;
|
||||||
@@ -148,9 +154,11 @@ pub fn provide_torrent_store() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(data_str) = msg.data().as_string() {
|
if let Some(data_str) = msg.data().as_string() {
|
||||||
|
log::debug!("SSE: Parsing JSON: {}", data_str);
|
||||||
if let Ok(event) = serde_json::from_str::<AppEvent>(&data_str) {
|
if let Ok(event) = serde_json::from_str::<AppEvent>(&data_str) {
|
||||||
match event {
|
match event {
|
||||||
AppEvent::FullList { torrents: list, .. } => {
|
AppEvent::FullList { torrents: list, .. } => {
|
||||||
|
log::info!("SSE: Received FullList with {} torrents", list.len());
|
||||||
torrents.update(|map| {
|
torrents.update(|map| {
|
||||||
let new_hashes: std::collections::HashSet<String> = list.iter().map(|t| t.hash.clone()).collect();
|
let new_hashes: std::collections::HashSet<String> = list.iter().map(|t| t.hash.clone()).collect();
|
||||||
map.retain(|hash, _| new_hashes.contains(hash));
|
map.retain(|hash, _| new_hashes.contains(hash));
|
||||||
@@ -158,6 +166,7 @@ pub fn provide_torrent_store() {
|
|||||||
map.insert(new_torrent.hash.clone(), new_torrent);
|
map.insert(new_torrent.hash.clone(), new_torrent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
log::debug!("SSE: torrents map now has {} entries", torrents.with(|m| m.len()));
|
||||||
}
|
}
|
||||||
AppEvent::Update(update) => {
|
AppEvent::Update(update) => {
|
||||||
torrents.update(|map| {
|
torrents.update(|map| {
|
||||||
|
|||||||
Reference in New Issue
Block a user