2026-03-24 22:40:08 -04:00
|
|
|
pub mod database;
|
|
|
|
|
pub mod schema;
|
2026-03-21 22:03:03 -04:00
|
|
|
|
2026-03-24 22:40:08 -04:00
|
|
|
use xml_builder::{XMLBuilder, XMLElement, XMLVersion};
|
|
|
|
|
use actix_web::{get, post, web, App,
|
|
|
|
|
HttpResponse,
|
|
|
|
|
HttpServer,
|
|
|
|
|
http::header::ContentType,
|
|
|
|
|
Responder,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
use database::{ add_did,
|
|
|
|
|
list_did
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
async fn route_did() -> impl Responder {
|
|
|
|
|
let mut xml = XMLBuilder::new()
|
|
|
|
|
.version(XMLVersion::XML1_1)
|
|
|
|
|
.encoding("UTF-8".into())
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
let mut doc = XMLElement::new("document");
|
|
|
|
|
doc.add_attribute("type", "xml/freeswitch-httapi");
|
|
|
|
|
|
|
|
|
|
let params = XMLElement::new("params");
|
|
|
|
|
let mut work = XMLElement::new("work");
|
|
|
|
|
|
|
|
|
|
let mut playback = XMLElement::new("playback");
|
|
|
|
|
playback.add_attribute("name", "exten");
|
|
|
|
|
playback.add_attribute("file", "ivr/ivr-welcome_to_freeswitch.wav");
|
|
|
|
|
work.add_child(playback).unwrap();
|
|
|
|
|
|
|
|
|
|
doc.add_child(params).unwrap();
|
|
|
|
|
doc.add_child(work).unwrap();
|
|
|
|
|
|
|
|
|
|
xml.set_root_element(doc);
|
|
|
|
|
|
|
|
|
|
let mut writer: Vec<u8> = Vec::new();
|
|
|
|
|
xml.generate(&mut writer).unwrap();
|
|
|
|
|
|
|
|
|
|
HttpResponse::Ok()
|
|
|
|
|
.content_type(ContentType::xml())
|
|
|
|
|
.body(writer)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn did_post() -> impl Responder {
|
|
|
|
|
add_did().unwrap();
|
|
|
|
|
HttpResponse::Ok().body("DID added.")
|
2026-03-21 22:03:03 -04:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 22:40:08 -04:00
|
|
|
async fn did_index() -> impl Responder {
|
|
|
|
|
let dids = list_did().unwrap();
|
|
|
|
|
HttpResponse::Ok().json(dids)
|
2026-03-21 22:03:03 -04:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 22:40:08 -04:00
|
|
|
fn api_config(cfg: &mut web::ServiceConfig) {
|
|
|
|
|
cfg.service(
|
|
|
|
|
web::resource("/fs")
|
|
|
|
|
.route(web::get().to(did_index))
|
|
|
|
|
.route(web::post().to(did_post))
|
|
|
|
|
.route(web::patch().to(|| async { HttpResponse::Ok().body("did patch") }))
|
|
|
|
|
.route(web::delete().to(|| async { HttpResponse::Ok().body("did delete") }))
|
|
|
|
|
);
|
|
|
|
|
cfg.service(
|
|
|
|
|
web::resource("/fs/{id}")
|
|
|
|
|
.route(web::get().to(|| async { HttpResponse::Ok().body("did get")}))
|
|
|
|
|
.route(web::patch().to(|| async { HttpResponse::Ok().body("did patch")}))
|
|
|
|
|
.route(web::delete().to(|| async { HttpResponse::Ok().body("did delete")}))
|
|
|
|
|
);
|
|
|
|
|
cfg.service(
|
|
|
|
|
web::resource("/route_did")
|
|
|
|
|
.route(web::post().to(route_did))
|
|
|
|
|
);
|
2026-03-21 22:03:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[actix_web::main]
|
|
|
|
|
async fn main() -> std::io::Result<()> {
|
|
|
|
|
HttpServer::new(|| {
|
|
|
|
|
App::new()
|
2026-03-24 22:40:08 -04:00
|
|
|
.service(
|
|
|
|
|
web::scope("/api").configure(api_config))
|
2026-03-21 22:03:03 -04:00
|
|
|
})
|
2026-03-24 22:40:08 -04:00
|
|
|
.bind(("0.0.0.0", 3000))?
|
2026-03-21 22:03:03 -04:00
|
|
|
.run()
|
|
|
|
|
.await
|
|
|
|
|
}
|