news_flash/models/
favicon.rs1use crate::models::{FeedID, Url};
2use crate::schema::fav_icons;
3use chrono::{DateTime, Utc};
4
5#[derive(Identifiable, Queryable, Clone, Debug, Insertable, Eq)]
6#[diesel(primary_key(feed_id))]
7#[diesel(table_name = fav_icons)]
8#[diesel(check_for_backend(SQLite))]
9pub struct FatFavIcon {
10 pub feed_id: FeedID,
11 #[diesel(column_name = "date")]
12 pub expires: DateTime<Utc>,
13 pub format: Option<String>,
14 pub etag: Option<String>,
15 pub lowres_source_url: Option<Url>,
16 pub lowres: Option<Vec<u8>>,
17 pub highres: Option<Vec<u8>>,
18 pub highres_source_url: Option<Url>,
19}
20
21impl PartialEq for FatFavIcon {
22 fn eq(&self, other: &FatFavIcon) -> bool {
23 self.feed_id == other.feed_id
24 }
25}
26
27impl From<FavIcon> for FatFavIcon {
28 fn from(value: FavIcon) -> Self {
29 FatFavIcon {
30 feed_id: value.feed_id,
31 expires: value.expires,
32 format: value.format,
33 etag: value.etag,
34 lowres_source_url: value.source_url,
35 lowres: value.data,
36 highres: None,
37 highres_source_url: None,
38 }
39 }
40}
41
42impl FatFavIcon {
43 pub fn is_expired(&self) -> bool {
44 Utc::now() >= self.expires
45 }
46}
47
48#[derive(Identifiable, Queryable, Clone, Debug, Insertable, Eq)]
49#[diesel(primary_key(feed_id))]
50#[diesel(table_name = fav_icons)]
51#[diesel(check_for_backend(SQLite))]
52pub struct FavIcon {
53 pub feed_id: FeedID,
54 #[diesel(column_name = "date")]
55 pub expires: DateTime<Utc>,
56 pub format: Option<String>,
57 pub etag: Option<String>,
58 #[diesel(column_name = "lowres_source_url")]
59 pub source_url: Option<Url>,
60 #[diesel(column_name = "lowres")]
61 pub data: Option<Vec<u8>>,
62}
63
64impl PartialEq for FavIcon {
65 fn eq(&self, other: &FavIcon) -> bool {
66 self.feed_id == other.feed_id
67 }
68}
69
70impl From<FatFavIcon> for FavIcon {
71 fn from(value: FatFavIcon) -> Self {
72 FavIcon {
73 feed_id: value.feed_id,
74 expires: value.expires,
75 format: value.format,
76 etag: value.etag,
77 source_url: value.lowres_source_url,
78 data: value.lowres,
79 }
80 }
81}
82
83impl FavIcon {
84 pub fn is_expired(&self) -> bool {
85 Utc::now() >= self.expires
86 }
87}