-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(dav-server): Polish dav-server integration details
Signed-off-by: Xuanwo <[email protected]>
- Loading branch information
Showing
12 changed files
with
416 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,57 @@ | ||
# dav-server-opendalfs | ||
# Apache OpenDAL™ dav-server integration | ||
|
||
[`dav-server-opendalfs`](https://crates.io/crates/dav-server-opendalfs) is an integration which uses OpenDAL as a backend to access data in various service with WebDAV protocol. | ||
[![Build Status]][actions] [![Latest Version]][crates.io] [![Crate Downloads]][crates.io] [![chat]][discord] | ||
|
||
[build status]: https://img.shields.io/github/actions/workflow/status/apache/opendal/ci_integration_dav_server.yml?branch=main | ||
[actions]: https://github.com/apache/opendal/actions?query=branch%3Amain | ||
[latest version]: https://img.shields.io/crates/v/dav-server-opendalfs.svg | ||
[crates.io]: https://crates.io/crates/dav-server-opendalfs | ||
[crate downloads]: https://img.shields.io/crates/d/dav-server-opendalfs.svg | ||
[chat]: https://img.shields.io/discord/1081052318650339399 | ||
[discord]: https://opendal.apache.org/discord | ||
|
||
`dav-server-opendalfs` is an [`dav-server`](https://github.com/messense/dav-server-rs) implementation using opendal. | ||
|
||
This crate can help you to access ANY storage services with the same webdav API. | ||
|
||
## Useful Links | ||
|
||
- Documentation: [release](https://docs.rs/dav-server-opendalfs/) | [dev](https://opendal.apache.org/docs/dav-server-opendalfs/dav_server_opendalfs/) | ||
|
||
## Examples | ||
|
||
``` | ||
use anyhow::Result; | ||
use dav_server::davpath::DavPath; | ||
use dav_server::fs::DavFileSystem; | ||
use dav_server_opendalfs::OpendalFs; | ||
use opendal::services::Memory; | ||
use opendal::Operator; | ||
#[tokio::test] | ||
async fn test() -> Result<()> { | ||
let op = Operator::new(Memory::default())?.finish(); | ||
let webdavfs = OpendalFs::new(op); | ||
let metadata = webdavfs | ||
.metadata(&DavPath::new("/").unwrap()) | ||
.await | ||
.unwrap(); | ||
println!("{}", metadata.is_dir()); | ||
Ok(()) | ||
} | ||
``` | ||
|
||
## Branding | ||
|
||
The first and most prominent mentions must use the full form: **Apache OpenDAL™** of the name for any individual usage (webpage, handout, slides, etc.) Depending on the context and writing style, you should use the full form of the name sufficiently often to ensure that readers clearly understand the association of both the OpenDAL project and the OpenDAL software product to the ASF as the parent organization. | ||
|
||
For more details, see the [Apache Product Name Usage Guide](https://www.apache.org/foundation/marks/guide). | ||
|
||
## License and Trademarks | ||
|
||
Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Apache OpenDAL, OpenDAL, and Apache are either registered trademarks or trademarks of the Apache Software Foundation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use dav_server::fs::{DavDirEntry, DavMetaData}; | ||
use futures::StreamExt; | ||
use futures::{FutureExt, Stream}; | ||
use opendal::Operator; | ||
use opendal::{Entry, Lister}; | ||
use std::pin::Pin; | ||
use std::task::Poll::Ready; | ||
use std::task::{ready, Context, Poll}; | ||
|
||
use super::metadata::OpendalMetaData; | ||
use super::utils::*; | ||
|
||
/// OpendalStream is a stream of `DavDirEntry` that is used to list the contents of a directory. | ||
pub struct OpendalStream { | ||
op: Operator, | ||
lister: Lister, | ||
} | ||
|
||
impl OpendalStream { | ||
/// Create a new opendal stream. | ||
pub fn new(op: Operator, lister: Lister) -> Self { | ||
OpendalStream { op, lister } | ||
} | ||
} | ||
|
||
impl Stream for OpendalStream { | ||
type Item = Box<dyn DavDirEntry>; | ||
|
||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> { | ||
let dav_stream = self.get_mut(); | ||
match ready!(dav_stream.lister.poll_next_unpin(cx)) { | ||
Some(entry) => { | ||
let webdav_entry = OpendalDirEntry::new(dav_stream.op.clone(), entry.unwrap()); | ||
Ready(Some(Box::new(webdav_entry) as Box<dyn DavDirEntry>)) | ||
} | ||
None => Ready(None), | ||
} | ||
} | ||
} | ||
|
||
/// OpendalDirEntry is a `DavDirEntry` implementation for opendal. | ||
pub struct OpendalDirEntry { | ||
op: Operator, | ||
dir_entry: Entry, | ||
} | ||
|
||
impl OpendalDirEntry { | ||
/// Create a new opendal dir entry. | ||
pub fn new(op: Operator, dir_entry: Entry) -> Self { | ||
OpendalDirEntry { dir_entry, op } | ||
} | ||
} | ||
|
||
impl DavDirEntry for OpendalDirEntry { | ||
fn name(&self) -> Vec<u8> { | ||
self.dir_entry.name().as_bytes().to_vec() | ||
} | ||
|
||
fn metadata(&self) -> dav_server::fs::FsFuture<Box<dyn DavMetaData>> { | ||
async move { | ||
self.op | ||
.stat(self.dir_entry.path()) | ||
.await | ||
.map(|metadata| Box::new(OpendalMetaData::new(metadata)) as Box<dyn DavMetaData>) | ||
.map_err(convert_error) | ||
} | ||
.boxed() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.