From b71414f431c5f06e80ab7ca40f780fe60287e86d Mon Sep 17 00:00:00 2001 From: Felix Schauerte Date: Sun, 17 Apr 2016 13:00:33 +0200 Subject: [PATCH] added support for source_content_type in os_daemon config --- README.md | 3 +++ lib/couchmagick-stream.js | 26 +++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) 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