diff --git a/README.md b/README.md index 8184a54..6c7dbf2 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ The API will be available on `http://localhost:8000`. For example, you can try ` Unsupported config option for services: 'sb-mirror' ``` then you are using an old version of `docker compose` which does not fully support the Compose Specification and [requires a 'version' key to differentiate the file from a V1 compose file](https://docs.docker.com/compose/compose-file/#version-top-level-element). Try appending `version: "3"` to the file. - + * On the first run of `docker compose`, even after the database files are downloaded, you may see errors like `could not open file "/mirror/sponsorTimes.csv" for reading: Permission denied`. Assuming the permissions on the `.csv` files are actually set to be world-readable, you might be able to fix this by stopping and restarting `docker compose`. * To access the PosgresQL database directly, you can `docker exec -ti postgres-sb-mirror bash -c 'psql $POSTGRES_DB $POSTGRES_USER'`. diff --git a/src/routes.rs b/src/routes.rs index 609d611..5521aaa 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -49,7 +49,7 @@ pub async fn skip_segments( } let sponsors = find_skip_segments(VideoName::ByHashPrefix(hash.clone()), categories, db).await; - + if sponsors.is_empty() { // Fall back to central Sponsorblock server let resp = reqwest::get(format!( @@ -65,7 +65,7 @@ pub async fn skip_segments( return content::RawJson(resp); } - + return content::RawJson(serde_json::to_string(&sponsors).unwrap()); } @@ -82,7 +82,7 @@ pub async fn skip_segments_by_id( } let sponsors = find_skip_segments(VideoName::ByID(videoID.clone()), categories, db).await; - + if sponsors.is_empty() { // Fall back to central Sponsorblock server let resp = reqwest::get(format!( @@ -98,7 +98,7 @@ pub async fn skip_segments_by_id( return content::RawJson(resp); } - + // Doing a lookup by video ID should return only one Sponsor object with // one list of segments. We need to return just the list of segments. return content::RawJson(serde_json::to_string(&sponsors[0].segments).unwrap()); @@ -113,16 +113,16 @@ async fn find_skip_segments( let cat: Vec = serde_json::from_str(categories.unwrap_or("[\"sponsor\"]")).unwrap(); if cat.is_empty() { - return Vec::new(); + return Vec::new(); } - + let results: Vec = db.run(move |conn| { let base_filter = sponsorTimes .filter(shadowHidden.eq(0)) .filter(hidden.eq(0)) .filter(votes.ge(0)) .filter(category.eq_any(cat)); // We know cat isn't empty at this point - + let queried = match name { VideoName::ByHashPrefix(hash_prefix) => { base_filter @@ -194,7 +194,7 @@ async fn find_skip_segments( for sponsor in sponsors.values_mut() { sponsor.segments.sort_by(|a, b| a.partial_cmp(b).unwrap()); } - + return sponsors.into_values().collect(); }