printobserver_types/image.rs
1//! Images fetched for a print, and the handle one travels in context under.
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6use crate::ids::{EventId, ImageId, PrintId};
7use crate::timestamp::Timestamp;
8
9/// One image, stored beside the event it arrived with.
10///
11/// `relative_path` is relative to the configured state directory, so that the
12/// store stays portable. Materializing an image resolves that to an absolute
13/// path; nothing in this system renders image bytes into JSON.
14#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
15#[serde(deny_unknown_fields)]
16pub struct ImageRecord {
17 /// This image's identifier, minted by the store.
18 pub id: ImageId,
19 /// The print it belongs to.
20 pub print_id: PrintId,
21 /// The event it arrived with.
22 pub event_id: EventId,
23 /// Where it was fetched from, when it was fetched from somewhere.
24 #[serde(default, skip_serializing_if = "Option::is_none")]
25 pub source_url: Option<String>,
26 /// When it was fetched.
27 pub fetched_at: Timestamp,
28 /// The content type it was served as.
29 pub content_type: String,
30 /// How many bytes it is.
31 pub byte_len: i64,
32 /// The SHA-256 of its bytes, lowercase hexadecimal.
33 pub sha256: String,
34 /// Where it lives, relative to the configured state directory.
35 pub relative_path: String,
36}
37
38/// The handle an image travels in context under.
39#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
40#[serde(deny_unknown_fields)]
41pub struct ImageRef {
42 /// The image's identifier.
43 pub id: ImageId,
44 /// The SHA-256 of its bytes, lowercase hexadecimal.
45 pub sha256: String,
46}