Skip to main content

paperless_api/
share_link.rs

1//! Types related to share links.
2
3use chrono::{DateTime, Utc};
4use derive_more::Display;
5use serde::{Deserialize, Serialize};
6
7use paperless_api_macros::{CreateDto, Item};
8
9use crate::PaperlessClient;
10
11/// The version of the file provided by a share link.
12#[derive(Debug, Display, Default, Clone, Copy, Deserialize, Serialize, PartialEq, Eq)]
13#[serde(rename_all = "lowercase")]
14pub enum ShareLinkFileVersion {
15    /// The "current" file version in the paperless archive.
16    /// This version might be modified by paperless.
17    #[default]
18    Archive,
19
20    /// The original file version initially uploaded to paperless.
21    Original,
22}
23
24/// A share link.
25#[derive(Debug, Clone, Deserialize, CreateDto, Item)]
26pub struct ShareLink {
27    /// Unique identifier of the share link.
28    #[dto(skip)]
29    pub id: crate::id::ShareLinkId,
30
31    /// Slug of the share link.
32    #[dto(skip)]
33    pub slug: String,
34
35    /// When the share link was created.
36    #[dto(skip)]
37    pub created: DateTime<Utc>,
38
39    /// Document of the share link.
40    pub document: crate::id::DocumentId,
41
42    /// When the share link expires.
43    pub expiration: DateTime<Utc>,
44
45    /// File version of the share link.
46    pub file_version: ShareLinkFileVersion,
47}
48
49impl ShareLink {
50    /// Returns the full URL of the share link.
51    #[must_use]
52    pub fn url(&self, client: &PaperlessClient) -> String {
53        format!("{}/share/{}", client.base_url, self.slug)
54    }
55}