spoolframe_protocol/
artwork.rs1use serde::{Deserialize, Serialize};
10use spoolframe_types::ArtworkId;
11
12use crate::messages::{Error, SessionId};
13
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
18#[serde(rename_all = "snake_case")]
19pub enum ArtworkSize {
20 Thumb,
22 Small,
24 Medium,
26 Large,
28 Original,
30 #[serde(other)]
32 Unknown,
33}
34
35impl ArtworkSize {
36 pub fn width(self) -> Option<u32> {
38 match self {
39 ArtworkSize::Thumb => Some(160),
40 ArtworkSize::Small => Some(320),
41 ArtworkSize::Medium => Some(640),
42 ArtworkSize::Large => Some(1280),
43 ArtworkSize::Original | ArtworkSize::Unknown => None,
44 }
45 }
46
47 pub fn as_str(self) -> &'static str {
48 match self {
49 ArtworkSize::Thumb => "thumb",
50 ArtworkSize::Small => "small",
51 ArtworkSize::Medium => "medium",
52 ArtworkSize::Large => "large",
53 ArtworkSize::Original => "original",
54 ArtworkSize::Unknown => "unknown",
55 }
56 }
57}
58
59#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
60pub struct ArtworkRequest {
61 pub session: SessionId,
62 pub id: ArtworkId,
63 pub size: ArtworkSize,
64}
65
66#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
68pub struct ArtworkReply {
69 pub content_type: String,
71 pub length: u64,
73 pub etag: String,
76}
77
78#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
79#[serde(rename_all = "snake_case")]
80pub enum ArtworkResponse {
81 Ok(ArtworkReply),
82 Err(Error),
83}