Skip to main content

browser_protocol/filesystem/
mod.rs

1use serde::{Serialize, Deserialize};
2use serde_json::Value as JsonValue;
3use std::borrow::Cow;
4
5
6#[derive(Debug, Clone, Serialize, Deserialize, Default)]
7#[serde(rename_all = "camelCase")]
8pub struct File<'a> {
9    name: Cow<'a, str>,
10    /// Timestamp
11    lastModified: crate::network::TimeSinceEpoch,
12    /// Size in bytes
13    size: f64,
14    #[serde(rename = "type")]
15    type_: Cow<'a, str>,
16}
17
18impl<'a> File<'a> {
19    pub fn builder(name: impl Into<Cow<'a, str>>, lastModified: crate::network::TimeSinceEpoch, size: f64, type_: impl Into<Cow<'a, str>>) -> FileBuilder<'a> {
20        FileBuilder {
21            name: name.into(),
22            lastModified: lastModified,
23            size: size,
24            type_: type_.into(),
25        }
26    }
27    pub fn name(&self) -> &str { self.name.as_ref() }
28    pub fn lastModified(&self) -> &crate::network::TimeSinceEpoch { &self.lastModified }
29    pub fn size(&self) -> f64 { self.size }
30    pub fn type_(&self) -> &str { self.type_.as_ref() }
31}
32
33
34pub struct FileBuilder<'a> {
35    name: Cow<'a, str>,
36    lastModified: crate::network::TimeSinceEpoch,
37    size: f64,
38    type_: Cow<'a, str>,
39}
40
41impl<'a> FileBuilder<'a> {
42    pub fn build(self) -> File<'a> {
43        File {
44            name: self.name,
45            lastModified: self.lastModified,
46            size: self.size,
47            type_: self.type_,
48        }
49    }
50}
51
52
53#[derive(Debug, Clone, Serialize, Deserialize, Default)]
54#[serde(rename_all = "camelCase")]
55pub struct Directory<'a> {
56    name: Cow<'a, str>,
57    nestedDirectories: Vec<Cow<'a, str>>,
58    /// Files that are directly nested under this directory.
59    nestedFiles: Vec<File<'a>>,
60}
61
62impl<'a> Directory<'a> {
63    pub fn builder(name: impl Into<Cow<'a, str>>, nestedDirectories: Vec<Cow<'a, str>>, nestedFiles: Vec<File<'a>>) -> DirectoryBuilder<'a> {
64        DirectoryBuilder {
65            name: name.into(),
66            nestedDirectories: nestedDirectories,
67            nestedFiles: nestedFiles,
68        }
69    }
70    pub fn name(&self) -> &str { self.name.as_ref() }
71    pub fn nestedDirectories(&self) -> &[Cow<'a, str>] { &self.nestedDirectories }
72    pub fn nestedFiles(&self) -> &[File<'a>] { &self.nestedFiles }
73}
74
75
76pub struct DirectoryBuilder<'a> {
77    name: Cow<'a, str>,
78    nestedDirectories: Vec<Cow<'a, str>>,
79    nestedFiles: Vec<File<'a>>,
80}
81
82impl<'a> DirectoryBuilder<'a> {
83    pub fn build(self) -> Directory<'a> {
84        Directory {
85            name: self.name,
86            nestedDirectories: self.nestedDirectories,
87            nestedFiles: self.nestedFiles,
88        }
89    }
90}
91
92
93#[derive(Debug, Clone, Serialize, Deserialize, Default)]
94#[serde(rename_all = "camelCase")]
95pub struct BucketFileSystemLocator<'a> {
96    /// Storage key
97    storageKey: crate::storage::SerializedStorageKey<'a>,
98    /// Bucket name. Not passing a 'bucketName' will retrieve the default Bucket. (https://developer.mozilla.org/en-US/docs/Web/API/Storage_API#storage_buckets)
99    #[serde(skip_serializing_if = "Option::is_none")]
100    bucketName: Option<Cow<'a, str>>,
101    /// Path to the directory using each path component as an array item.
102    pathComponents: Vec<Cow<'a, str>>,
103}
104
105impl<'a> BucketFileSystemLocator<'a> {
106    pub fn builder(storageKey: crate::storage::SerializedStorageKey<'a>, pathComponents: Vec<Cow<'a, str>>) -> BucketFileSystemLocatorBuilder<'a> {
107        BucketFileSystemLocatorBuilder {
108            storageKey: storageKey,
109            bucketName: None,
110            pathComponents: pathComponents,
111        }
112    }
113    pub fn storageKey(&self) -> &crate::storage::SerializedStorageKey<'a> { &self.storageKey }
114    pub fn bucketName(&self) -> Option<&str> { self.bucketName.as_deref() }
115    pub fn pathComponents(&self) -> &[Cow<'a, str>] { &self.pathComponents }
116}
117
118
119pub struct BucketFileSystemLocatorBuilder<'a> {
120    storageKey: crate::storage::SerializedStorageKey<'a>,
121    bucketName: Option<Cow<'a, str>>,
122    pathComponents: Vec<Cow<'a, str>>,
123}
124
125impl<'a> BucketFileSystemLocatorBuilder<'a> {
126    /// Bucket name. Not passing a 'bucketName' will retrieve the default Bucket. (https://developer.mozilla.org/en-US/docs/Web/API/Storage_API#storage_buckets)
127    pub fn bucketName(mut self, bucketName: impl Into<Cow<'a, str>>) -> Self { self.bucketName = Some(bucketName.into()); self }
128    pub fn build(self) -> BucketFileSystemLocator<'a> {
129        BucketFileSystemLocator {
130            storageKey: self.storageKey,
131            bucketName: self.bucketName,
132            pathComponents: self.pathComponents,
133        }
134    }
135}
136
137
138#[derive(Debug, Clone, Serialize, Deserialize, Default)]
139#[serde(rename_all = "camelCase")]
140pub struct GetDirectoryParams<'a> {
141    bucketFileSystemLocator: BucketFileSystemLocator<'a>,
142}
143
144impl<'a> GetDirectoryParams<'a> {
145    pub fn builder(bucketFileSystemLocator: BucketFileSystemLocator<'a>) -> GetDirectoryParamsBuilder<'a> {
146        GetDirectoryParamsBuilder {
147            bucketFileSystemLocator: bucketFileSystemLocator,
148        }
149    }
150    pub fn bucketFileSystemLocator(&self) -> &BucketFileSystemLocator<'a> { &self.bucketFileSystemLocator }
151}
152
153
154pub struct GetDirectoryParamsBuilder<'a> {
155    bucketFileSystemLocator: BucketFileSystemLocator<'a>,
156}
157
158impl<'a> GetDirectoryParamsBuilder<'a> {
159    pub fn build(self) -> GetDirectoryParams<'a> {
160        GetDirectoryParams {
161            bucketFileSystemLocator: self.bucketFileSystemLocator,
162        }
163    }
164}
165
166
167#[derive(Debug, Clone, Serialize, Deserialize, Default)]
168#[serde(rename_all = "camelCase")]
169pub struct GetDirectoryReturns<'a> {
170    /// Returns the directory object at the path.
171    directory: Directory<'a>,
172}
173
174impl<'a> GetDirectoryReturns<'a> {
175    pub fn builder(directory: Directory<'a>) -> GetDirectoryReturnsBuilder<'a> {
176        GetDirectoryReturnsBuilder {
177            directory: directory,
178        }
179    }
180    pub fn directory(&self) -> &Directory<'a> { &self.directory }
181}
182
183
184pub struct GetDirectoryReturnsBuilder<'a> {
185    directory: Directory<'a>,
186}
187
188impl<'a> GetDirectoryReturnsBuilder<'a> {
189    pub fn build(self) -> GetDirectoryReturns<'a> {
190        GetDirectoryReturns {
191            directory: self.directory,
192        }
193    }
194}
195
196impl<'a> GetDirectoryParams<'a> { pub const METHOD: &'static str = "FileSystem.getDirectory"; }
197
198impl<'a> crate::CdpCommand<'a> for GetDirectoryParams<'a> {
199    const METHOD: &'static str = "FileSystem.getDirectory";
200    type Response = GetDirectoryReturns<'a>;
201}