1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use crate::jobs::SettingsMap;
use crate::mapping::Mappable;
use crate::record::{TypedValue, ValidationError};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use url::Url;
pub const DEFAULT_CHECK_INTERVAL: u64 = 3600;
#[derive(Serialize, Deserialize, Debug, Clone, Default, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct Feed {
pub url: String,
pub settings: Option<FeedSettings>,
#[serde(default)]
pub media_jobs: SettingsMap,
#[serde(default)]
pub post_jobs: SettingsMap,
}
impl Feed {
pub fn with_url(url: String) -> Self {
Self {
url,
..Default::default()
}
}
}
impl TypedValue for Feed {
const NAME: &'static str = "oas.Feed";
fn validate(&self) -> Result<(), ValidationError> {
let _url = Url::parse(&self.url)?;
Ok(())
}
}
impl Mappable for Feed {}
#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct FeedSettings {
pub check_interval: u64,
#[serde(default)]
pub crawl_backwards: bool,
}
impl Default for FeedSettings {
fn default() -> Self {
Self {
check_interval: DEFAULT_CHECK_INTERVAL,
crawl_backwards: false,
}
}
}