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