qualia_cli/handlers/
solid.rs1use std::path::PathBuf;
2
3use crate::cli::SolidAction;
4
5pub async fn handle(action: SolidAction) {
6 match action {
7 SolidAction::Serve {
8 host,
9 port,
10 data_root,
11 public_base,
12 demo_oidc,
13 no_demo_oidc,
14 } => {
15 let data_root = data_root.unwrap_or_else(|| {
16 std::env::var("QUALIA_SOLID_POD_ROOT")
17 .map(PathBuf::from)
18 .unwrap_or_else(|_| std::env::temp_dir().join("qualia-solid-pod"))
19 });
20 let public_base = public_base.unwrap_or_else(|| format!("http://{host}:{port}"));
21 let cfg = qualia_solid_bridge::BridgeConfig {
22 listen: format!("{host}:{port}").parse().expect("invalid host:port"),
23 data_root,
24 public_base,
25 demo_oidc: demo_oidc && !no_demo_oidc,
26 };
27 qualia_solid_bridge::run_bridge(cfg).await;
28 }
29 SolidAction::Fetch { url, token, out } => {
30 match qualia_solid_bridge::fetch_resource(&url, token.as_deref()).await {
31 Ok(r) => {
32 println!("status : {}", r.status);
33 println!("content-type : {}", r.content_type);
34 println!("quin_count : {}", r.quin_count);
35 println!("url : {}", r.url);
36 if let Some(path) = out {
37 if let Err(e) = std::fs::write(&path, r.body.as_bytes()) {
38 eprintln!("write {}: {e}", path.display());
39 } else {
40 println!("wrote : {}", path.display());
41 }
42 } else {
43 let preview: String = r.body.chars().take(800).collect();
44 println!("--- body (preview) ---\n{preview}");
45 }
46 }
47 Err(e) => eprintln!("solid fetch failed: {e}"),
48 }
49 }
50 SolidAction::Put {
51 url,
52 file,
53 content_type,
54 token,
55 } => match std::fs::read(&file) {
56 Ok(body) => {
57 match qualia_solid_bridge::put_resource(
58 &url,
59 &body,
60 &content_type,
61 token.as_deref(),
62 )
63 .await
64 {
65 Ok(status) => println!("PUT ok status={status} url={url}"),
66 Err(e) => eprintln!("solid put failed: {e}"),
67 }
68 }
69 Err(e) => eprintln!("read {}: {e}", file.display()),
70 },
71 SolidAction::Post {
72 container,
73 file,
74 content_type,
75 slug,
76 token,
77 } => match std::fs::read(&file) {
78 Ok(body) => {
79 match qualia_solid_bridge::post_to_container(
80 &container,
81 &body,
82 &content_type,
83 slug.as_deref(),
84 token.as_deref(),
85 )
86 .await
87 {
88 Ok((status, loc)) => {
89 println!("POST ok status={status}");
90 if let Some(l) = loc {
91 println!("location={l}");
92 }
93 }
94 Err(e) => eprintln!("solid post failed: {e}"),
95 }
96 }
97 Err(e) => eprintln!("read {}: {e}", file.display()),
98 },
99 }
100}