|
|
|
@ -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
|
|
|
|
|