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
|
all: sign-release sign-debug
|
||||||
|
|
||||||
|
@PHONY: webui-dev
|
||||||
|
webui-dev:
|
||||||
|
cd crates/librqbit/webui && \
|
||||||
|
tsc --watch
|
||||||
|
|
||||||
@PHONY: clean
|
@PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -rf target
|
rm -rf target
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ use serde::{Deserialize, Serialize};
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
use tower_http::cors::{AllowHeaders, AllowOrigin};
|
|
||||||
use tracing::{info, warn};
|
use tracing::{info, warn};
|
||||||
|
|
||||||
use axum::Router;
|
use axum::Router;
|
||||||
|
|
@ -118,6 +117,7 @@ impl HttpApi {
|
||||||
state.api_peer_stats(idx, filter).map(axum::Json)
|
state.api_peer_stats(idx, filter).map(axum::Json)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused_mut)]
|
||||||
let mut app = Router::new()
|
let mut app = Router::new()
|
||||||
.route("/", get(api_root))
|
.route("/", get(api_root))
|
||||||
.route("/dht/stats", get(dht_stats))
|
.route("/dht/stats", get(dht_stats))
|
||||||
|
|
@ -150,18 +150,18 @@ impl HttpApi {
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
let cors_layer = {
|
// This is to develop webui by just doing "open index.html && tsc --watch"
|
||||||
#[cfg(debug_assertions)]
|
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()
|
tower_http::cors::CorsLayer::default()
|
||||||
.allow_origin(AllowOrigin::predicate(|_, _| true))
|
.allow_origin(AllowOrigin::predicate(|_, _| true))
|
||||||
.allow_headers(AllowHeaders::any())
|
.allow_headers(AllowHeaders::any())
|
||||||
}
|
})
|
||||||
#[cfg(not(debug_assertions))]
|
.unwrap_or_default();
|
||||||
{
|
|
||||||
tower_http::cors::CorsLayer::default()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
app = app.nest("/web/", webui_router).layer(cors_layer);
|
app = app.nest("/web/", webui_router).layer(cors_layer);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
// Define API URL and base path
|
// 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)
|
// Helper function for making API requests (async/await)
|
||||||
async function makeRequest(method, path, data) {
|
async function makeRequest(method, path, data) {
|
||||||
|
|
@ -99,10 +99,7 @@ async function displayTorrents() {
|
||||||
}
|
}
|
||||||
// Replace the old content with the new one
|
// Replace the old content with the new one
|
||||||
const outputDiv = document.getElementById('output');
|
const outputDiv = document.getElementById('output');
|
||||||
if (outputDiv) {
|
outputDiv.replaceChildren(torrentsContainer);
|
||||||
outputDiv.innerHTML = '';
|
|
||||||
outputDiv.appendChild(torrentsContainer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
@ -170,7 +167,7 @@ function clearErrorAlert() {
|
||||||
async function init() {
|
async function init() {
|
||||||
try {
|
try {
|
||||||
await displayTorrents();
|
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) {
|
catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
// Define API URL and base path
|
// 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 for the Torrent API response
|
||||||
interface Torrent {
|
interface Torrent {
|
||||||
|
|
@ -149,10 +149,8 @@ async function displayTorrents(): Promise<void> {
|
||||||
|
|
||||||
// Replace the old content with the new one
|
// Replace the old content with the new one
|
||||||
const outputDiv = document.getElementById('output');
|
const outputDiv = document.getElementById('output');
|
||||||
if (outputDiv) {
|
outputDiv.innerHTML = '';
|
||||||
outputDiv.innerHTML = '';
|
outputDiv.appendChild(torrentsContainer);
|
||||||
outputDiv.appendChild(torrentsContainer);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue