Skip to main content

spoolframe_protocol/
resource.rs

1//! One metadata frame followed by exactly `length` raw bytes for every
2//! binary resource. Playback revisions are independent of encoder epochs.
3use crate::{ArtworkFace, ArtworkRequest, Error, MediaRead, PlaybackHandle, SessionId};
4use serde::{Deserialize, Serialize};
5use spoolframe_types::{ArtworkId, SubtitleFormat};
6
7#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8#[serde(tag = "type", rename_all = "snake_case")]
9pub enum ResourceRequest {
10    Artwork {
11        request: ArtworkRequest,
12        max_bytes: u64,
13    },
14    Media {
15        request: MediaRead,
16        revision: u64,
17    },
18    Subtitle {
19        session: SessionId,
20        handle: PlaybackHandle,
21        revision: u64,
22        offset: u64,
23        version: Option<u64>,
24    },
25    SubtitleSegment {
26        session: SessionId,
27        handle: PlaybackHandle,
28        revision: u64,
29        segment: u32,
30    },
31    /// Upload a cover for playlist `id` (`spoolframe:playlist-art`):
32    /// the only request whose stream goes on past it, with exactly
33    /// `length` bytes of a JPEG, PNG, WebP or HEIC picture. Answered
34    /// `ready { length: 0, playlist_art { artwork } }`, with no body.
35    /// Refused before the picture is read when the user may not edit the
36    /// playlist (`NotAllowed`) or `length` is past
37    /// [`crate::playlists::MAX_ART_BYTES`] (`ImageTooLarge`).
38    SetPlaylistArt {
39        session: SessionId,
40        id: String,
41        length: u64,
42    },
43    /// Read download `id`'s file (`spoolframe:downloads`): at most
44    /// `length` bytes from `offset`, and no more than [`crate::MAX_READ`].
45    /// Any offset may be asked, so a download broken off resumes where it
46    /// stopped. Answered `ready { length, download { size } }` with the
47    /// bytes; `length` is short only at the file's end. `NotFound` for an
48    /// id that is not the session user's; `DownloadNotReady` until its
49    /// state is `ready`. Not a playback: it takes no playback slot.
50    Download {
51        session: SessionId,
52        id: String,
53        offset: u64,
54        length: u64,
55    },
56}
57
58#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
59#[serde(tag = "type", rename_all = "snake_case")]
60pub enum ResourceMetadata {
61    Artwork {
62        content_type: String,
63        etag: String,
64        /// Experimental (`smart-crop`), for a connection that named it:
65        /// the faces in this backdrop, empty if it has none. Left out for
66        /// a backdrop not scanned yet, and for any other image.
67        #[serde(default, skip_serializing_if = "Option::is_none")]
68        faces: Option<Vec<ArtworkFace>>,
69    },
70    Media {
71        size: u64,
72        complete: bool,
73        epoch: u32,
74        revision: u64,
75    },
76    Subtitle {
77        format: SubtitleFormat,
78        total: u64,
79        version: u64,
80        revision: u64,
81    },
82    /// The cover `SetPlaylistArt` stored: the playlist's `artwork` now.
83    PlaylistArt { artwork: ArtworkId },
84    /// A download's file (`Download`): its whole length.
85    Download { size: u64 },
86}
87
88#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
89#[serde(tag = "type", rename_all = "snake_case")]
90pub enum ResourceResponse {
91    Ready {
92        length: u64,
93        metadata: ResourceMetadata,
94    },
95    Error {
96        error: Error,
97    },
98}