0000: 75 73 65 20 73 74 64 3a 3a 7b 0a 09 62 6f 72 72 use std::{..borr
0010: 6f 77 3a 3a 43 6f 77 2c 0a 09 66 6d 74 2c 0a 09 ow::Cow,..fmt,..
0020: 73 79 6e 63 3a 3a 41 72 63 2c 0a 7d 3b 0a 0a 75 sync::Arc,.};..u
0030: 73 65 20 73 6d 6f 6c 3a 3a 6c 6f 63 6b 3a 3a 4d se smol::lock::M
0040: 75 74 65 78 3b 0a 75 73 65 20 63 68 72 6f 6e 6f utex;.use chrono
0050: 3a 3a 7b 0a 09 44 61 74 65 54 69 6d 65 2c 0a 09 ::{..DateTime,..
0060: 46 69 78 65 64 4f 66 66 73 65 74 2c 0a 09 4c 6f FixedOffset,..Lo
0070: 63 61 6c 2c 0a 7d 3b 0a 75 73 65 20 73 71 6c 78 cal,.};.use sqlx
0080: 3a 3a 7b 0a 09 50 6f 73 74 67 72 65 73 2c 0a 09 ::{..Postgres,..
0090: 52 6f 77 2c 0a 09 70 6f 73 74 67 72 65 73 3a 3a Row,..postgres::
00a0: 50 67 50 6f 6f 6c 4f 70 74 69 6f 6e 73 2c 0a 09 PgPoolOptions,..
00b0: 70 6f 6f 6c 3a 3a 50 6f 6f 6c 43 6f 6e 6e 65 63 pool::PoolConnec
00c0: 74 69 6f 6e 2c 0a 7d 3b 0a 75 73 65 20 73 74 61 tion,.};.use sta
00d0: 63 6b 65 64 5f 65 72 72 6f 72 73 3a 3a 7b 0a 09 cked_errors::{..
00e0: 52 65 73 75 6c 74 2c 0a 09 53 74 61 63 6b 61 62 Result,..Stackab
00f0: 6c 65 45 72 72 2c 0a 09 62 61 69 6c 2c 0a 7d 3b leErr,..bail,.};
0100: 0a 0a 23 5b 64 65 72 69 76 65 28 73 71 6c 78 3a ..#[derive(sqlx:
0110: 3a 46 72 6f 6d 52 6f 77 2c 20 44 65 62 75 67 29 :FromRow, Debug)
0120: 5d 0a 70 75 62 20 73 74 72 75 63 74 20 4c 69 73 ].pub struct Lis
0130: 74 20 7b 0a 09 70 75 62 20 73 6f 75 72 63 65 5f t {..pub source_
0140: 69 64 3a 20 69 33 32 2c 0a 09 70 75 62 20 63 68 id: i32,..pub ch
0150: 61 6e 6e 65 6c 3a 20 53 74 72 69 6e 67 2c 0a 09 annel: String,..
0160: 70 75 62 20 65 6e 61 62 6c 65 64 3a 20 62 6f 6f pub enabled: boo
0170: 6c 2c 0a 09 70 75 62 20 75 72 6c 3a 20 53 74 72 l,..pub url: Str
0180: 69 6e 67 2c 0a 09 70 75 62 20 69 76 5f 68 61 73 ing,..pub iv_has
0190: 68 3a 20 4f 70 74 69 6f 6e 3c 53 74 72 69 6e 67 h: Option<String
01a0: 3e 2c 0a 09 70 75 62 20 75 72 6c 5f 72 65 3a 20 >,..pub url_re:
01b0: 4f 70 74 69 6f 6e 3c 53 74 72 69 6e 67 3e 2c 0a Option<String>,.
01c0: 7d 0a 0a 69 6d 70 6c 20 66 6d 74 3a 3a 44 69 73 }..impl fmt::Dis
01d0: 70 6c 61 79 20 66 6f 72 20 4c 69 73 74 20 7b 0a play for List {.
01e0: 09 66 6e 20 66 6d 74 28 26 73 65 6c 66 2c 20 66 .fn fmt(&self, f
01f0: 3a 20 26 6d 75 74 20 66 6d 74 3a 3a 46 6f 72 6d : &mut fmt::Form
0200: 61 74 74 65 72 3c 27 5f 3e 29 20 2d 3e 20 73 74 atter<'_>) -> st
0210: 64 3a 3a 72 65 73 75 6c 74 3a 3a 52 65 73 75 6c d::result::Resul
0220: 74 3c 28 29 2c 20 66 6d 74 3a 3a 45 72 72 6f 72 t<(), fmt::Error
0230: 3e 20 7b 0a 09 09 77 72 69 74 65 21 28 66 2c 20 > {...write!(f,
0240: 22 5c 5c 23 66 65 65 64 5c 5c 5f 7b 7d 20 5c 5c "\\#feed\\_{} \\
0250: 2a ef b8 8f e2 83 a3 20 60 7b 7d 60 20 7b 7d 5c *ļøā£ `{}` {}\
0260: 6e f0 9f 94 97 20 60 7b 7d 60 22 2c 20 73 65 6c nš `{}`", sel
0270: 66 2e 73 6f 75 72 63 65 5f 69 64 2c 20 73 65 6c f.source_id, sel
0280: 66 2e 63 68 61 6e 6e 65 6c 2c 0a 09 09 09 6d 61 f.channel,....ma
0290: 74 63 68 20 73 65 6c 66 2e 65 6e 61 62 6c 65 64 tch self.enabled
02a0: 20 7b 0a 09 09 09 09 74 72 75 65 20 20 3d 3e 20 {.....true =>
02b0: 22 f0 9f 94 84 20 65 6e 61 62 6c 65 64 22 2c 0a "š enabled",.
02c0: 09 09 09 09 66 61 6c 73 65 20 3d 3e 20 22 e2 9b ....false => "ā
02d0: 94 20 64 69 73 61 62 6c 65 64 22 2c 0a 09 09 09 disabled",....
02e0: 7d 2c 20 73 65 6c 66 2e 75 72 6c 29 3f 3b 0a 09 }, self.url)?;..
02f0: 09 69 66 20 6c 65 74 20 53 6f 6d 65 28 69 76 5f .if let Some(iv_
0300: 68 61 73 68 29 20 3d 20 26 73 65 6c 66 2e 69 76 hash) = &self.iv
0310: 5f 68 61 73 68 20 7b 0a 09 09 09 77 72 69 74 65 _hash {....write
0320: 21 28 66 2c 20 22 5c 6e 49 56 3a 20 60 7b 69 76 !(f, "\nIV: `{iv
0330: 5f 68 61 73 68 7d 60 22 29 3f 3b 0a 09 09 7d 0a _hash}`")?;...}.
0340: 09 09 69 66 20 6c 65 74 20 53 6f 6d 65 28 75 72 ..if let Some(ur
0350: 6c 5f 72 65 29 20 3d 20 26 73 65 6c 66 2e 75 72 l_re) = &self.ur
0360: 6c 5f 72 65 20 7b 0a 09 09 09 77 72 69 74 65 21 l_re {....write!
0370: 28 66 2c 20 22 5c 6e 52 45 3a 20 60 7b 75 72 6c (f, "\nRE: `{url
0380: 5f 72 65 7d 60 22 29 3f 3b 0a 09 09 7d 0a 09 09 _re}`")?;...}...
0390: 4f 6b 28 28 29 29 0a 09 7d 0a 7d 0a 0a 23 5b 64 Ok(())..}.}..#[d
03a0: 65 72 69 76 65 28 73 71 6c 78 3a 3a 46 72 6f 6d erive(sqlx::From
03b0: 52 6f 77 2c 20 44 65 62 75 67 29 5d 0a 70 75 62 Row, Debug)].pub
03c0: 20 73 74 72 75 63 74 20 53 6f 75 72 63 65 20 7b struct Source {
03d0: 0a 09 70 75 62 20 63 68 61 6e 6e 65 6c 5f 69 64 ..pub channel_id
03e0: 3a 20 69 36 34 2c 0a 09 70 75 62 20 75 72 6c 3a : i64,..pub url:
03f0: 20 53 74 72 69 6e 67 2c 0a 09 70 75 62 20 69 76 String,..pub iv
0400: 5f 68 61 73 68 3a 20 4f 70 74 69 6f 6e 3c 53 74 _hash: Option<St
0410: 72 69 6e 67 3e 2c 0a 09 70 75 62 20 6f 77 6e 65 ring>,..pub owne
0420: 72 3a 20 69 36 34 2c 0a 09 70 75 62 20 75 72 6c r: i64,..pub url
0430: 5f 72 65 3a 20 4f 70 74 69 6f 6e 3c 53 74 72 69 _re: Option<Stri
0440: 6e 67 3e 2c 0a 7d 0a 0a 23 5b 64 65 72 69 76 65 ng>,.}..#[derive
0450: 28 73 71 6c 78 3a 3a 46 72 6f 6d 52 6f 77 29 5d (sqlx::FromRow)]
0460: 0a 70 75 62 20 73 74 72 75 63 74 20 51 75 65 75 .pub struct Queu
0470: 65 20 7b 0a 09 70 75 62 20 73 6f 75 72 63 65 5f e {..pub source_
0480: 69 64 3a 20 4f 70 74 69 6f 6e 3c 69 33 32 3e 2c id: Option<i32>,
0490: 0a 09 70 75 62 20 6e 65 78 74 5f 66 65 74 63 68 ..pub next_fetch
04a0: 3a 20 4f 70 74 69 6f 6e 3c 44 61 74 65 54 69 6d : Option<DateTim
04b0: 65 3c 4c 6f 63 61 6c 3e 3e 2c 0a 09 70 75 62 20 e<Local>>,..pub
04c0: 6f 77 6e 65 72 3a 20 4f 70 74 69 6f 6e 3c 69 36 owner: Option<i6
04d0: 34 3e 2c 0a 09 70 75 62 20 6c 61 73 74 5f 73 63 4>,..pub last_sc
04e0: 72 61 70 65 3a 20 44 61 74 65 54 69 6d 65 3c 4c rape: DateTime<L
04f0: 6f 63 61 6c 3e 2c 0a 7d 0a 0a 23 5b 64 65 72 69 ocal>,.}..#[deri
0500: 76 65 28 43 6c 6f 6e 65 29 5d 0a 70 75 62 20 73 ve(Clone)].pub s
0510: 74 72 75 63 74 20 44 62 20 28 0a 09 41 72 63 3c truct Db (..Arc<
0520: 4d 75 74 65 78 3c 73 71 6c 78 3a 3a 50 6f 6f 6c Mutex<sqlx::Pool
0530: 3c 73 71 6c 78 3a 3a 50 6f 73 74 67 72 65 73 3e <sqlx::Postgres>
0540: 3e 3e 2c 0a 29 3b 0a 0a 69 6d 70 6c 20 44 62 20 >>,.);..impl Db
0550: 7b 0a 09 70 75 62 20 66 6e 20 6e 65 77 20 28 70 {..pub fn new (p
0560: 67 75 72 69 3a 20 26 73 74 72 29 20 2d 3e 20 52 guri: &str) -> R
0570: 65 73 75 6c 74 3c 44 62 3e 20 7b 0a 09 09 4f 6b esult<Db> {...Ok
0580: 28 44 62 20 28 0a 09 09 09 41 72 63 3a 3a 6e 65 (Db (....Arc::ne
0590: 77 28 4d 75 74 65 78 3a 3a 6e 65 77 28 50 67 50 w(Mutex::new(PgP
05a0: 6f 6f 6c 4f 70 74 69 6f 6e 73 3a 3a 6e 65 77 28 oolOptions::new(
05b0: 29 0a 09 09 09 09 2e 6d 61 78 5f 63 6f 6e 6e 65 )......max_conne
05c0: 63 74 69 6f 6e 73 28 35 29 0a 09 09 09 09 2e 61 ctions(5)......a
05d0: 63 71 75 69 72 65 5f 74 69 6d 65 6f 75 74 28 73 cquire_timeout(s
05e0: 74 64 3a 3a 74 69 6d 65 3a 3a 44 75 72 61 74 69 td::time::Durati
05f0: 6f 6e 3a 3a 6e 65 77 28 33 30 30 2c 20 30 29 29 on::new(300, 0))
0600: 0a 09 09 09 09 2e 69 64 6c 65 5f 74 69 6d 65 6f ......idle_timeo
0610: 75 74 28 73 74 64 3a 3a 74 69 6d 65 3a 3a 44 75 ut(std::time::Du
0620: 72 61 74 69 6f 6e 3a 3a 6e 65 77 28 36 30 2c 20 ration::new(60,
0630: 30 29 29 0a 09 09 09 09 2e 63 6f 6e 6e 65 63 74 0))......connect
0640: 5f 6c 61 7a 79 28 70 67 75 72 69 29 0a 09 09 09 _lazy(pguri)....
0650: 09 2e 73 74 61 63 6b 28 29 3f 29 29 2c 0a 09 09 ..stack()?)),...
0660: 29 29 0a 09 7d 0a 0a 09 70 75 62 20 61 73 79 6e ))..}...pub asyn
0670: 63 20 66 6e 20 62 65 67 69 6e 28 26 73 65 6c 66 c fn begin(&self
0680: 29 20 2d 3e 20 52 65 73 75 6c 74 3c 43 6f 6e 6e ) -> Result<Conn
0690: 3e 20 7b 0a 09 09 6c 65 74 20 70 6f 6f 6c 20 3d > {...let pool =
06a0: 20 73 65 6c 66 2e 30 2e 6c 6f 63 6b 5f 61 72 63 self.0.lock_arc
06b0: 28 29 2e 61 77 61 69 74 3b 0a 09 09 6c 65 74 20 ().await;...let
06c0: 63 6f 6e 6e 20 3d 20 43 6f 6e 6e 20 28 20 70 6f conn = Conn ( po
06d0: 6f 6c 2e 61 63 71 75 69 72 65 28 29 2e 61 77 61 ol.acquire().awa
06e0: 69 74 2e 73 74 61 63 6b 28 29 3f 20 29 3b 0a 09 it.stack()? );..
06f0: 09 4f 6b 28 63 6f 6e 6e 29 0a 09 7d 0a 7d 0a 0a .Ok(conn)..}.}..
0700: 70 75 62 20 73 74 72 75 63 74 20 43 6f 6e 6e 20 pub struct Conn
0710: 28 0a 09 50 6f 6f 6c 43 6f 6e 6e 65 63 74 69 6f (..PoolConnectio
0720: 6e 3c 50 6f 73 74 67 72 65 73 3e 2c 0a 29 3b 0a n<Postgres>,.);.
0730: 0a 69 6d 70 6c 20 43 6f 6e 6e 20 7b 0a 09 70 75 .impl Conn {..pu
0740: 62 20 61 73 79 6e 63 20 66 6e 20 61 64 64 5f 70 b async fn add_p
0750: 6f 73 74 20 28 26 6d 75 74 20 73 65 6c 66 2c 20 ost (&mut self,
0760: 73 6f 75 72 63 65 5f 69 64 3a 20 69 33 32 2c 20 source_id: i32,
0770: 64 61 74 65 3a 20 26 44 61 74 65 54 69 6d 65 3c date: &DateTime<
0780: 46 69 78 65 64 4f 66 66 73 65 74 3e 2c 20 70 6f FixedOffset>, po
0790: 73 74 5f 75 72 6c 3a 20 26 73 74 72 29 20 2d 3e st_url: &str) ->
07a0: 20 52 65 73 75 6c 74 3c 28 29 3e 20 7b 0a 09 09 Result<()> {...
07b0: 73 71 6c 78 3a 3a 71 75 65 72 79 28 22 69 6e 73 sqlx::query("ins
07c0: 65 72 74 20 69 6e 74 6f 20 72 73 73 74 67 5f 70 ert into rsstg_p
07d0: 6f 73 74 20 28 73 6f 75 72 63 65 5f 69 64 2c 20 ost (source_id,
07e0: 70 6f 73 74 65 64 2c 20 75 72 6c 29 20 76 61 6c posted, url) val
07f0: 75 65 73 20 28 24 31 2c 20 24 32 2c 20 24 33 29 ues ($1, $2, $3)
0800: 3b 22 29 0a 09 09 09 2e 62 69 6e 64 28 73 6f 75 ;").....bind(sou
0810: 72 63 65 5f 69 64 29 0a 09 09 09 2e 62 69 6e 64 rce_id).....bind
0820: 28 64 61 74 65 29 0a 09 09 09 2e 62 69 6e 64 28 (date).....bind(
0830: 70 6f 73 74 5f 75 72 6c 29 0a 09 09 09 2e 65 78 post_url).....ex
0840: 65 63 75 74 65 28 26 6d 75 74 20 2a 73 65 6c 66 ecute(&mut *self
0850: 2e 30 29 2e 61 77 61 69 74 2e 73 74 61 63 6b 28 .0).await.stack(
0860: 29 3f 3b 0a 09 09 4f 6b 28 28 29 29 0a 09 7d 0a )?;...Ok(())..}.
0870: 0a 09 70 75 62 20 61 73 79 6e 63 20 66 6e 20 63 ..pub async fn c
0880: 6c 65 61 6e 20 3c 49 3e 20 28 26 6d 75 74 20 73 lean <I> (&mut s
0890: 65 6c 66 2c 20 73 6f 75 72 63 65 5f 69 64 3a 20 elf, source_id:
08a0: 69 33 32 2c 20 6f 77 6e 65 72 3a 20 49 29 20 2d i32, owner: I) -
08b0: 3e 20 52 65 73 75 6c 74 3c 43 6f 77 3c 27 5f 2c > Result<Cow<'_,
08c0: 20 73 74 72 3e 3e 0a 09 77 68 65 72 65 20 49 3a str>>..where I:
08d0: 20 49 6e 74 6f 3c 69 36 34 3e 20 7b 0a 09 09 6d Into<i64> {...m
08e0: 61 74 63 68 20 73 71 6c 78 3a 3a 71 75 65 72 79 atch sqlx::query
08f0: 28 22 64 65 6c 65 74 65 20 66 72 6f 6d 20 72 73 ("delete from rs
0900: 73 74 67 5f 70 6f 73 74 20 70 20 75 73 69 6e 67 stg_post p using
0910: 20 72 73 73 74 67 5f 73 6f 75 72 63 65 20 73 20 rsstg_source s
0920: 77 68 65 72 65 20 70 2e 73 6f 75 72 63 65 5f 69 where p.source_i
0930: 64 20 3d 20 24 31 20 61 6e 64 20 6f 77 6e 65 72 d = $1 and owner
0940: 20 3d 20 24 32 20 61 6e 64 20 70 2e 73 6f 75 72 = $2 and p.sour
0950: 63 65 5f 69 64 20 3d 20 73 2e 73 6f 75 72 63 65 ce_id = s.source
0960: 5f 69 64 3b 22 29 0a 09 09 09 2e 62 69 6e 64 28 _id;").....bind(
0970: 73 6f 75 72 63 65 5f 69 64 29 0a 09 09 09 2e 62 source_id).....b
0980: 69 6e 64 28 6f 77 6e 65 72 2e 69 6e 74 6f 28 29 ind(owner.into()
0990: 29 0a 09 09 09 2e 65 78 65 63 75 74 65 28 26 6d ).....execute(&m
09a0: 75 74 20 2a 73 65 6c 66 2e 30 29 2e 61 77 61 69 ut *self.0).awai
09b0: 74 2e 73 74 61 63 6b 28 29 3f 2e 72 6f 77 73 5f t.stack()?.rows_
09c0: 61 66 66 65 63 74 65 64 28 29 20 7b 0a 09 09 09 affected() {....
09d0: 30 20 3d 3e 20 7b 20 4f 6b 28 22 4e 6f 20 64 61 0 => { Ok("No da
09e0: 74 61 20 66 6f 75 6e 64 20 66 6f 75 6e 64 2e 22 ta found found."
09f0: 2e 69 6e 74 6f 28 29 29 20 7d 2c 0a 09 09 09 78 .into()) },....x
0a00: 20 3d 3e 20 7b 20 4f 6b 28 66 6f 72 6d 61 74 21 => { Ok(format!
0a10: 28 22 7b 78 7d 20 70 6f 73 74 73 20 70 75 72 67 ("{x} posts purg
0a20: 65 64 2e 22 29 2e 69 6e 74 6f 28 29 29 20 7d 2c ed.").into()) },
0a30: 0a 09 09 7d 0a 09 7d 0a 0a 09 70 75 62 20 61 73 ...}..}...pub as
0a40: 79 6e 63 20 66 6e 20 64 65 6c 65 74 65 20 3c 49 ync fn delete <I
0a50: 3e 20 28 26 6d 75 74 20 73 65 6c 66 2c 20 73 6f > (&mut self, so
0a60: 75 72 63 65 5f 69 64 3a 20 69 33 32 2c 20 6f 77 urce_id: i32, ow
0a70: 6e 65 72 3a 20 49 29 20 2d 3e 20 52 65 73 75 6c ner: I) -> Resul
0a80: 74 3c 43 6f 77 3c 27 5f 2c 20 73 74 72 3e 3e 0a t<Cow<'_, str>>.
0a90: 09 77 68 65 72 65 20 49 3a 20 49 6e 74 6f 3c 69 .where I: Into<i
0aa0: 36 34 3e 20 7b 0a 09 09 6d 61 74 63 68 20 73 71 64> {...match sq
0ab0: 6c 78 3a 3a 71 75 65 72 79 28 22 64 65 6c 65 74 lx::query("delet
0ac0: 65 20 66 72 6f 6d 20 72 73 73 74 67 5f 73 6f 75 e from rsstg_sou
0ad0: 72 63 65 20 77 68 65 72 65 20 73 6f 75 72 63 65 rce where source
0ae0: 5f 69 64 20 3d 20 24 31 20 61 6e 64 20 6f 77 6e _id = $1 and own
0af0: 65 72 20 3d 20 24 32 3b 22 29 0a 09 09 09 2e 62 er = $2;").....b
0b00: 69 6e 64 28 73 6f 75 72 63 65 5f 69 64 29 0a 09 ind(source_id)..
0b10: 09 09 2e 62 69 6e 64 28 6f 77 6e 65 72 2e 69 6e ...bind(owner.in
0b20: 74 6f 28 29 29 0a 09 09 09 2e 65 78 65 63 75 74 to()).....execut
0b30: 65 28 26 6d 75 74 20 2a 73 65 6c 66 2e 30 29 2e e(&mut *self.0).
0b40: 61 77 61 69 74 2e 73 74 61 63 6b 28 29 3f 2e 72 await.stack()?.r
0b50: 6f 77 73 5f 61 66 66 65 63 74 65 64 28 29 20 7b ows_affected() {
0b60: 0a 09 09 09 30 20 3d 3e 20 7b 20 4f 6b 28 22 4e ....0 => { Ok("N
0b70: 6f 20 64 61 74 61 20 66 6f 75 6e 64 20 66 6f 75 o data found fou
0b80: 6e 64 2e 22 2e 69 6e 74 6f 28 29 29 20 7d 2c 0a nd.".into()) },.
0b90: 09 09 09 78 20 3d 3e 20 7b 20 4f 6b 28 66 6f 72 ...x => { Ok(for
0ba0: 6d 61 74 21 28 22 7b 78 7d 20 73 6f 75 72 63 65 mat!("{x} source
0bb0: 73 20 72 65 6d 6f 76 65 64 2e 22 29 2e 69 6e 74 s removed.").int
0bc0: 6f 28 29 29 20 7d 2c 0a 09 09 7d 0a 09 7d 0a 0a o()) },...}..}..
0bd0: 09 70 75 62 20 61 73 79 6e 63 20 66 6e 20 64 69 .pub async fn di
0be0: 73 61 62 6c 65 20 3c 49 3e 20 28 26 6d 75 74 20 sable <I> (&mut
0bf0: 73 65 6c 66 2c 20 73 6f 75 72 63 65 5f 69 64 3a self, source_id:
0c00: 20 69 33 32 2c 20 6f 77 6e 65 72 3a 20 49 29 20 i32, owner: I)
0c10: 2d 3e 20 52 65 73 75 6c 74 3c 26 73 74 72 3e 0a -> Result<&str>.
0c20: 09 77 68 65 72 65 20 49 3a 20 49 6e 74 6f 3c 69 .where I: Into<i
0c30: 36 34 3e 20 7b 0a 09 09 6d 61 74 63 68 20 73 71 64> {...match sq
0c40: 6c 78 3a 3a 71 75 65 72 79 28 22 75 70 64 61 74 lx::query("updat
0c50: 65 20 72 73 73 74 67 5f 73 6f 75 72 63 65 20 73 e rsstg_source s
0c60: 65 74 20 65 6e 61 62 6c 65 64 20 3d 20 66 61 6c et enabled = fal
0c70: 73 65 20 77 68 65 72 65 20 73 6f 75 72 63 65 5f se where source_
0c80: 69 64 20 3d 20 24 31 20 61 6e 64 20 6f 77 6e 65 id = $1 and owne
0c90: 72 20 3d 20 24 32 22 29 0a 09 09 09 2e 62 69 6e r = $2").....bin
0ca0: 64 28 73 6f 75 72 63 65 5f 69 64 29 0a 09 09 09 d(source_id)....
0cb0: 2e 62 69 6e 64 28 6f 77 6e 65 72 2e 69 6e 74 6f .bind(owner.into
0cc0: 28 29 29 0a 09 09 09 2e 65 78 65 63 75 74 65 28 ()).....execute(
0cd0: 26 6d 75 74 20 2a 73 65 6c 66 2e 30 29 2e 61 77 &mut *self.0).aw
0ce0: 61 69 74 2e 73 74 61 63 6b 28 29 3f 2e 72 6f 77 ait.stack()?.row
0cf0: 73 5f 61 66 66 65 63 74 65 64 28 29 20 7b 0a 09 s_affected() {..
0d00: 09 09 31 20 3d 3e 20 7b 20 4f 6b 28 22 53 6f 75 ..1 => { Ok("Sou
0d10: 72 63 65 20 64 69 73 61 62 6c 65 64 2e 22 29 20 rce disabled.")
0d20: 7d 2c 0a 09 09 09 30 20 3d 3e 20 7b 20 4f 6b 28 },....0 => { Ok(
0d30: 22 53 6f 75 72 63 65 20 6e 6f 74 20 66 6f 75 6e "Source not foun
0d40: 64 2e 22 29 20 7d 2c 0a 09 09 09 5f 20 3d 3e 20 d.") },...._ =>
0d50: 7b 20 62 61 69 6c 21 28 22 44 61 74 61 62 61 73 { bail!("Databas
0d60: 65 20 65 72 72 6f 72 2e 22 29 20 7d 2c 0a 09 09 e error.") },...
0d70: 7d 0a 09 7d 0a 0a 09 70 75 62 20 61 73 79 6e 63 }..}...pub async
0d80: 20 66 6e 20 65 6e 61 62 6c 65 20 3c 49 3e 20 28 fn enable <I> (
0d90: 26 6d 75 74 20 73 65 6c 66 2c 20 73 6f 75 72 63 &mut self, sourc
0da0: 65 5f 69 64 3a 20 69 33 32 2c 20 6f 77 6e 65 72 e_id: i32, owner
0db0: 3a 20 49 29 20 2d 3e 20 52 65 73 75 6c 74 3c 26 : I) -> Result<&
0dc0: 73 74 72 3e 0a 09 77 68 65 72 65 20 49 3a 20 49 str>..where I: I
0dd0: 6e 74 6f 3c 69 36 34 3e 20 7b 0a 09 09 6d 61 74 nto<i64> {...mat
0de0: 63 68 20 73 71 6c 78 3a 3a 71 75 65 72 79 28 22 ch sqlx::query("
0df0: 75 70 64 61 74 65 20 72 73 73 74 67 5f 73 6f 75 update rsstg_sou
0e00: 72 63 65 20 73 65 74 20 65 6e 61 62 6c 65 64 20 rce set enabled
0e10: 3d 20 74 72 75 65 20 77 68 65 72 65 20 73 6f 75 = true where sou
0e20: 72 63 65 5f 69 64 20 3d 20 24 31 20 61 6e 64 20 rce_id = $1 and
0e30: 6f 77 6e 65 72 20 3d 20 24 32 22 29 0a 09 09 09 owner = $2")....
0e40: 2e 62 69 6e 64 28 73 6f 75 72 63 65 5f 69 64 29 .bind(source_id)
0e50: 0a 09 09 09 2e 62 69 6e 64 28 6f 77 6e 65 72 2e .....bind(owner.
0e60: 69 6e 74 6f 28 29 29 0a 09 09 09 2e 65 78 65 63 into()).....exec
0e70: 75 74 65 28 26 6d 75 74 20 2a 73 65 6c 66 2e 30 ute(&mut *self.0
0e80: 29 2e 61 77 61 69 74 2e 73 74 61 63 6b 28 29 3f ).await.stack()?
0e90: 2e 72 6f 77 73 5f 61 66 66 65 63 74 65 64 28 29 .rows_affected()
0ea0: 20 7b 0a 09 09 09 31 20 3d 3e 20 7b 20 4f 6b 28 {....1 => { Ok(
0eb0: 22 53 6f 75 72 63 65 20 65 6e 61 62 6c 65 64 2e "Source enabled.
0ec0: 22 29 20 7d 2c 0a 09 09 09 30 20 3d 3e 20 7b 20 ") },....0 => {
0ed0: 4f 6b 28 22 53 6f 75 72 63 65 20 6e 6f 74 20 66 Ok("Source not f
0ee0: 6f 75 6e 64 2e 22 29 20 7d 2c 0a 09 09 09 5f 20 ound.") },...._
0ef0: 3d 3e 20 7b 20 62 61 69 6c 21 28 22 44 61 74 61 => { bail!("Data
0f00: 62 61 73 65 20 65 72 72 6f 72 2e 22 29 20 7d 2c base error.") },
0f10: 0a 09 09 7d 0a 09 7d 0a 0a 09 2f 2f 2f 20 43 68 ...}..}.../// Ch
0f20: 65 63 6b 73 20 77 68 65 74 68 65 72 20 61 20 70 ecks whether a p
0f30: 6f 73 74 20 77 69 74 68 20 74 68 65 20 67 69 76 ost with the giv
0f40: 65 6e 20 55 52 4c 20 65 78 69 73 74 73 20 66 6f en URL exists fo
0f50: 72 20 74 68 65 20 73 70 65 63 69 66 69 65 64 20 r the specified
0f60: 73 6f 75 72 63 65 2e 0a 09 2f 2f 2f 0a 09 2f 2f source...///..//
0f70: 2f 20 23 20 50 61 72 61 6d 65 74 65 72 73 0a 09 / # Parameters..
0f80: 2f 2f 2f 20 2d 20 60 70 6f 73 74 5f 75 72 6c 60 /// - `post_url`
0f90: 3a 20 54 68 65 20 55 52 4c 20 6f 66 20 74 68 65 : The URL of the
0fa0: 20 70 6f 73 74 20 74 6f 20 63 68 65 63 6b 2e 0a post to check..
0fb0: 09 2f 2f 2f 20 2d 20 60 69 64 60 3a 20 54 68 65 ./// - `id`: The
0fc0: 20 73 6f 75 72 63 65 20 69 64 65 6e 74 69 66 69 source identifi
0fd0: 65 72 20 28 63 6f 6e 76 65 72 74 65 64 20 74 6f er (converted to
0fe0: 20 60 69 36 34 60 29 2e 0a 09 2f 2f 2f 0a 09 2f `i64`)...///../
0ff0: 2f 2f 20 23 20 52 65 74 75 72 6e 73 0a 09 2f 2f // # Returns..//
1000: 2f 20 60 74 72 75 65 60 20 69 66 20 61 20 70 6f / `true` if a po
1010: 73 74 20 77 69 74 68 20 74 68 65 20 55 52 4c 20 st with the URL
1020: 65 78 69 73 74 73 20 66 6f 72 20 74 68 65 20 73 exists for the s
1030: 6f 75 72 63 65 2c 20 60 66 61 6c 73 65 60 20 6f ource, `false` o
1040: 74 68 65 72 77 69 73 65 2e 0a 09 70 75 62 20 61 therwise...pub a
1050: 73 79 6e 63 20 66 6e 20 65 78 69 73 74 73 20 3c sync fn exists <
1060: 49 3e 20 28 26 6d 75 74 20 73 65 6c 66 2c 20 70 I> (&mut self, p
1070: 6f 73 74 5f 75 72 6c 3a 20 26 73 74 72 2c 20 69 ost_url: &str, i
1080: 64 3a 20 49 29 20 2d 3e 20 52 65 73 75 6c 74 3c d: I) -> Result<
1090: 62 6f 6f 6c 3e 0a 09 77 68 65 72 65 20 49 3a 20 bool>..where I:
10a0: 49 6e 74 6f 3c 69 36 34 3e 20 7b 0a 09 09 6c 65 Into<i64> {...le
10b0: 74 20 72 6f 77 20 3d 20 73 71 6c 78 3a 3a 71 75 t row = sqlx::qu
10c0: 65 72 79 28 22 73 65 6c 65 63 74 20 65 78 69 73 ery("select exis
10d0: 74 73 28 73 65 6c 65 63 74 20 74 72 75 65 20 66 ts(select true f
10e0: 72 6f 6d 20 72 73 73 74 67 5f 70 6f 73 74 20 77 rom rsstg_post w
10f0: 68 65 72 65 20 75 72 6c 20 3d 20 24 31 20 61 6e here url = $1 an
1100: 64 20 73 6f 75 72 63 65 5f 69 64 20 3d 20 24 32 d source_id = $2
1110: 29 20 61 73 20 65 78 69 73 74 73 3b 22 29 0a 09 ) as exists;")..
1120: 09 09 2e 62 69 6e 64 28 70 6f 73 74 5f 75 72 6c ...bind(post_url
1130: 29 0a 09 09 09 2e 62 69 6e 64 28 69 64 2e 69 6e ).....bind(id.in
1140: 74 6f 28 29 29 0a 09 09 09 2e 66 65 74 63 68 5f to()).....fetch_
1150: 6f 6e 65 28 26 6d 75 74 20 2a 73 65 6c 66 2e 30 one(&mut *self.0
1160: 29 2e 61 77 61 69 74 2e 73 74 61 63 6b 28 29 3f ).await.stack()?
1170: 3b 0a 09 09 72 6f 77 2e 74 72 79 5f 67 65 74 28 ;...row.try_get(
1180: 22 65 78 69 73 74 73 22 29 0a 09 09 09 2e 73 74 "exists").....st
1190: 61 63 6b 5f 65 72 72 28 22 44 61 74 61 62 61 73 ack_err("Databas
11a0: 65 20 65 72 72 6f 72 3a 20 63 61 6e 27 74 20 63 e error: can't c
11b0: 68 65 63 6b 20 77 68 65 74 68 65 72 20 70 6f 73 heck whether pos
11c0: 74 20 65 78 69 73 74 73 2e 22 29 0a 09 7d 0a 0a t exists.")..}..
11d0: 09 2f 2f 2f 20 47 65 74 20 61 6c 6c 20 70 65 6e ./// Get all pen
11e0: 64 69 6e 67 20 65 76 65 6e 74 73 20 66 6f 72 20 ding events for
11f0: 28 6e 6f 77 20 2b 20 31 20 6d 69 6e 75 74 65 29 (now + 1 minute)
1200: 0a 09 70 75 62 20 61 73 79 6e 63 20 66 6e 20 67 ..pub async fn g
1210: 65 74 5f 71 75 65 75 65 20 28 26 6d 75 74 20 73 et_queue (&mut s
1220: 65 6c 66 29 20 2d 3e 20 52 65 73 75 6c 74 3c 56 elf) -> Result<V
1230: 65 63 3c 51 75 65 75 65 3e 3e 20 7b 0a 09 09 6c ec<Queue>> {...l
1240: 65 74 20 62 6c 6f 63 6b 3a 20 56 65 63 3c 51 75 et block: Vec<Qu
1250: 65 75 65 3e 20 3d 20 73 71 6c 78 3a 3a 71 75 65 eue> = sqlx::que
1260: 72 79 5f 61 73 28 22 73 65 6c 65 63 74 20 73 6f ry_as("select so
1270: 75 72 63 65 5f 69 64 2c 20 6e 65 78 74 5f 66 65 urce_id, next_fe
1280: 74 63 68 2c 20 6f 77 6e 65 72 2c 20 6c 61 73 74 tch, owner, last
1290: 5f 73 63 72 61 70 65 20 66 72 6f 6d 20 72 73 73 _scrape from rss
12a0: 74 67 5f 6f 72 64 65 72 20 6e 61 74 75 72 61 6c tg_order natural
12b0: 20 6c 65 66 74 20 6a 6f 69 6e 20 72 73 73 74 67 left join rsstg
12c0: 5f 73 6f 75 72 63 65 20 77 68 65 72 65 20 6e 65 _source where ne
12d0: 78 74 5f 66 65 74 63 68 20 3c 20 6e 6f 77 28 29 xt_fetch < now()
12e0: 20 2b 20 69 6e 74 65 72 76 61 6c 20 27 31 20 6d + interval '1 m
12f0: 69 6e 75 74 65 27 3b 22 29 0a 09 09 09 2e 66 65 inute';").....fe
1300: 74 63 68 5f 61 6c 6c 28 26 6d 75 74 20 2a 73 65 tch_all(&mut *se
1310: 6c 66 2e 30 29 2e 61 77 61 69 74 2e 73 74 61 63 lf.0).await.stac
1320: 6b 28 29 3f 3b 0a 09 09 4f 6b 28 62 6c 6f 63 6b k()?;...Ok(block
1330: 29 0a 09 7d 0a 0a 09 70 75 62 20 61 73 79 6e 63 )..}...pub async
1340: 20 66 6e 20 67 65 74 5f 6c 69 73 74 20 3c 49 3e fn get_list <I>
1350: 20 28 26 6d 75 74 20 73 65 6c 66 2c 20 6f 77 6e (&mut self, own
1360: 65 72 3a 20 49 29 20 2d 3e 20 52 65 73 75 6c 74 er: I) -> Result
1370: 3c 56 65 63 3c 4c 69 73 74 3e 3e 0a 09 77 68 65 <Vec<List>>..whe
1380: 72 65 20 49 3a 20 49 6e 74 6f 3c 69 36 34 3e 20 re I: Into<i64>
1390: 7b 0a 09 09 6c 65 74 20 73 6f 75 72 63 65 3a 20 {...let source:
13a0: 56 65 63 3c 4c 69 73 74 3e 20 3d 20 73 71 6c 78 Vec<List> = sqlx
13b0: 3a 3a 71 75 65 72 79 5f 61 73 28 22 73 65 6c 65 ::query_as("sele
13c0: 63 74 20 73 6f 75 72 63 65 5f 69 64 2c 20 63 68 ct source_id, ch
13d0: 61 6e 6e 65 6c 2c 20 65 6e 61 62 6c 65 64 2c 20 annel, enabled,
13e0: 75 72 6c 2c 20 69 76 5f 68 61 73 68 2c 20 75 72 url, iv_hash, ur
13f0: 6c 5f 72 65 20 66 72 6f 6d 20 72 73 73 74 67 5f l_re from rsstg_
1400: 73 6f 75 72 63 65 20 77 68 65 72 65 20 6f 77 6e source where own
1410: 65 72 20 3d 20 24 31 20 6f 72 64 65 72 20 62 79 er = $1 order by
1420: 20 73 6f 75 72 63 65 5f 69 64 22 29 0a 09 09 09 source_id")....
1430: 2e 62 69 6e 64 28 6f 77 6e 65 72 2e 69 6e 74 6f .bind(owner.into
1440: 28 29 29 0a 09 09 09 2e 66 65 74 63 68 5f 61 6c ()).....fetch_al
1450: 6c 28 26 6d 75 74 20 2a 73 65 6c 66 2e 30 29 2e l(&mut *self.0).
1460: 61 77 61 69 74 2e 73 74 61 63 6b 28 29 3f 3b 0a await.stack()?;.
1470: 09 09 4f 6b 28 73 6f 75 72 63 65 29 0a 09 7d 0a ..Ok(source)..}.
1480: 0a 09 70 75 62 20 61 73 79 6e 63 20 66 6e 20 67 ..pub async fn g
1490: 65 74 5f 6f 6e 65 20 3c 49 3e 20 28 26 6d 75 74 et_one <I> (&mut
14a0: 20 73 65 6c 66 2c 20 6f 77 6e 65 72 3a 20 49 2c self, owner: I,
14b0: 20 69 64 3a 20 69 33 32 29 20 2d 3e 20 52 65 73 id: i32) -> Res
14c0: 75 6c 74 3c 4f 70 74 69 6f 6e 3c 4c 69 73 74 3e ult<Option<List>
14d0: 3e 0a 09 77 68 65 72 65 20 49 3a 20 49 6e 74 6f >..where I: Into
14e0: 3c 69 36 34 3e 20 7b 0a 09 09 6c 65 74 20 73 6f <i64> {...let so
14f0: 75 72 63 65 3a 20 4f 70 74 69 6f 6e 3c 4c 69 73 urce: Option<Lis
1500: 74 3e 20 3d 20 73 71 6c 78 3a 3a 71 75 65 72 79 t> = sqlx::query
1510: 5f 61 73 28 22 73 65 6c 65 63 74 20 73 6f 75 72 _as("select sour
1520: 63 65 5f 69 64 2c 20 63 68 61 6e 6e 65 6c 2c 20 ce_id, channel,
1530: 65 6e 61 62 6c 65 64 2c 20 75 72 6c 2c 20 69 76 enabled, url, iv
1540: 5f 68 61 73 68 2c 20 75 72 6c 5f 72 65 20 66 72 _hash, url_re fr
1550: 6f 6d 20 72 73 73 74 67 5f 73 6f 75 72 63 65 20 om rsstg_source
1560: 77 68 65 72 65 20 6f 77 6e 65 72 20 3d 20 24 31 where owner = $1
1570: 20 61 6e 64 20 73 6f 75 72 63 65 5f 69 64 20 3d and source_id =
1580: 20 24 32 22 29 0a 09 09 09 2e 62 69 6e 64 28 6f $2").....bind(o
1590: 77 6e 65 72 2e 69 6e 74 6f 28 29 29 0a 09 09 09 wner.into())....
15a0: 2e 62 69 6e 64 28 69 64 29 0a 09 09 09 2e 66 65 .bind(id).....fe
15b0: 74 63 68 5f 6f 70 74 69 6f 6e 61 6c 28 26 6d 75 tch_optional(&mu
15c0: 74 20 2a 73 65 6c 66 2e 30 29 2e 61 77 61 69 74 t *self.0).await
15d0: 2e 73 74 61 63 6b 28 29 3f 3b 0a 09 09 4f 6b 28 .stack()?;...Ok(
15e0: 73 6f 75 72 63 65 29 0a 09 7d 0a 0a 09 70 75 62 source)..}...pub
15f0: 20 61 73 79 6e 63 20 66 6e 20 67 65 74 5f 73 6f async fn get_so
1600: 75 72 63 65 20 3c 49 3e 20 28 26 6d 75 74 20 73 urce <I> (&mut s
1610: 65 6c 66 2c 20 69 64 3a 20 69 33 32 2c 20 6f 77 elf, id: i32, ow
1620: 6e 65 72 3a 20 49 29 20 2d 3e 20 52 65 73 75 6c ner: I) -> Resul
1630: 74 3c 53 6f 75 72 63 65 3e 0a 09 77 68 65 72 65 t<Source>..where
1640: 20 49 3a 20 49 6e 74 6f 3c 69 36 34 3e 20 7b 0a I: Into<i64> {.
1650: 09 09 6c 65 74 20 73 6f 75 72 63 65 3a 20 53 6f ..let source: So
1660: 75 72 63 65 20 3d 20 73 71 6c 78 3a 3a 71 75 65 urce = sqlx::que
1670: 72 79 5f 61 73 28 22 73 65 6c 65 63 74 20 63 68 ry_as("select ch
1680: 61 6e 6e 65 6c 5f 69 64 2c 20 75 72 6c 2c 20 69 annel_id, url, i
1690: 76 5f 68 61 73 68 2c 20 6f 77 6e 65 72 2c 20 75 v_hash, owner, u
16a0: 72 6c 5f 72 65 20 66 72 6f 6d 20 72 73 73 74 67 rl_re from rsstg
16b0: 5f 73 6f 75 72 63 65 20 77 68 65 72 65 20 73 6f _source where so
16c0: 75 72 63 65 5f 69 64 20 3d 20 24 31 20 61 6e 64 urce_id = $1 and
16d0: 20 6f 77 6e 65 72 20 3d 20 24 32 22 29 0a 09 09 owner = $2")...
16e0: 09 2e 62 69 6e 64 28 69 64 29 0a 09 09 09 2e 62 ..bind(id).....b
16f0: 69 6e 64 28 6f 77 6e 65 72 2e 69 6e 74 6f 28 29 ind(owner.into()
1700: 29 0a 09 09 09 2e 66 65 74 63 68 5f 6f 6e 65 28 ).....fetch_one(
1710: 26 6d 75 74 20 2a 73 65 6c 66 2e 30 29 2e 61 77 &mut *self.0).aw
1720: 61 69 74 2e 73 74 61 63 6b 28 29 3f 3b 0a 09 09 ait.stack()?;...
1730: 4f 6b 28 73 6f 75 72 63 65 29 0a 09 7d 0a 0a 09 Ok(source)..}...
1740: 70 75 62 20 61 73 79 6e 63 20 66 6e 20 73 65 74 pub async fn set
1750: 5f 73 63 72 61 70 65 20 3c 49 3e 20 28 26 6d 75 _scrape <I> (&mu
1760: 74 20 73 65 6c 66 2c 20 69 64 3a 20 49 29 20 2d t self, id: I) -
1770: 3e 20 52 65 73 75 6c 74 3c 28 29 3e 0a 09 77 68 > Result<()>..wh
1780: 65 72 65 20 49 3a 20 49 6e 74 6f 3c 69 36 34 3e ere I: Into<i64>
1790: 20 7b 0a 09 09 73 71 6c 78 3a 3a 71 75 65 72 79 {...sqlx::query
17a0: 28 22 75 70 64 61 74 65 20 72 73 73 74 67 5f 73 ("update rsstg_s
17b0: 6f 75 72 63 65 20 73 65 74 20 6c 61 73 74 5f 73 ource set last_s
17c0: 63 72 61 70 65 20 3d 20 6e 6f 77 28 29 20 77 68 crape = now() wh
17d0: 65 72 65 20 73 6f 75 72 63 65 5f 69 64 20 3d 20 ere source_id =
17e0: 24 31 3b 22 29 0a 09 09 09 2e 62 69 6e 64 28 69 $1;").....bind(i
17f0: 64 2e 69 6e 74 6f 28 29 29 0a 09 09 09 2e 65 78 d.into()).....ex
1800: 65 63 75 74 65 28 26 6d 75 74 20 2a 73 65 6c 66 ecute(&mut *self
1810: 2e 30 29 2e 61 77 61 69 74 2e 73 74 61 63 6b 28 .0).await.stack(
1820: 29 3f 3b 0a 09 09 4f 6b 28 28 29 29 0a 09 7d 0a )?;...Ok(())..}.
1830: 0a 09 70 75 62 20 61 73 79 6e 63 20 66 6e 20 75 ..pub async fn u
1840: 70 64 61 74 65 20 3c 49 3e 20 28 26 6d 75 74 20 pdate <I> (&mut
1850: 73 65 6c 66 2c 20 75 70 64 61 74 65 3a 20 4f 70 self, update: Op
1860: 74 69 6f 6e 3c 69 33 32 3e 2c 20 63 68 61 6e 6e tion<i32>, chann
1870: 65 6c 3a 20 26 73 74 72 2c 20 63 68 61 6e 6e 65 el: &str, channe
1880: 6c 5f 69 64 3a 20 69 36 34 2c 20 75 72 6c 3a 20 l_id: i64, url:
1890: 26 73 74 72 2c 20 69 76 5f 68 61 73 68 3a 20 4f &str, iv_hash: O
18a0: 70 74 69 6f 6e 3c 26 73 74 72 3e 2c 20 75 72 6c ption<&str>, url
18b0: 5f 72 65 3a 20 4f 70 74 69 6f 6e 3c 26 73 74 72 _re: Option<&str
18c0: 3e 2c 20 6f 77 6e 65 72 3a 20 49 29 20 2d 3e 20 >, owner: I) ->
18d0: 52 65 73 75 6c 74 3c 26 73 74 72 3e 0a 09 77 68 Result<&str>..wh
18e0: 65 72 65 20 49 3a 20 49 6e 74 6f 3c 69 36 34 3e ere I: Into<i64>
18f0: 20 7b 0a 09 09 6d 61 74 63 68 20 6d 61 74 63 68 {...match match
1900: 20 75 70 64 61 74 65 20 7b 0a 09 09 09 09 53 6f update {.....So
1910: 6d 65 28 69 64 29 20 3d 3e 20 7b 0a 09 09 09 09 me(id) => {.....
1920: 09 73 71 6c 78 3a 3a 71 75 65 72 79 28 22 75 70 .sqlx::query("up
1930: 64 61 74 65 20 72 73 73 74 67 5f 73 6f 75 72 63 date rsstg_sourc
1940: 65 20 73 65 74 20 63 68 61 6e 6e 65 6c 5f 69 64 e set channel_id
1950: 20 3d 20 24 32 2c 20 75 72 6c 20 3d 20 24 33 2c = $2, url = $3,
1960: 20 69 76 5f 68 61 73 68 20 3d 20 24 34 2c 20 6f iv_hash = $4, o
1970: 77 6e 65 72 20 3d 20 24 35 2c 20 63 68 61 6e 6e wner = $5, chann
1980: 65 6c 20 3d 20 24 36 2c 20 75 72 6c 5f 72 65 20 el = $6, url_re
1990: 3d 20 24 37 20 77 68 65 72 65 20 73 6f 75 72 63 = $7 where sourc
19a0: 65 5f 69 64 20 3d 20 24 31 22 29 0a 09 09 09 09 e_id = $1").....
19b0: 09 09 2e 62 69 6e 64 28 69 64 29 0a 09 09 09 09 ...bind(id).....
19c0: 7d 2c 0a 09 09 09 09 4e 6f 6e 65 20 3d 3e 20 7b },.....None => {
19d0: 0a 09 09 09 09 09 73 71 6c 78 3a 3a 71 75 65 72 ......sqlx::quer
19e0: 79 28 22 69 6e 73 65 72 74 20 69 6e 74 6f 20 72 y("insert into r
19f0: 73 73 74 67 5f 73 6f 75 72 63 65 20 28 63 68 61 sstg_source (cha
1a00: 6e 6e 65 6c 5f 69 64 2c 20 75 72 6c 2c 20 69 76 nnel_id, url, iv
1a10: 5f 68 61 73 68 2c 20 6f 77 6e 65 72 2c 20 63 68 _hash, owner, ch
1a20: 61 6e 6e 65 6c 2c 20 75 72 6c 5f 72 65 29 20 76 annel, url_re) v
1a30: 61 6c 75 65 73 20 28 24 31 2c 20 24 32 2c 20 24 alues ($1, $2, $
1a40: 33 2c 20 24 34 2c 20 24 35 2c 20 24 36 29 22 29 3, $4, $5, $6)")
1a50: 0a 09 09 09 09 7d 2c 0a 09 09 09 7d 0a 09 09 09 .....},....}....
1a60: 09 2e 62 69 6e 64 28 63 68 61 6e 6e 65 6c 5f 69 ..bind(channel_i
1a70: 64 29 0a 09 09 09 09 2e 62 69 6e 64 28 75 72 6c d)......bind(url
1a80: 29 0a 09 09 09 09 2e 62 69 6e 64 28 69 76 5f 68 )......bind(iv_h
1a90: 61 73 68 29 0a 09 09 09 09 2e 62 69 6e 64 28 6f ash)......bind(o
1aa0: 77 6e 65 72 2e 69 6e 74 6f 28 29 29 0a 09 09 09 wner.into())....
1ab0: 09 2e 62 69 6e 64 28 63 68 61 6e 6e 65 6c 29 0a ..bind(channel).
1ac0: 09 09 09 09 2e 62 69 6e 64 28 75 72 6c 5f 72 65 .....bind(url_re
1ad0: 29 0a 09 09 09 09 2e 65 78 65 63 75 74 65 28 26 )......execute(&
1ae0: 6d 75 74 20 2a 73 65 6c 66 2e 30 29 2e 61 77 61 mut *self.0).awa
1af0: 69 74 0a 09 09 09 7b 0a 09 09 09 4f 6b 28 5f 29 it....{....Ok(_)
1b00: 20 3d 3e 20 4f 6b 28 6d 61 74 63 68 20 75 70 64 => Ok(match upd
1b10: 61 74 65 20 7b 0a 09 09 09 09 53 6f 6d 65 28 5f ate {.....Some(_
1b20: 29 20 3d 3e 20 22 43 68 61 6e 6e 65 6c 20 75 70 ) => "Channel up
1b30: 64 61 74 65 64 2e 22 2c 0a 09 09 09 09 4e 6f 6e dated.",.....Non
1b40: 65 20 3d 3e 20 22 43 68 61 6e 6e 65 6c 20 61 64 e => "Channel ad
1b50: 64 65 64 2e 22 2c 0a 09 09 09 7d 29 2c 0a 09 09 ded.",....}),...
1b60: 09 45 72 72 28 73 71 6c 78 3a 3a 45 72 72 6f 72 .Err(sqlx::Error
1b70: 3a 3a 44 61 74 61 62 61 73 65 28 65 72 72 29 29 ::Database(err))
1b80: 20 3d 3e 20 7b 0a 09 09 09 09 6d 61 74 63 68 20 => {.....match
1b90: 65 72 72 2e 64 6f 77 6e 63 61 73 74 3a 3a 3c 73 err.downcast::<s
1ba0: 71 6c 78 3a 3a 70 6f 73 74 67 72 65 73 3a 3a 50 qlx::postgres::P
1bb0: 67 44 61 74 61 62 61 73 65 45 72 72 6f 72 3e 28 gDatabaseError>(
1bc0: 29 2e 72 6f 75 74 69 6e 65 28 29 20 7b 0a 09 09 ).routine() {...
1bd0: 09 09 09 53 6f 6d 65 28 22 5f 62 74 5f 63 68 65 ...Some("_bt_che
1be0: 63 6b 5f 75 6e 69 71 75 65 22 2c 20 29 20 3d 3e ck_unique", ) =>
1bf0: 20 7b 0a 09 09 09 09 09 09 4f 6b 28 22 44 75 70 {.......Ok("Dup
1c00: 6c 69 63 61 74 65 20 6b 65 79 2e 22 29 0a 09 09 licate key.")...
1c10: 09 09 09 7d 2c 0a 09 09 09 09 09 53 6f 6d 65 28 ...},......Some(
1c20: 5f 29 20 3d 3e 20 7b 0a 09 09 09 09 09 09 4f 6b _) => {.......Ok
1c30: 28 22 44 61 74 61 62 61 73 65 20 65 72 72 6f 72 ("Database error
1c40: 2e 22 29 0a 09 09 09 09 09 7d 2c 0a 09 09 09 09 .")......},.....
1c50: 09 4e 6f 6e 65 20 3d 3e 20 7b 0a 09 09 09 09 09 .None => {......
1c60: 09 4f 6b 28 22 4e 6f 20 64 61 74 61 62 61 73 65 .Ok("No database
1c70: 20 65 72 72 6f 72 20 65 78 74 72 61 63 74 65 64 error extracted
1c80: 2e 22 29 0a 09 09 09 09 09 7d 2c 0a 09 09 09 09 .")......},.....
1c90: 7d 0a 09 09 09 7d 2c 0a 09 09 09 45 72 72 28 65 }....},....Err(e
1ca0: 72 72 29 20 3d 3e 20 7b 0a 09 09 09 09 62 61 69 rr) => {.....bai
1cb0: 6c 21 28 22 53 6f 72 72 79 2c 20 75 6e 6b 6e 6f l!("Sorry, unkno
1cc0: 77 6e 20 65 72 72 6f 72 3a 5c 6e 7b 65 72 72 3a wn error:\n{err:
1cd0: 23 3f 7d 5c 6e 22 29 3b 0a 09 09 09 7d 2c 0a 09 #?}\n");....},..
1ce0: 09 7d 0a 09 7d 0a 7d 0a .}..}.}.