Skip to main content

paperless_api/
share_link_bundle.rs

1//! Types related to share links.
2
3use chrono::{DateTime, Utc};
4use derive_more::Display;
5use paperless_api_macros::Item;
6use serde::{Deserialize, Serialize};
7
8use crate::{
9    PaperlessClient,
10    dto::{CreateDto, UpdateDto},
11    id::{DocumentId, ShareLinkBundleId},
12    share_link::ShareLinkFileVersion,
13};
14
15/// A share link bundle.
16#[derive(Debug, Clone, Deserialize, Serialize, Item)]
17pub struct ShareLinkBundle {
18    /// Unique identifier of the share link bundle.
19    pub id: crate::id::ShareLinkBundleId,
20
21    /// The documents in the bundle.
22    pub documents: Vec<DocumentId>,
23
24    /// File version of the share link.
25    pub file_version: ShareLinkFileVersion,
26
27    /// Slug of the bundle.
28    pub slug: String,
29
30    /// When the bundle was created.
31    pub created: DateTime<Utc>,
32
33    /// When the bundle was built.
34    pub built_at: DateTime<Utc>,
35
36    /// When the bundle expires.
37    pub expiration: DateTime<Utc>,
38
39    /// Size of the bundle in number of bytes.
40    pub size_bytes: u32,
41
42    /// Number of documents in the bundle.
43    pub document_count: u32,
44
45    /// The status of the bundle.
46    pub status: ShareLinkBundleStatus,
47}
48
49#[derive(Debug, Clone, Serialize)]
50pub struct ShareLinkBundleDto {
51    /// Number of days until the bundles expires.
52    pub expiration_days: u16,
53
54    /// The version of the files in the bundle.
55    pub file_version: ShareLinkFileVersion,
56
57    /// The documents in the bundle.
58    pub document_ids: Vec<DocumentId>,
59}
60
61impl CreateDto for ShareLinkBundle {
62    type Id = ShareLinkBundleId;
63    type BaseType = ShareLinkBundle;
64}
65
66impl UpdateDto for ShareLinkBundle {
67    type Id = ShareLinkBundleId;
68    type BaseType = ShareLinkBundle;
69}
70
71/// The status of a share link bundle.
72#[derive(Debug, Display, Clone, Copy, PartialEq, Eq, Hash, Deserialize, Serialize)]
73#[serde(rename_all = "lowercase")]
74pub enum ShareLinkBundleStatus {
75    Pending,
76    Processing,
77    Ready,
78    Failed,
79}
80
81impl ShareLinkBundle {
82    /// Returns the full URL of the share link.
83    #[must_use]
84    pub fn url(&self, client: &PaperlessClient) -> String {
85        format!("{}/share/{}", client.base_url, self.slug)
86    }
87}