wallabag_api/types/
new_entry.rs

1// Copyright 2018 Samuel Walladge <samuel@swalladge.net>
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3
4use chrono::{DateTime, Utc};
5
6use serde::{Deserialize, Serialize};
7
8use crate::utils::serde::bool_to_int;
9
10/// A struct representing an entry to be created.
11/// At least `url` must be provided. If you wish to provide the HTML content you
12/// must also provide `content` and `title` to prevent the wallabag server from
13/// fetching it from the url.
14#[derive(Deserialize, Serialize, Debug)]
15pub struct NewEntry {
16    pub url: String,
17    pub title: Option<String>,
18
19    /// Tags containing a comma are valid but discouraged...
20    /// Also note that these are tag labels as strings, not Tag objects.
21    pub tags: Option<Vec<String>>,
22
23    #[serde(serialize_with = "bool_to_int")]
24    pub archive: Option<bool>,
25    #[serde(serialize_with = "bool_to_int")]
26    pub starred: Option<bool>,
27    #[serde(serialize_with = "bool_to_int")]
28    pub public: Option<bool>,
29
30    pub content: Option<String>,
31    pub language: Option<String>,
32    pub preview_picture: Option<String>,
33    pub published_at: Option<DateTime<Utc>>,
34
35    /// Formatted as "name 1, name 2"
36    pub authors: Option<String>,
37
38    pub origin_url: Option<String>,
39}
40
41impl NewEntry {
42    /// Create a new entry with a url (url is the only mandatory field). The
43    /// rest of the fields will be populated with `None`.
44    pub fn new_with_url(url: String) -> Self {
45        Self {
46            url,
47            title: None,
48            tags: None,
49            archive: None,
50            starred: None,
51            content: None,
52            language: None,
53            preview_picture: None,
54            published_at: None,
55            authors: None,
56            public: None,
57            origin_url: None,
58        }
59    }
60}