1
2
3
4
5
6
7
8
|
use std::borrow::Cow;
use anyhow::{
Result,
bail,
};
use async_std::sync::{
Arc,
|
|
>
>
>
|
1
2
3
4
5
6
7
8
9
10
11
|
use std::{
borrow::Cow,
fmt,
};
use anyhow::{
Result,
bail,
};
use async_std::sync::{
Arc,
|
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
pub source_id: i32,
pub channel: String,
pub enabled: bool,
pub url: String,
pub iv_hash: Option<String>,
pub url_re: Option<String>,
}
#[derive(sqlx::FromRow, Debug)]
pub struct Source {
pub channel_id: i64,
pub url: String,
pub iv_hash: Option<String>,
pub owner: i64,
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
pub source_id: i32,
pub channel: String,
pub enabled: bool,
pub url: String,
pub iv_hash: Option<String>,
pub url_re: Option<String>,
}
impl fmt::Display for List {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!(f, "\\#ļøā£ {} \\*ļøā£ `{}` {}\nš `{}`", self.source_id, self.channel,
match self.enabled {
true => "š enabled",
false => "ā disabled",
}, self.url)?;
if let Some(iv_hash) = &self.iv_hash {
write!(f, "\nIV: `{iv_hash}`")?;
}
if let Some(url_re) = &self.url_re {
write!(f, "\nRE: `{url_re}`")?;
}
Ok(())
}
}
#[derive(sqlx::FromRow, Debug)]
pub struct Source {
pub channel_id: i64,
pub url: String,
pub iv_hash: Option<String>,
pub owner: i64,
|
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
pub async fn get_list <I> (&mut self, owner: I) -> Result<Vec<List>>
where I: Into<i64> {
let source: Vec<List> = sqlx::query_as("select source_id, channel, enabled, url, iv_hash, url_re from rsstg_source where owner = $1 order by source_id")
.bind(owner.into())
.fetch_all(&mut *self.conn).await?;
Ok(source)
}
pub async fn get_source <I> (&mut self, id: i32, owner: I) -> Result<Source>
where I: Into<i64> {
let source: Source = sqlx::query_as("select channel_id, url, iv_hash, owner, url_re from rsstg_source where source_id = $1 and owner = $2")
.bind(id)
.bind(owner.into())
.fetch_one(&mut *self.conn).await?;
|
>
>
>
>
>
>
>
>
>
|
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
pub async fn get_list <I> (&mut self, owner: I) -> Result<Vec<List>>
where I: Into<i64> {
let source: Vec<List> = sqlx::query_as("select source_id, channel, enabled, url, iv_hash, url_re from rsstg_source where owner = $1 order by source_id")
.bind(owner.into())
.fetch_all(&mut *self.conn).await?;
Ok(source)
}
pub async fn get_one <I> (&mut self, owner: I, id: i32) -> Result<Option<List>>
where I: Into<i64> {
let source: Option<List> = sqlx::query_as("select source_id, channel, enabled, url, iv_hash, url_re from rsstg_source where owner = $1 and source_id = $2")
.bind(owner.into())
.bind(id)
.fetch_optional(&mut *self.conn).await?;
Ok(source)
}
pub async fn get_source <I> (&mut self, id: i32, owner: I) -> Result<Source>
where I: Into<i64> {
let source: Source = sqlx::query_as("select channel_id, url, iv_hash, owner, url_re from rsstg_source where source_id = $1 and owner = $2")
.bind(id)
.bind(owner.into())
.fetch_one(&mut *self.conn).await?;
|