More chatgpt modifications
This commit is contained in:
parent
88ca5960df
commit
aef1ffbd90
4 changed files with 21 additions and 21 deletions
5
Makefile
5
Makefile
|
|
@ -2,6 +2,11 @@ OPENSSL_VERSION=3.1.1
|
|||
|
||||
all: sign-release sign-debug
|
||||
|
||||
@PHONY: webui-dev
|
||||
webui-dev:
|
||||
cd crates/librqbit/webui && \
|
||||
tsc --watch
|
||||
|
||||
@PHONY: clean
|
||||
clean:
|
||||
rm -rf target
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ use serde::{Deserialize, Serialize};
|
|||
use std::net::SocketAddr;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
use tower_http::cors::{AllowHeaders, AllowOrigin};
|
||||
use tracing::{info, warn};
|
||||
|
||||
use axum::Router;
|
||||
|
|
@ -118,6 +117,7 @@ impl HttpApi {
|
|||
state.api_peer_stats(idx, filter).map(axum::Json)
|
||||
}
|
||||
|
||||
#[allow(unused_mut)]
|
||||
let mut app = Router::new()
|
||||
.route("/", get(api_root))
|
||||
.route("/dht/stats", get(dht_stats))
|
||||
|
|
@ -150,18 +150,18 @@ impl HttpApi {
|
|||
}),
|
||||
);
|
||||
|
||||
let cors_layer = {
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
// This is to develop webui by just doing "open index.html && tsc --watch"
|
||||
let cors_layer = std::env::var("CORS_DEBUG")
|
||||
.ok()
|
||||
.map(|_| {
|
||||
use tower_http::cors::{AllowHeaders, AllowOrigin};
|
||||
|
||||
warn!("CorsLayer: allowing everything because CORS_DEBUG is set");
|
||||
tower_http::cors::CorsLayer::default()
|
||||
.allow_origin(AllowOrigin::predicate(|_, _| true))
|
||||
.allow_headers(AllowHeaders::any())
|
||||
}
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
tower_http::cors::CorsLayer::default()
|
||||
}
|
||||
};
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
app = app.nest("/web/", webui_router).layer(cors_layer);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// Define API URL and base path
|
||||
const apiUrl = window.origin == null ? 'http://localhost:3030' : '';
|
||||
const apiUrl = window.origin == 'null' ? 'http://localhost:3030' : '';
|
||||
|
||||
// Helper function for making API requests (async/await)
|
||||
async function makeRequest(method, path, data) {
|
||||
|
|
@ -99,10 +99,7 @@ async function displayTorrents() {
|
|||
}
|
||||
// Replace the old content with the new one
|
||||
const outputDiv = document.getElementById('output');
|
||||
if (outputDiv) {
|
||||
outputDiv.innerHTML = '';
|
||||
outputDiv.appendChild(torrentsContainer);
|
||||
}
|
||||
outputDiv.replaceChildren(torrentsContainer);
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
|
|
@ -170,7 +167,7 @@ function clearErrorAlert() {
|
|||
async function init() {
|
||||
try {
|
||||
await displayTorrents();
|
||||
autoRefreshTorrents(5000); // Set the interval (in milliseconds), e.g., 5000 for every 5 seconds
|
||||
autoRefreshTorrents(500); // Set the interval (in milliseconds), e.g., 5000 for every 5 seconds
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// Define API URL and base path
|
||||
const apiUrl = 'http://localhost:3030';
|
||||
const apiUrl = window.origin == 'null' ? 'http://localhost:3030' : '';
|
||||
|
||||
// Interface for the Torrent API response
|
||||
interface Torrent {
|
||||
|
|
@ -149,10 +149,8 @@ async function displayTorrents(): Promise<void> {
|
|||
|
||||
// Replace the old content with the new one
|
||||
const outputDiv = document.getElementById('output');
|
||||
if (outputDiv) {
|
||||
outputDiv.innerHTML = '';
|
||||
outputDiv.appendChild(torrentsContainer);
|
||||
}
|
||||
outputDiv.innerHTML = '';
|
||||
outputDiv.appendChild(torrentsContainer);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue