Fix a couple bugs
This commit is contained in:
parent
1bea1f9235
commit
1c53aeba2f
6 changed files with 57 additions and 30 deletions
|
|
@ -38,7 +38,11 @@ impl HttpApi {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn make_http_api_and_run(self, addr: SocketAddr) -> anyhow::Result<()> {
|
||||
pub async fn make_http_api_and_run(
|
||||
self,
|
||||
addr: SocketAddr,
|
||||
read_only: bool,
|
||||
) -> anyhow::Result<()> {
|
||||
let state = self.inner;
|
||||
|
||||
async fn api_root() -> impl IntoResponse {
|
||||
|
|
@ -160,22 +164,26 @@ impl HttpApi {
|
|||
state.api_set_rust_log(new_value).map(axum::Json)
|
||||
}
|
||||
|
||||
#[allow(unused_mut)]
|
||||
let mut app = Router::new()
|
||||
.route("/", get(api_root))
|
||||
.route("/rust_log", post(set_rust_log))
|
||||
.route("/dht/stats", get(dht_stats))
|
||||
.route("/dht/table", get(dht_table))
|
||||
.route("/torrents", get(torrents_list).post(torrents_post))
|
||||
.route("/torrents", get(torrents_list))
|
||||
.route("/torrents/:id", get(torrent_details))
|
||||
.route("/torrents/:id/haves", get(torrent_haves))
|
||||
.route("/torrents/:id/stats", get(torrent_stats_v0))
|
||||
.route("/torrents/:id/stats/v1", get(torrent_stats_v1))
|
||||
.route("/torrents/:id/peer_stats", get(peer_stats))
|
||||
.route("/torrents/:id/pause", post(torrent_action_pause))
|
||||
.route("/torrents/:id/start", post(torrent_action_start))
|
||||
.route("/torrents/:id/forget", post(torrent_action_forget))
|
||||
.route("/torrents/:id/delete", post(torrent_action_delete))
|
||||
.route("/rust_log", post(set_rust_log));
|
||||
.route("/torrents/:id/peer_stats", get(peer_stats));
|
||||
|
||||
if !read_only {
|
||||
app = app
|
||||
.route("/torrents", post(torrents_post))
|
||||
.route("/torrents/:id/pause", post(torrent_action_pause))
|
||||
.route("/torrents/:id/start", post(torrent_action_start))
|
||||
.route("/torrents/:id/forget", post(torrent_action_forget))
|
||||
.route("/torrents/:id/delete", post(torrent_action_delete));
|
||||
}
|
||||
|
||||
#[cfg(feature = "webui")]
|
||||
{
|
||||
|
|
|
|||
|
|
@ -210,6 +210,8 @@ pub struct SessionOptions {
|
|||
pub disable_dht: bool,
|
||||
pub disable_dht_persistence: bool,
|
||||
pub persistence: bool,
|
||||
// Will default to output_folder/.rqbit-session.json
|
||||
pub persistence_filename: Option<PathBuf>,
|
||||
pub dht_config: Option<PersistentDhtConfig>,
|
||||
pub peer_id: Option<Id20>,
|
||||
pub peer_opts: Option<PeerConnectionOptions>,
|
||||
|
|
@ -240,7 +242,9 @@ impl Session {
|
|||
Some(dht)
|
||||
};
|
||||
let peer_opts = opts.peer_opts.unwrap_or_default();
|
||||
let session_filename = output_folder.join(".rqbit-session.json");
|
||||
let session_filename = opts
|
||||
.persistence_filename
|
||||
.unwrap_or_else(|| output_folder.join(".rqbit-session.json"));
|
||||
let session = Arc::new(Self {
|
||||
persistence_filename: session_filename,
|
||||
peer_id,
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ impl Serialize for Speed {
|
|||
}
|
||||
Tmp {
|
||||
mbps: self.mbps,
|
||||
human_readable: format!("{:?}", self.mbps),
|
||||
human_readable: format!("{}", self),
|
||||
}
|
||||
.serialize(serializer)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue