Skip to content

Commit bb5b7f4

Browse files
committed
Move away from buckets terminology
1 parent 7d9ef05 commit bb5b7f4

File tree

3 files changed

+21
-29
lines changed

3 files changed

+21
-29
lines changed

src/external/s3.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,12 @@ impl S3Service {
202202
#[derive(Clone, Debug)]
203203
pub struct Bucket<'a> {
204204
name: &'static str,
205-
buckets: &'a S3Service,
205+
s3: &'a S3Service,
206206
}
207207

208208
impl<'a> Bucket<'a> {
209-
pub const fn new(buckets: &'a S3Service, name: &'static str) -> Self {
210-
Self { name, buckets }
209+
pub const fn new(s3: &'a S3Service, name: &'static str) -> Self {
210+
Self { name, s3 }
211211
}
212212

213213
/// The name of this bucket.
@@ -230,14 +230,7 @@ impl<'a> Bucket<'a> {
230230
///
231231
/// * [`AppError::S3`] - If the S3 request fails.
232232
pub async fn get_object(&self, key: impl Into<String>) -> Result<Bytes, AppError> {
233-
let mut resp = self
234-
.buckets
235-
.client()
236-
.get_object()
237-
.bucket(self.name)
238-
.key(key)
239-
.send()
240-
.await?;
233+
let mut resp = self.s3.client().get_object().bucket(self.name).key(key).send().await?;
241234

242235
let mut bytes = BytesMut::new();
243236
while let Some(chunk) = resp.body.next().await {
@@ -264,7 +257,7 @@ impl<'a> Bucket<'a> {
264257
data: impl Into<ByteStream>,
265258
content_type: &Mime,
266259
) -> Result<(), AppError> {
267-
self.buckets
260+
self.s3
268261
.client()
269262
.put_object()
270263
.bucket(self.name)
@@ -296,7 +289,7 @@ impl<'a> Bucket<'a> {
296289
let mut objects = Vec::new();
297290

298291
// AWS-SDK has a nice pagination API to send continuation tokens implicitly, so we use that
299-
let mut req = self.buckets.client().list_objects_v2().bucket(self.name).prefix(prefix);
292+
let mut req = self.s3.client().list_objects_v2().bucket(self.name).prefix(prefix);
300293

301294
if let Some(limit) = limit {
302295
req = req.max_keys(limit);
@@ -324,7 +317,7 @@ impl<'a> Bucket<'a> {
324317
///
325318
/// * [`AppError::S3`] - If the S3 request fails.
326319
pub async fn delete_object(&self, key: impl Into<String>) -> Result<(), AppError> {
327-
self.buckets
320+
self.s3
328321
.client()
329322
.delete_object()
330323
.bucket(self.name)
@@ -363,7 +356,7 @@ impl<'a> Bucket<'a> {
363356
})
364357
.collect();
365358

366-
self.buckets
359+
self.s3
367360
.client()
368361
.delete_objects()
369362
.bucket(self.name)

src/models/attachment.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub trait AttachmentLike {
2727
/// This determines the ordering of attachments within a message, starting from 0.
2828
fn id(&self) -> u8;
2929
/// The name of the attachment file, including the file extension.
30-
fn filename(&self) -> &String;
30+
fn filename(&self) -> &str;
3131
/// The ID of the message this attachment belongs to.
3232
fn message_id(&self) -> Snowflake<Message>;
3333
/// The ID of the channel the message was sent to.
@@ -164,9 +164,8 @@ impl FullAttachment {
164164
/// ## Errors
165165
///
166166
/// * [`AppError::S3`] - If the S3 request fails.
167-
pub async fn upload(&self, buckets: &S3Service) -> Result<(), AppError> {
168-
buckets
169-
.attachments()
167+
pub async fn upload(&self, s3: &S3Service) -> Result<(), AppError> {
168+
s3.attachments()
170169
.put_object(self.s3_key(), self.content.clone(), &self.mime())
171170
.await
172171
}
@@ -176,8 +175,8 @@ impl FullAttachment {
176175
/// ## Errors
177176
///
178177
/// * [`AppError::S3`] - If the S3 request fails.
179-
pub async fn download(&mut self, buckets: &S3Service) -> Result<(), AppError> {
180-
self.content = buckets.attachments().get_object(self.s3_key()).await?;
178+
pub async fn download(&mut self, s3: &S3Service) -> Result<(), AppError> {
179+
self.content = s3.attachments().get_object(self.s3_key()).await?;
181180
Ok(())
182181
}
183182

@@ -187,8 +186,8 @@ impl FullAttachment {
187186
/// ## Errors
188187
///
189188
/// * [`AppError::S3`] - If the S3 request fails.
190-
pub async fn delete(&self, buckets: &S3Service) -> Result<(), AppError> {
191-
buckets.attachments().delete_object(self.s3_key()).await
189+
pub async fn delete(&self, s3: &S3Service) -> Result<(), AppError> {
190+
s3.attachments().delete_object(self.s3_key()).await
192191
}
193192
}
194193

@@ -197,7 +196,7 @@ impl AttachmentLike for FullAttachment {
197196
self.id
198197
}
199198

200-
fn filename(&self) -> &String {
199+
fn filename(&self) -> &str {
201200
&self.filename
202201
}
203202

@@ -264,7 +263,7 @@ impl PartialAttachment {
264263
/// ## Errors
265264
///
266265
/// * [`AppError::S3`] - If the S3 request fails.
267-
pub async fn download(self, buckets: &S3Service) -> Result<FullAttachment, AppError> {
266+
pub async fn download(self, s3: &S3Service) -> Result<FullAttachment, AppError> {
268267
let mut attachment = FullAttachment::new(
269268
self.id,
270269
self.filename,
@@ -273,7 +272,7 @@ impl PartialAttachment {
273272
self.channel_id,
274273
self.message_id,
275274
);
276-
attachment.download(buckets).await?;
275+
attachment.download(s3).await?;
277276
Ok(attachment)
278277
}
279278

@@ -405,7 +404,7 @@ impl AttachmentLike for PartialAttachment {
405404
self.id
406405
}
407406

408-
fn filename(&self) -> &String {
407+
fn filename(&self) -> &str {
409408
&self.filename
410409
}
411410

src/models/avatar.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,15 @@ impl<K: AvatarKind> PartialAvatar<K> {
291291
/// ## Errors
292292
///
293293
/// * [`AppError::S3`] - If the S3 request fails.
294-
pub async fn download(self, buckets: &S3Service) -> Result<FullAvatar<K>, AppError> {
294+
pub async fn download(self, s3: &S3Service) -> Result<FullAvatar<K>, AppError> {
295295
let mime = self.mime().clone();
296296
let mut attachment = FullAvatar::builder()
297297
.avatar_hash(self.avatar_hash)
298298
.holder_id(self.holder_id)
299299
.mime(mime)
300300
.content(Bytes::new())
301301
.build()?;
302-
attachment.download(buckets).await?;
302+
attachment.download(s3).await?;
303303
Ok(attachment)
304304
}
305305
}

0 commit comments

Comments
 (0)