mirror of
https://codeberg.org/YGGverse/psocks.git
synced 2026-04-01 00:45:27 +00:00
disallow server start if at least one list parsed with errors; add initial listing api
This commit is contained in:
parent
0b08744f8f
commit
752ea23f80
4 changed files with 111 additions and 36 deletions
26
src/main.rs
26
src/main.rs
|
|
@ -59,10 +59,30 @@ async fn api_block(
|
|||
#[rocket::get("/api/rules")]
|
||||
async fn api_rules(rules: &State<Arc<Rules>>) -> Result<Json<Vec<String>>, Status> {
|
||||
let active = rules.active().await;
|
||||
info!("Get rules (total: {})", active.len());
|
||||
debug!("Get rules (total: {})", active.len());
|
||||
Ok(Json(active))
|
||||
}
|
||||
|
||||
#[rocket::get("/api/lists")]
|
||||
async fn api_lists(rules: &State<Arc<Rules>>) -> Result<Json<Vec<rules::ListEntry>>, Status> {
|
||||
let lists = rules.lists();
|
||||
debug!("Get lists index (total: {})", lists.len());
|
||||
Ok(Json(lists))
|
||||
}
|
||||
|
||||
#[rocket::get("/api/list/<id>")]
|
||||
async fn api_list(
|
||||
id: usize,
|
||||
rules: &State<Arc<Rules>>,
|
||||
) -> Result<Json<Option<&rules::List>>, Status> {
|
||||
let list = rules.list(&id);
|
||||
debug!(
|
||||
"Get list #{id} rules (total: {:?})",
|
||||
list.map(|l| l.items.len())
|
||||
);
|
||||
Ok(Json(list))
|
||||
}
|
||||
|
||||
#[rocket::launch]
|
||||
async fn rocket() -> _ {
|
||||
env_logger::init();
|
||||
|
|
@ -94,7 +114,9 @@ async fn rocket() -> _ {
|
|||
.manage(Instant::now())
|
||||
.mount(
|
||||
"/",
|
||||
rocket::routes![index, api_totals, api_allow, api_block, api_rules],
|
||||
rocket::routes![
|
||||
index, api_totals, api_allow, api_block, api_rules, api_lists, api_list
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue