1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
+
+
+
+
+
-
-
|
use crate::{
Arc,
Mutex,
};
use std::{
borrow::Cow,
fmt,
sync::Arc,
};
use smol::lock::Mutex;
use chrono::{
DateTime,
FixedOffset,
Local,
};
use sqlx::{
Postgres,
|
| ︙ | | |
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
+
+
+
+
+
+
+
|
}
if let Some(url_re) = &self.url_re {
write!(f, "\nRE: `{url_re}`")?;
}
Ok(())
}
}
/// One feed, used for caching and menu navigation
#[derive(sqlx::FromRow, Debug)]
pub struct Feed {
pub source_id: i32,
pub channel: String,
}
#[derive(sqlx::FromRow, Debug)]
pub struct Source {
pub channel_id: i64,
pub url: String,
pub iv_hash: Option<String>,
pub owner: i64,
|
| ︙ | | |
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
|
let row = sqlx::query("select exists(select true from rsstg_post where url = $1 and source_id = $2) as exists;")
.bind(post_url)
.bind(id.into())
.fetch_one(&mut *self.0).await.stack()?;
row.try_get("exists")
.stack_err("Database error: can't check whether post exists.")
}
pub async fn get_feeds <I>(&mut self, owner: I) -> Result<Vec<Feed>>
where I: Into<i64> {
let block: Vec<Feed> = sqlx::query_as("select source_id, channel from rsstg_source where owner = $1 order by source_id")
.bind(owner.into())
.fetch_all(&mut *self.0).await.stack()?;
Ok(block)
}
/// Get all pending events for (now + 1 minute)
pub async fn get_queue (&mut self) -> Result<Vec<Queue>> {
let block: Vec<Queue> = sqlx::query_as("select source_id, next_fetch, owner, last_scrape from rsstg_order natural left join rsstg_source where next_fetch < now() + interval '1 minute';")
.fetch_all(&mut *self.0).await.stack()?;
Ok(block)
}
pub async fn get_list <I> (&mut self, owner: I) -> Result<Vec<List>>
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.0).await.stack()?;
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.0).await.stack()?;
Ok(source)
}
pub async fn get_one_name <I> (&mut self, owner: I, name: &str) -> 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 channel = $2")
.bind(owner.into())
.bind(name)
.fetch_optional(&mut *self.0).await.stack()?;
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.0).await.stack()?;
|
| ︙ | | |
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
-
+
|
.bind(channel_id)
.bind(url)
.bind(iv_hash)
.bind(owner.into())
.bind(channel)
.bind(url_re)
.execute(&mut *self.0).await
{
{
Ok(_) => Ok(match update {
Some(_) => "Channel updated.",
None => "Channel added.",
}),
Err(sqlx::Error::Database(err)) => {
match err.downcast::<sqlx::postgres::PgDatabaseError>().routine() {
Some("_bt_check_unique", ) => {
|
| ︙ | | |
| | | | |