diff --git a/README.md b/README.md index d203a7d..599b9ee 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,9 @@ timeout = 60000 ; Ignore the following databases (again comma separated list) ; Regular expressions are again allowed: blacklist = /^_/ +; Only attachments which match any of the mime types below are processed (separate with comma). +; Default is /^image\// Regular expressions are allowed: +;source_content_types = /^image\//,application/postscript ``` ## Imagemagick Configuration diff --git a/lib/couchmagick-stream.js b/lib/couchmagick-stream.js index b7858aa..3b35b62 100644 --- a/lib/couchmagick-stream.js +++ b/lib/couchmagick-stream.js @@ -11,6 +11,18 @@ var nano = require('nano'); var strformat = require('strformat'); var docuri = require('docuri'); +function compileRegexp(string) { + if (string instanceof RegExp) { + return string; + } + if (string.match(/^\/.*\/$/)) { + string = string.slice(1, string.length - 1); + } else { + string = '^' + string + '$'; + } + return new RegExp(string); +} + // TODO: emit all documents, also filtered one, to enable checkpointing module.exports = function couchmagick(url, options) { @@ -18,6 +30,15 @@ module.exports = function couchmagick(url, options) { options.concurrency = options.concurrency || 1; options.timeout = options.timeout || 60 * 1000; // 1 minute + options.source_content_types = options.source_content_types ? + options.source_content_types.split(/,\s*/) : [/^image\//]; + if (options.source_content_types) { + if (!Array.isArray(options.source_content_types)) { + options.source_content_types = [options.source_content_types]; + } + options.source_content_types = options.source_content_types.map(compileRegexp); + } + var couch = nano(url); var configs = {}; @@ -224,7 +245,10 @@ module.exports = function couchmagick(url, options) { return false; } - return data.doc._attachments[data.name].content_type.match(/^image\//); + var content_type = data.doc._attachments[data.name].content_type; + return options.source_content_types.some(function(r) { + return content_type.match(r); + }); }), // split stream into versions