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
use super::OpError;
use super::OpResult;
use crate::ctx::Ctx;
use chrono::DateTime;
use chrono::Utc;
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 created: DateTime<Utc>,
}

pub(crate) async fn op_inspect_object(
  ctx: Arc<Ctx>,
  req: OpInspectObjectInput,
) -> OpResult<OpInspectObjectOutput> {
  let Some(obj) = ctx.committed_objects.get(&req.key).filter(|o| req.id.is_none() || Some(o.id()) == req.id).map(|e| e.value().clone()) else {
    return Err(OpError::ObjectNotFound);
  };
  Ok(OpInspectObjectOutput {
    id: obj.id(),
    size: obj.size,
    created: obj.created,
  })
}