Skip to content

Commit

Permalink
feat(ignore): implement suggestions from #112
Browse files Browse the repository at this point in the history
  • Loading branch information
RouHim committed Nov 30, 2023
1 parent 35a5910 commit 871b7f2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 36 deletions.
48 changes: 25 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,27 @@ services:

All configuration is done via environment variables:

| Name | Description | Default value | Can be overwritten in URL |
|--------------------------|-------------------------------------------------------------------------------------------------------|-------------------------------|---------------------------|
| RESOURCE_PATHS | A list of folders from which the images should be loaded (comma separated). | `/resources` (Container only) | |
| DATA_FOLDER | Path to a folder where the data should be stored, needs to read/write access | `/data` (Container only) | |
| PORT | Port on which the application should listen. | `8080` | |
| SLIDESHOW_INTERVAL | Interval of the slideshow in seconds | 30 | x |
| REFRESH_INTERVAL | Interval how often the page should be reloaded in minutes | 60 | |
| DATE_FORMAT | Date format of the image taken date (https://docs.rs/chrono/0.4.19/chrono/format/strftime/index.html) | %d.%m.%Y | |
| BIGDATA_CLOUD_API_KEY | To resolve geo coordinates to city name. Obtain here: https://www.bigdatacloud.com | | |
| OPEN_WEATHER_MAP_API_KEY | To receive weather live data. Obtain here: https://openweathermap.org/api | | |
| WEATHER_ENABLED | Indicates if weather should be shown in the slideshow | false | x |
| WEATHER_LOCATION | Name of a city | Berlin | |
| WEATHER_LANGUAGE | Weather language ([ISO_639-1 two digit code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)) | en | |
| WEATHER_UNIT | Weather units (`metric` or `imperial`) | metric | |
| HOME_ASSISTANT_BASE_URL | Home assistant base url (e.g.: `http://192.168.0.123:8123`) | | |
| HOME_ASSISTANT_ENTITY_ID | Home assistant entity id to load the weather from (e.g.: `sensor.outside_temperature`) | | |
| HOME_ASSISTANT_API_TOKEN | Home assistant api access token | | |
| SHOW_HIDE_BUTTON | Show the hide button on the slideshow | false | x |
| RANDOM_SLIDESHOW | Show only random images instead of images from this week in previous years | false | x |
| IGNORED_FOLDERS | A list of folder names which should be ignored (comma separated). | | |
| Name | Description | Default value | Can be overwritten in URL |
|----------------------------|-------------------------------------------------------------------------------------------------------------|-------------------------------|---------------------------|
| RESOURCE_PATHS | A list of folders from which the images should be loaded (comma separated). | `/resources` (Container only) | |
| DATA_FOLDER | Path to a folder where the data should be stored, needs to read/write access | `/data` (Container only) | |
| PORT | Port on which the application should listen. | `8080` | |
| SLIDESHOW_INTERVAL | Interval of the slideshow in seconds | 30 | x |
| REFRESH_INTERVAL | Interval how often the page should be reloaded in minutes | 60 | |
| DATE_FORMAT | Date format of the image taken date (https://docs.rs/chrono/0.4.19/chrono/format/strftime/index.html) | %d.%m.%Y | |
| BIGDATA_CLOUD_API_KEY | To resolve geo coordinates to city name. Obtain here: https://www.bigdatacloud.com | | |
| OPEN_WEATHER_MAP_API_KEY | To receive weather live data. Obtain here: https://openweathermap.org/api | | |
| WEATHER_ENABLED | Indicates if weather should be shown in the slideshow | false | x |
| WEATHER_LOCATION | Name of a city | Berlin | |
| WEATHER_LANGUAGE | Weather language ([ISO_639-1 two digit code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)) | en | |
| WEATHER_UNIT | Weather units (`metric` or `imperial`) | metric | |
| HOME_ASSISTANT_BASE_URL | Home assistant base url (e.g.: `http://192.168.0.123:8123`) | | |
| HOME_ASSISTANT_ENTITY_ID | Home assistant entity id to load the weather from (e.g.: `sensor.outside_temperature`) | | |
| HOME_ASSISTANT_API_TOKEN | Home assistant api access token | | |
| SHOW_HIDE_BUTTON | Show the hide button on the slideshow | false | x |
| RANDOM_SLIDESHOW | Show only random images instead of images from this week in previous years | false | x |
| IGNORE_FOLDER_MARKER_FILES | A list of file names which causes the folder in which the file is located to be ignored. (comma separated). | `.ignore` | |
| IGNORE_FOLDER_REGEX | A regular expression that causes the folder to be ignored if it matches. | | |

> Some parameters, as marked in the table, can be overwritten as URL parameter
> e.g.: http://localhost:8080/?SLIDESHOW_INTERVAL=10&SHOW_HIDE_BUTTON=false
Expand All @@ -127,9 +128,10 @@ All configuration is done via environment variables:

There are two ways to ignore folders:

1) Set the environment variable `IGNORED_FOLDERS` to a comma separated list of folder names which should be ignored.
Example: `IGNORED_FOLDERS=thumbnails,$RECYLE.BIN``
2) Create a file named `.ignore` in the folder which should be ignored. The file should be empty.
1) By file name: If a folder contains a file with the name specified in `IGNORE_FOLDER_MARKER_FILES`, the folder is
ignored.
2) By folder name: If a folder name matches the regular expression specified in `IGNORE_FOLDER_REGEX`, the folder is
ignored.

## Limitations

Expand Down
40 changes: 27 additions & 13 deletions src/filesystem_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::path::{Path, PathBuf};
use image::ImageFormat;
use lazy_static::lazy_static;
use log::{error, info, warn};
use regex::Regex;

use crate::resource_reader::ImageResource;
use crate::{resource_reader, utils};
Expand Down Expand Up @@ -68,22 +69,32 @@ pub fn read_files_recursive(path: &Path) -> Vec<ImageResource> {
.collect()
}

/// Checks if the folder should be skipped, because it is ignored or contains a .ignore file
/// Checks if the folder should be skipped, because it is ignored or contains certain .ignore file
/// Returns true if the folder should be skipped
/// Returns false if the folder should be processed
fn should_skip_folder(path: &Path) -> bool {
lazy_static! {
static ref IGNORED_FOLDERS: Vec<String> = std::env::var("IGNORED_FOLDERS")
.unwrap_or("".to_string())
.as_str()
.split(',')
.map(|s| s.to_string())
.collect();
};
static ref IGNORE_FOLDER_REGEX: Option<Regex> = std::env::var("IGNORE_FOLDER_REGEX")
.ok()
.map(|ignore_folders| Regex::new(&ignore_folders).unwrap());
static ref IGNORE_FOLDER_MARKER_FILES: Vec<String> =
std::env::var("IGNORE_FOLDER_MARKER_FILES")
.unwrap_or(".ignore".to_string())
.as_str()
.split(',')
.map(|s| s.to_string())
.collect();
}

let folder_name = path.file_name().unwrap().to_str().unwrap();
if IGNORED_FOLDERS.contains(&folder_name.to_string()) {
info!("Skipping folder: {:?} because it is ignored", path);
if IGNORE_FOLDER_REGEX.is_some()
&& IGNORE_FOLDER_REGEX.as_ref().unwrap().is_match(folder_name)
{
info!(
"⏭️ Skipping folder: {:?} because it is ignored by regular expression {:?}",
path,
std::env::var("IGNORE_FOLDER_REGEX").unwrap()
);
return true;
}

Expand All @@ -104,12 +115,15 @@ fn should_skip_folder(path: &Path) -> bool {
error
)
});
metadata.is_file() && entry.file_name().to_str().unwrap() == ".ignore"
metadata.is_file()
&& IGNORE_FOLDER_MARKER_FILES
.contains(&entry.file_name().to_str().unwrap().to_string())
});
if contains_ignore_file {
info!(
"Skipping folder: {:?} because it contains a .ignore file",
path
"⏭️ Skipping folder: {:?} because it contains any of these files {:?}",
path,
std::env::var("IGNORE_FOLDER_REGEX")
);
return true;
}
Expand Down

0 comments on commit 871b7f2

Please sign in to comment.