use std::sync::Arc;
use http::StatusCode;
use super::core::*;
use super::error::*;
use opendal_core::raw::oio;
use opendal_core::raw::*;
use opendal_core::*;
pub struct WebdavLister {
core: Arc<WebdavCore>,
path: String,
args: OpList,
}
impl WebdavLister {
pub fn new(core: Arc<WebdavCore>, path: &str, args: OpList) -> Self {
Self {
core,
path: path.to_string(),
args,
}
}
}
impl oio::PageList for WebdavLister {
async fn next_page(&self, ctx: &mut oio::PageContext) -> Result<()> {
let resp = self.core.webdav_list(&self.path, &self.args).await?;
let is_jfrog_artifactory = if let Some(v) = resp.headers().get("x-jfrog-version") {
v.to_str().unwrap_or_default().starts_with("Artifactory")
} else {
false
};
let bs = if resp.status().is_success() {
resp.into_body()
} else if resp.status() == StatusCode::NOT_FOUND && self.path.ends_with('/') {
ctx.done = true;
return Ok(());
} else {
return Err(parse_error(resp));
};
let result: Multistatus = deserialize_multistatus(&bs.to_bytes())?;
for res in result.response {
let mut path = res
.href
.strip_prefix(&self.core.server_path)
.unwrap_or(&res.href)
.to_string();
let meta = parse_propstat(&res.propstat)?;
if !path.ends_with('/') && meta.is_dir() {
path += "/"
}
let decoded_path = percent_decode_path(&path);
let normalized_path = if self.core.root != decoded_path {
build_rel_path(&self.core.root, &decoded_path)
} else {
"/".to_owned()
};
if is_jfrog_artifactory && meta.content_type() == Some("application/x-checksum") {
continue;
}
ctx.entries
.push_back(oio::Entry::new(&normalized_path, meta))
}
ctx.done = true;
Ok(())
}
}