cloudpub_client/plugins/webdav/
mod.rs1use crate::config::{ClientConfig, ClientOpts};
2use crate::plugins::httpd::{setup_httpd, start_httpd};
3use crate::plugins::Plugin;
4use crate::shell::SubProcess;
5use anyhow::Result;
6use async_trait::async_trait;
7use cloudpub_common::protocol::message::Message;
8use cloudpub_common::protocol::ServerEndpoint;
9use parking_lot::RwLock;
10use std::sync::Arc;
11use tokio::sync::mpsc;
12
13const WEBDAV_CONFIG: &str = include_str!("httpd.conf");
14const WEBDAV_SUBDIR: &str = "webdav";
15
16pub struct WebdavPlugin;
17
18#[async_trait]
19impl Plugin for WebdavPlugin {
20 fn name(&self) -> &'static str {
21 "webdav"
22 }
23
24 async fn setup(
25 &self,
26 config: &Arc<RwLock<ClientConfig>>,
27 _opts: &ClientOpts,
28 command_rx: &mut mpsc::Receiver<Message>,
29 result_tx: &mpsc::Sender<Message>,
30 ) -> Result<()> {
31 setup_httpd(config, command_rx, result_tx, Default::default()).await
32 }
33
34 async fn publish(
35 &self,
36 endpoint: &ServerEndpoint,
37 _config: &Arc<RwLock<ClientConfig>>,
38 _opts: &ClientOpts,
39 result_tx: &mpsc::Sender<Message>,
40 ) -> Result<SubProcess> {
41 let publish_dir = endpoint.client.as_ref().unwrap().local_addr.clone();
44 let env = Default::default();
45
46 start_httpd(
47 endpoint,
48 WEBDAV_CONFIG,
49 WEBDAV_SUBDIR,
50 &publish_dir,
51 env,
52 result_tx.clone(),
53 )
54 .await
55 }
56}