Add setting to allow nsfw images (#264)

This commit is contained in:
Keelhauled
2022-10-24 18:11:10 +02:00
committed by GitHub
parent 889b25d441
commit 279cf943eb
5 changed files with 17 additions and 8 deletions
+1
View File
@@ -7,6 +7,7 @@ enabled = true
prefer_animated = false prefer_animated = false
banned_images = [] banned_images = []
only_download_boilr_images = false only_download_boilr_images = false
allow_nsfw = false
[steam] [steam]
create_collections = false create_collections = false
+13 -7
View File
@@ -204,7 +204,7 @@ async fn search_for_images_to_download(
for image_ids in image_ids.chunks(99) { for image_ids in image_ids.chunks(99) {
let image_search_result = let image_search_result =
get_images_for_ids(client, image_ids, &image_type, download_animated).await; get_images_for_ids(client, image_ids, &image_type, download_animated, settings.steamgrid_db.allow_nsfw).await;
match image_search_result { match image_search_result {
Ok(images) => { Ok(images) => {
let images = images let images = images
@@ -261,9 +261,10 @@ async fn get_images_for_ids(
image_ids: &[usize], image_ids: &[usize],
image_type: &ImageType, image_type: &ImageType,
download_animated: bool, download_animated: bool,
allow_nsfw: bool,
) -> Result<Vec<steamgriddb_api::response::SteamGridDbResult<steamgriddb_api::images::Image>>, String> ) -> Result<Vec<steamgriddb_api::response::SteamGridDbResult<steamgriddb_api::images::Image>>, String>
{ {
let query_type = get_query_type(download_animated, image_type); let query_type = get_query_type(download_animated, image_type, allow_nsfw);
let image_search_result = client.get_images_for_ids(image_ids, &query_type).await; let image_search_result = client.get_images_for_ids(image_ids, &query_type).await;
@@ -275,6 +276,7 @@ const BIG_PICTURE_DIMS: [GridDimentions; 2] = [GridDimentions::D920x430, GridDim
pub fn get_query_type( pub fn get_query_type(
download_animated: bool, download_animated: bool,
image_type: &ImageType, image_type: &ImageType,
allow_nsfw: bool,
) -> steamgriddb_api::QueryType { ) -> steamgriddb_api::QueryType {
let anymation_type = if download_animated { let anymation_type = if download_animated {
Some(&[steamgriddb_api::query_parameters::AnimtionType::Animated][..]) Some(&[steamgriddb_api::query_parameters::AnimtionType::Animated][..])
@@ -282,33 +284,37 @@ pub fn get_query_type(
None None
}; };
use steamgriddb_api::query_parameters::GridQueryParameters; use steamgriddb_api::query_parameters::GridQueryParameters;
let allow_nsfw_enum = match allow_nsfw {
true => Some(&Nsfw::Any),
false => Some(&Nsfw::False),
};
let big_picture_parameters = GridQueryParameters { let big_picture_parameters = GridQueryParameters {
dimentions: Some(&BIG_PICTURE_DIMS), dimentions: Some(&BIG_PICTURE_DIMS),
types: anymation_type, types: anymation_type,
nsfw: Some(&Nsfw::False), nsfw: allow_nsfw_enum,
..Default::default() ..Default::default()
}; };
use steamgriddb_api::query_parameters::HeroQueryParameters; use steamgriddb_api::query_parameters::HeroQueryParameters;
let hero_parameters = HeroQueryParameters { let hero_parameters = HeroQueryParameters {
types: anymation_type, types: anymation_type,
nsfw: Some(&Nsfw::False), nsfw: allow_nsfw_enum,
..Default::default() ..Default::default()
}; };
let grid_parameters = GridQueryParameters { let grid_parameters = GridQueryParameters {
types: anymation_type, types: anymation_type,
nsfw: Some(&Nsfw::False), nsfw: allow_nsfw_enum,
..Default::default() ..Default::default()
}; };
use steamgriddb_api::query_parameters::LogoQueryParameters; use steamgriddb_api::query_parameters::LogoQueryParameters;
let logo_parameters = LogoQueryParameters { let logo_parameters = LogoQueryParameters {
types: anymation_type, types: anymation_type,
nsfw: Some(&Nsfw::False), nsfw: allow_nsfw_enum,
..Default::default() ..Default::default()
}; };
use steamgriddb_api::query_parameters::IconQueryParameters; use steamgriddb_api::query_parameters::IconQueryParameters;
let icon_parameters = IconQueryParameters { let icon_parameters = IconQueryParameters {
nsfw: Some(&Nsfw::False), nsfw: allow_nsfw_enum,
..Default::default() ..Default::default()
}; };
let query_type = match image_type { let query_type = match image_type {
+1
View File
@@ -9,6 +9,7 @@ pub struct SteamGridDbSettings {
pub prefer_animated: bool, pub prefer_animated: bool,
pub banned_images: Vec<String>, pub banned_images: Vec<String>,
pub only_download_boilr_images: bool, pub only_download_boilr_images: bool,
pub allow_nsfw: bool,
} }
impl SteamGridDbSettings { impl SteamGridDbSettings {
+1 -1
View File
@@ -619,7 +619,7 @@ impl MyEguiApp {
self.rt.spawn_blocking(move || { self.rt.spawn_blocking(move || {
let thumbnails_folder = get_thumbnails_folder(); let thumbnails_folder = get_thumbnails_folder();
let client = steamgriddb_api::Client::new(auth_key); let client = steamgriddb_api::Client::new(auth_key);
let query = get_query_type(false, &image_type); let query = get_query_type(false, &image_type, settings.steamgrid_db.allow_nsfw);
let search_res = block_on(client.get_images_for_id(grid_id, &query)); let search_res = block_on(client.get_images_for_id(grid_id, &query));
if let Ok(possible_images) = search_res { if let Ok(possible_images) = search_res {
let mut result = vec![]; let mut result = vec![];
+1
View File
@@ -117,6 +117,7 @@ impl MyEguiApp {
&mut self.settings.steamgrid_db.only_download_boilr_images, &mut self.settings.steamgrid_db.only_download_boilr_images,
"Only download images for BoilR shortcuts", "Only download images for BoilR shortcuts",
); );
ui.checkbox(&mut self.settings.steamgrid_db.allow_nsfw, "Allow NSFW images");
} }
ui.add_space(SECTION_SPACING); ui.add_space(SECTION_SPACING);
} }