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 blacklist feature #98

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions MMM-Wallpaper.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Module.register("MMM-Wallpaper", {
flickrDataCacheTime: 24 * 60 * 60 * 1000,
flickrResultsPerPage: 500, // Flickr API is limited to 500 photos per page
fadeEdges: false,
recurseLocalDirectories: false,
blacklist: []
},

getStyles: function() {
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ local:
|Option|Default|Description|
|---|---|---|
|`"recurseLocalDirectories"`|`false`|Whether to recurse into subdirectories when looking for images.|
|`"blacklist"`| `[]`| An array of strings. Any path containing an element of this array as a substring will not be considered.|

## Notifications

Expand Down
11 changes: 11 additions & 0 deletions node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ module.exports = NodeHelper.create({
const sourcePath = config.source.substring(6).trim();
const urlPath = `/${self.name}/images/${result.key}/`;
const fileMatcher = /\.(?:a?png|avif|gif|p?jpe?g|jfif|pjp|svg|webp|bmp)$/;
const blacklist = config.blacklist;

if (!(result.key in self.handlers)) {
var handler = express.static(sourcePath);
Expand All @@ -196,8 +197,18 @@ module.exports = NodeHelper.create({
const dirents = await fs.promises.readdir(dir, { withFileTypes: true });
let result = [];

outer:
for (const dirent of dirents) {
const entpath = path.resolve(dir, dirent.name);

if (blacklist) {
for (const entry of blacklist) {
if (entpath.includes(entry)) {
continue outer
}
}
}

if (dirent.isDirectory() && config.recurseLocalDirectories) {
result = result.concat(await getFiles(entpath, `${prefix}${dirent.name}/`));
} else if (dirent.isFile() && dirent.name.toLowerCase().match(fileMatcher) != null) {
Expand Down