MCPcopy Create free account
hub / github.com/ParzivalHack/PySpector / scan

Function scan

src/main.rs:19–151  ·  view source on GitHub ↗
(req: web::Json<ScanRequest>)

Source from the content-addressed store, hash-verified

17
18#[post("/scan")]
19async fn scan(req: web::Json<ScanRequest>) -> impl Responder {
20 if req.path.is_none() && req.url.is_none() {
21 return HttpResponse::BadRequest().body("Either 'path' or 'url' must be provided.");
22 }
23 if req.path.is_some() && req.url.is_some() {
24 return HttpResponse::BadRequest().body("Cannot provide both 'path' and 'url'.");
25 }
26
27 let json_output = req.json_output;
28 let ai = req.ai;
29 let url = req.url.clone();
30 let path = req.path.clone();
31
32 let scan_result = web::block(move || {
33 let mut temp_dir_path: Option<String> = None;
34 let target_path = if let Some(u) = &url {
35 let timestamp = std::time::SystemTime::now()
36 .duration_since(std::time::UNIX_EPOCH)
37 .unwrap()
38 .as_nanos();
39 let temp_path = format!("/tmp/pyspector_scan_{}", timestamp);
40
41 let output = Command::new("git")
42 .args(&["clone", "--depth", "1", u, &temp_path])
43 .output();
44
45 match output {
46 Ok(o) if o.status.success() => {
47 temp_dir_path = Some(temp_path.clone());
48 temp_path
49 }
50 Ok(o) => {
51 let stderr = String::from_utf8_lossy(&o.stderr);
52 return Err(format!("Failed to clone repository: {}", stderr));
53 }
54 Err(e) => return Err(format!("Failed to execute git clone: {}", e)),
55 }
56 } else {
57 path.clone().unwrap()
58 };
59
60 let result = Python::attach(|py| -> Result<String, String> {
61 // Import the required modules
62 let pyspector_cli = py.import("pyspector.cli").map_err(|e| {
63 format!("Failed to import pyspector.cli: {}. Is PySpector installed?", e)
64 })?;
65
66 let pyspector_config = py.import("pyspector.config").map_err(|e| {
67 format!("Failed to import pyspector.config: {}", e)
68 })?;
69
70 let pyspector_reporting = py.import("pyspector.reporting").map_err(|e| {
71 format!("Failed to import pyspector.reporting: {}", e)
72 })?;
73
74 let pyspector_rust_core = py.import("pyspector._rust_core").map_err(|e| {
75 format!("Failed to import pyspector._rust_core: {}", e)
76 })?;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected