diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-08-22 20:23:53 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-08-22 20:23:53 +0200 |
commit | d71f3efe57646d639ae19b26dbea5115c219557c (patch) | |
tree | 4728a25dd065b829cb05f5310499d648cbe53f6a /src/storage/video_database | |
parent | refactor(cli): Remove the useless `concurrent_processes` flag from `update` (diff) | |
download | yt-d71f3efe57646d639ae19b26dbea5115c219557c.tar.gz yt-d71f3efe57646d639ae19b26dbea5115c219557c.zip |
refactor(storage): Make all URL parsings panic
These URLs should be checked *before* they are written to the database, thus being unable to decode them after they've been read from the database is an application bug and not a user input issue.
Diffstat (limited to 'src/storage/video_database')
-rw-r--r-- | src/storage/video_database/downloader.rs | 8 | ||||
-rw-r--r-- | src/storage/video_database/getters.rs | 6 |
2 files changed, 7 insertions, 7 deletions
diff --git a/src/storage/video_database/downloader.rs b/src/storage/video_database/downloader.rs index c04ab8d..a7f6cad 100644 --- a/src/storage/video_database/downloader.rs +++ b/src/storage/video_database/downloader.rs @@ -43,7 +43,7 @@ pub async fn get_next_uncached_video(app: &App) -> Result<Option<Video>> { let base = result?; let thumbnail_url = if let Some(url) = &base.thumbnail_url { - Some(Url::parse(&url)?) + Some(Url::parse(&url).expect("Parsing this as url should always work")) } else { None }; @@ -72,7 +72,7 @@ pub async fn get_next_uncached_video(app: &App) -> Result<Option<Video>> { status_change, thumbnail_url, title: base.title.clone(), - url: Url::parse(&base.url)?, + url: Url::parse(&base.url).expect("Parsing this as url should always work"), }; Ok(Some(video)) @@ -100,7 +100,7 @@ pub async fn get_next_video_watchable(app: &App) -> Result<Option<Video>> { let base = result?; let thumbnail_url = if let Some(url) = &base.thumbnail_url { - Some(Url::parse(&url)?) + Some(Url::parse(&url).expect("Parsing this as url should always work")) } else { None }; @@ -129,7 +129,7 @@ pub async fn get_next_video_watchable(app: &App) -> Result<Option<Video>> { status_change, thumbnail_url, title: base.title.clone(), - url: Url::parse(&base.url)?, + url: Url::parse(&base.url).expect("Parsing this as url should always work"), }; Ok(Some(video)) diff --git a/src/storage/video_database/getters.rs b/src/storage/video_database/getters.rs index fd363fb..b912276 100644 --- a/src/storage/video_database/getters.rs +++ b/src/storage/video_database/getters.rs @@ -33,7 +33,7 @@ use super::{MpvOptions, VideoOptions, VideoStatus, YtDlpOptions}; macro_rules! video_from_record { ($record:expr) => { let thumbnail_url = if let Some(url) = &$record.thumbnail_url { - Some(Url::parse(&url)?) + Some(Url::parse(&url).expect("Parsing this as url should always work")) } else { None }; @@ -54,7 +54,7 @@ macro_rules! video_from_record { status: VideoStatus::from_db_integer($record.status), thumbnail_url, title: $record.title.clone(), - url: Url::parse(&$record.url)?, + url: Url::parse(&$record.url).expect("Parsing this as url should always work"), priority: $record.priority, status_change: if $record.status_change == 1 { true @@ -147,7 +147,7 @@ pub async fn get_videos( status: VideoStatus::from_db_integer(base.get("status")), thumbnail_url, title: base.get::<String, &str>("title").to_owned(), - url: Url::parse(base.get("url"))?, + url: Url::parse(base.get("url")).expect("Parsing this as url should always work"), priority: base.get("priority"), status_change: { let val = base.get::<i64, &str>("status_change"); |