Skip to main content

paperless_api/
share_link.rs

1//! Types related to share links.
2
3use std::sync::Arc;
4
5use chrono::{DateTime, Utc};
6use derive_more::Display;
7use serde::{Deserialize, Serialize};
8
9use paperless_api_macros::CreateDto;
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)]
26#[api_info(private, endpoint = "share_links")]
27pub struct ShareLink {
28    /// Unique identifier of the share link.
29    #[dto(skip)]
30    pub id: crate::id::ShareLinkId,
31
32    /// Document of the share link.
33    pub document: crate::id::DocumentId,
34
35    /// When the share link was created.
36    #[dto(skip)]
37    pub created: DateTime<Utc>,
38
39    /// When the share link expires.
40    pub expiration: DateTime<Utc>,
41
42    /// File version of the share link.
43    pub file_version: ShareLinkFileVersion,
44
45    /// Slug of the share link.
46    #[dto(skip)]
47    pub slug: String,
48
49    #[serde(skip)]
50    #[dto(skip)]
51    pub(crate) base_url: Arc<str>,
52}
53
54impl ShareLink {
55    #[must_use]
56    pub fn url(&self) -> String {
57        format!("{}/share/{}", self.base_url, self.slug)
58    }
59}