Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting to allow nsfw images #264

Merged
merged 1 commit into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/defaultconfig.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ enabled = true
prefer_animated = false
banned_images = []
only_download_boilr_images = false
allow_nsfw = false

[steam]
create_collections = false
Expand Down
20 changes: 13 additions & 7 deletions src/steamgriddb/downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ async fn search_for_images_to_download(

for image_ids in image_ids.chunks(99) {
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 {
Ok(images) => {
let images = images
Expand Down Expand Up @@ -261,9 +261,10 @@ async fn get_images_for_ids(
image_ids: &[usize],
image_type: &ImageType,
download_animated: bool,
allow_nsfw: bool,
) -> 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;

Expand All @@ -275,40 +276,45 @@ const BIG_PICTURE_DIMS: [GridDimentions; 2] = [GridDimentions::D920x430, GridDim
pub fn get_query_type(
download_animated: bool,
image_type: &ImageType,
allow_nsfw: bool,
) -> steamgriddb_api::QueryType {
let anymation_type = if download_animated {
Some(&[steamgriddb_api::query_parameters::AnimtionType::Animated][..])
} else {
None
};
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 {
dimentions: Some(&BIG_PICTURE_DIMS),
types: anymation_type,
nsfw: Some(&Nsfw::False),
nsfw: allow_nsfw_enum,
..Default::default()
};
use steamgriddb_api::query_parameters::HeroQueryParameters;
let hero_parameters = HeroQueryParameters {
types: anymation_type,
nsfw: Some(&Nsfw::False),
nsfw: allow_nsfw_enum,
..Default::default()
};
let grid_parameters = GridQueryParameters {
types: anymation_type,
nsfw: Some(&Nsfw::False),
nsfw: allow_nsfw_enum,
..Default::default()
};
use steamgriddb_api::query_parameters::LogoQueryParameters;
let logo_parameters = LogoQueryParameters {
types: anymation_type,
nsfw: Some(&Nsfw::False),
nsfw: allow_nsfw_enum,
..Default::default()
};

use steamgriddb_api::query_parameters::IconQueryParameters;
let icon_parameters = IconQueryParameters {
nsfw: Some(&Nsfw::False),
nsfw: allow_nsfw_enum,
..Default::default()
};
let query_type = match image_type {
Expand Down
1 change: 1 addition & 0 deletions src/steamgriddb/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct SteamGridDbSettings {
pub prefer_animated: bool,
pub banned_images: Vec<String>,
pub only_download_boilr_images: bool,
pub allow_nsfw: bool,
}

impl SteamGridDbSettings {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/ui_image_download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ impl MyEguiApp {
self.rt.spawn_blocking(move || {
let thumbnails_folder = get_thumbnails_folder();
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));
if let Ok(possible_images) = search_res {
let mut result = vec![];
Expand Down
1 change: 1 addition & 0 deletions src/ui/ui_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ impl MyEguiApp {
&mut self.settings.steamgrid_db.only_download_boilr_images,
"Only download images for BoilR shortcuts",
);
ui.checkbox(&mut self.settings.steamgrid_db.allow_nsfw, "Allow NSFW images");
}
ui.add_space(SECTION_SPACING);
}
Expand Down