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
use super::OpError;
use super::OpResult;
use crate::bucket::FoundObject;
use crate::ctx::Ctx;
use std::sync::Arc;
use tinybuf::TinyBuf;

pub struct OpInspectObjectInput {
  pub key: TinyBuf,
  // Only useful if versioning is enabled.
  pub id: Option<u64>,
}

pub struct OpInspectObjectOutput {
  pub id: u64,
  pub size: u64,
}

pub(crate) async fn op_inspect_object(
  ctx: Arc<Ctx>,
  req: OpInspectObjectInput,
) -> OpResult<OpInspectObjectOutput> {
  let bkt = ctx.buckets.get_bucket_for_key(&req.key).await;
  let Some(FoundObject { id, size, .. }) = bkt.find_object(req.id).await else {
    return Err(OpError::ObjectNotFound);
  };

  Ok(OpInspectObjectOutput { id, size })
}