opendal/services/vercel_blob/
lister.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18use std::sync::Arc;
19
20use super::core::parse_blob;
21use super::core::VercelBlobCore;
22use crate::raw::oio::Entry;
23use crate::raw::*;
24use crate::Result;
25
26pub struct VercelBlobLister {
27    core: Arc<VercelBlobCore>,
28
29    path: String,
30    limit: Option<usize>,
31}
32
33impl VercelBlobLister {
34    pub(super) fn new(core: Arc<VercelBlobCore>, path: &str, limit: Option<usize>) -> Self {
35        VercelBlobLister {
36            core,
37            path: path.to_string(),
38            limit,
39        }
40    }
41}
42
43impl oio::PageList for VercelBlobLister {
44    async fn next_page(&self, ctx: &mut oio::PageContext) -> Result<()> {
45        let p = build_abs_path(&self.core.root, &self.path);
46
47        let resp = self.core.list(&p, self.limit).await?;
48
49        ctx.done = !resp.has_more;
50
51        if let Some(cursor) = resp.cursor {
52            ctx.token = cursor;
53        }
54
55        for blob in resp.blobs {
56            let path = build_rel_path(&self.core.root, &blob.pathname);
57
58            if path == self.path {
59                continue;
60            }
61
62            let md = parse_blob(&blob)?;
63
64            ctx.entries.push_back(Entry::new(&path, md));
65        }
66
67        Ok(())
68    }
69}