Skip to main content

paperless_api/
share_link.rs

1use std::borrow::Cow;
2
3use derive_more::Display;
4use serde::{Deserialize, Serialize};
5
6/// The version of the file provided by a share link.
7#[derive(Debug, Display, Clone, Copy, Deserialize, Serialize, PartialEq, Eq)]
8#[serde(rename_all = "lowercase")]
9pub enum ShareLinkFileVersion {
10    /// The "current" file version in the paperless archive.
11    /// This version might be modified by paperless e.g. via OCR processing.
12    Archive,
13
14    /// The original file version initially uploaded to paperless.
15    Original,
16}
17
18/// A share link
19#[derive(Debug, Clone, Deserialize)]
20pub struct ShareLink<'a> {
21    /// Unique identifier of the share link.
22    pub id: crate::id::ShareLinkId,
23
24    /// Document of the share link.
25    pub document: crate::id::DocumentId,
26
27    /// File version of the share link.
28    pub file_version: ShareLinkFileVersion,
29
30    /// Slug of the share link.
31    pub slug: String,
32
33    #[serde(skip)]
34    pub(crate) base_url: Cow<'a, str>,
35}
36
37impl ShareLink<'_> {
38    #[must_use]
39    pub fn url(&self) -> String {
40        format!("{}/share/{}", self.base_url, self.slug)
41    }
42
43    /// Returns an owned version of this share link.
44    #[must_use]
45    pub fn owned(self) -> ShareLink<'static> {
46        ShareLink {
47            base_url: Cow::Owned(self.base_url.into_owned()),
48            ..self
49        }
50    }
51}