1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
use cratePublicKey;
use crateSessionCredential;
use ;
use Arc;
use ;
use crate::;
/// Read and write **your own data** with simple path-based operations (authenticated).
///
/// Obtained via [`PubkySession::storage()`]. The user is implied by the session —
/// you only supply **absolute paths** (e.g. `"/pub/my.app/file.txt"`).
/// The SDK resolves the homeserver and attaches credentials automatically.
///
/// # Request failures
///
/// Invalid paths return [`RequestError::Validation`] inside [`crate::Error::Request`];
/// URL parsing returns [`crate::Error::Parse`]. Automatic grant refresh failures
/// return [`crate::Error::CredentialRefresh`]; its secret-safe payload retains
/// an optional refresh HTTP status. Homeserver resolution, other credential
/// preparation, and transport errors propagate.
///
/// Non-success HTTP statuses return [`RequestError::Server`] with the status and
/// server message, including authentication/permission failures (401/403) and 5xx.
/// Only [`exists`](Self::exists) and [`stats`](Self::stats) treat 404/410 as missing.
///
/// # Path conventions
///
/// - Paths under `/pub/` are **publicly readable** by anyone via [`PublicStorage`].
/// - Paths under `/priv/` are **private** to the signed-in user.
///
/// # Example
///
/// ```no_run
/// # async fn example(session: pubky::PubkySession) -> pubky::Result<()> {
/// let storage = session.storage();
///
/// // Write
/// storage.put("/pub/my.app/hello.txt", "world").await?;
///
/// // Read
/// let body = storage.get("/pub/my.app/hello.txt").await?.text().await?;
///
/// // Check existence
/// let exists = storage.exists("/pub/my.app/hello.txt").await?;
///
/// // Metadata (content-length, content-type, etag, last-modified)
/// if let Some(stats) = storage.stats("/pub/my.app/hello.txt").await? {
/// println!("size: {:?}", stats.content_length);
/// }
///
/// // List a directory (path must end with `/`)
/// let entries = storage.list("/pub/my.app/")?.limit(50).send().await?;
///
/// // Delete
/// storage.delete("/pub/my.app/hello.txt").await?;
/// # Ok(()) }
/// ```
/// Read **anyone's public data** without signing in (unauthenticated).
///
/// No keys or session needed. Accepts **addressed resources** that pair a user's
/// public key with an absolute path. Supported address formats:
/// - `"pubky://<z32-pubkey>/pub/..."` (canonical)
/// - `"pubky<z32-pubkey>/pub/..."` (compact)
/// - `(PublicKey, "/pub/...")` tuple
///
/// Writes are not available — use [`SessionStorage`] for that.
///
/// # Example
///
/// ```no_run
/// use pubky::{Pubky, PublicKey};
///
/// # async fn example() -> pubky::Result<()> {
/// let pubky = Pubky::new()?;
/// let user: PublicKey = "o1gg96ewuojmopcjbz8895478wdtxtzzuxnfjjz8o8e77csa1ngo"
/// .parse().unwrap();
///
/// let public = pubky.public_storage();
///
/// // Read a file
/// let body = public
/// .get(format!("pubky://{}/pub/pubky.app/profile.json", user.z32()))
/// .await?
/// .text().await?;
///
/// // Or use a tuple
/// let exists = public.exists((&user, "/pub/pubky.app/profile.json")).await?;
///
/// // List a directory
/// let entries = public
/// .list(format!("pubky://{}/pub/pubky.app/", user.z32()))?
/// .shallow(true)
/// .send().await?;
/// # Ok(()) }
/// ```
/// Helper: validation error for directory listings without trailing slash.