mirror of https://github.com/jo/couchmagick.git
Initial commit
commit
30c1b47d40
@ -0,0 +1 @@
|
|||||||
|
node_modules/
|
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"curly": true,
|
||||||
|
"eqeqeq": true,
|
||||||
|
"immed": true,
|
||||||
|
"latedef": true,
|
||||||
|
"newcap": true,
|
||||||
|
"noarg": true,
|
||||||
|
"sub": true,
|
||||||
|
"undef": true,
|
||||||
|
"unused": true,
|
||||||
|
"boss": true,
|
||||||
|
"eqnull": true,
|
||||||
|
"node": true
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
couchmagick
|
||||||
|
===========
|
||||||
|
Run ImageMagicks `convert` on CouchDB documents.
|
||||||
|
|
||||||
|
Installation
|
||||||
|
------------
|
||||||
|
via npm:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install couchmagick -g
|
||||||
|
```
|
||||||
|
|
||||||
|
Configuration
|
||||||
|
-------------
|
||||||
|
Add couchmagick to the `os_daemons`:
|
||||||
|
```ini
|
||||||
|
[os_daemons]
|
||||||
|
couchmagick = couchmagick
|
||||||
|
```
|
||||||
|
|
||||||
|
Now CouchDB takes care of the couchmagick process.
|
||||||
|
|
||||||
|
```ini
|
||||||
|
[couchmagick]
|
||||||
|
user = mein-user
|
||||||
|
password = secure
|
||||||
|
dbs = photos, _users
|
||||||
|
filter = 'myapp/myfilter'
|
||||||
|
```
|
||||||
|
|
||||||
|
Contributing
|
||||||
|
------------
|
||||||
|
Lint your code via `npm run jshint`.
|
||||||
|
|
||||||
|
License
|
||||||
|
-------
|
||||||
|
Copyright (c) 2012-2013 Johannes J. Schmidt, null2 GmbH
|
||||||
|
|
||||||
|
Licensed under the MIT license.
|
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
require('..')();
|
@ -0,0 +1,159 @@
|
|||||||
|
/* couchmagick
|
||||||
|
* (c) 2013 Johannes J. Schmidt, null2 GmbH, Berlin
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var pkg = require('./package.json');
|
||||||
|
var couchdbWorker = require('couchdb-worker');
|
||||||
|
var url = require('url');
|
||||||
|
|
||||||
|
// logging
|
||||||
|
function info(msg) {
|
||||||
|
process.stdout.write(JSON.stringify(["log", msg]) + '\n');
|
||||||
|
}
|
||||||
|
function error(msg) {
|
||||||
|
process.stdout.write(JSON.stringify(["log", msg, {"level": "error"}]) + '\n');
|
||||||
|
}
|
||||||
|
function debug(msg) {
|
||||||
|
process.stdout.write(JSON.stringify(["log", msg, {"level": "debug"}]) + '\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
// configuration
|
||||||
|
// [httpd]
|
||||||
|
// {"bind_address": "127.0.0.1", "port": "5984"}
|
||||||
|
// [couchmagick]
|
||||||
|
// {"dbs": "myfotos"}
|
||||||
|
var config = {};
|
||||||
|
function parseConfig(data) {
|
||||||
|
debug('parsing config: ' + data);
|
||||||
|
|
||||||
|
try {
|
||||||
|
data = JSON.parse(data);
|
||||||
|
} catch(e) {
|
||||||
|
error('Error parsing config: ' + e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// [httpd]
|
||||||
|
if (data.port) {
|
||||||
|
config.port = data.port;
|
||||||
|
}
|
||||||
|
if (data.bind_address) {
|
||||||
|
config.bind_address = data.bind_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
// [couchmagick]
|
||||||
|
if (data.dbs) {
|
||||||
|
config.dbs = data.dbs.split(/,\s+/);
|
||||||
|
}
|
||||||
|
if (data.user) {
|
||||||
|
config.user = data.user;
|
||||||
|
}
|
||||||
|
if (data.password) {
|
||||||
|
config.password = data.password;
|
||||||
|
}
|
||||||
|
if (data.filter) {
|
||||||
|
config.filter = data.filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
// process function
|
||||||
|
function convert(doc, db, next) {
|
||||||
|
info('processing doc ' + doc._id + '...');
|
||||||
|
next(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// run workers
|
||||||
|
function run(config) {
|
||||||
|
if (!config.bind_address) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!config.dbs) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
info('using config: ' + JSON.stringify(config));
|
||||||
|
|
||||||
|
var server = url.format({
|
||||||
|
protocol: 'http',
|
||||||
|
hostname: config.bind_address,
|
||||||
|
port: config.port
|
||||||
|
});
|
||||||
|
debug('using server: ' + server);
|
||||||
|
|
||||||
|
var auth;
|
||||||
|
if (config.user && config.password) {
|
||||||
|
auth = {
|
||||||
|
user: config.user,
|
||||||
|
password: config.password
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var followOptions = {};
|
||||||
|
if (config.filter) {
|
||||||
|
followOptions.filter = config.filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
config.dbs.forEach(function(db) {
|
||||||
|
debug('starting worker for ' + db);
|
||||||
|
|
||||||
|
var options = {
|
||||||
|
id: pkg.name,
|
||||||
|
db: {
|
||||||
|
url: url.resolve(server, db),
|
||||||
|
auth: auth
|
||||||
|
},
|
||||||
|
follow: followOptions,
|
||||||
|
process: convert
|
||||||
|
};
|
||||||
|
|
||||||
|
debug('using worker options: ' + JSON.stringify(options));
|
||||||
|
|
||||||
|
try {
|
||||||
|
var worker = couchdbWorker(options);
|
||||||
|
|
||||||
|
worker.on('error', function(err) {
|
||||||
|
error('Serious error: ' + err);
|
||||||
|
});
|
||||||
|
|
||||||
|
worker.on('worker:complete', function(doc) {
|
||||||
|
debug('Completed: ' + doc._id);
|
||||||
|
});
|
||||||
|
|
||||||
|
worker.on('worker:error', function(err, doc) {
|
||||||
|
info('Error processing ' + doc._id + ' :' + err);
|
||||||
|
});
|
||||||
|
|
||||||
|
worker.start();
|
||||||
|
} catch(e) {
|
||||||
|
error('Error starting worker: ' + e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = function() {
|
||||||
|
process.stdin.on('data', function(data) {
|
||||||
|
if (typeof data !== 'string') {
|
||||||
|
data = data.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
data.replace(/\s+$/, '').split(/\n+/).forEach(parseConfig);
|
||||||
|
|
||||||
|
run(config);
|
||||||
|
});
|
||||||
|
|
||||||
|
process.stdin.on('end', function () {
|
||||||
|
process.exit(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
// restart on config change
|
||||||
|
process.stdout.write(JSON.stringify(["register", "httpd"]) + '\n');
|
||||||
|
process.stdout.write(JSON.stringify(["register", pkg.name]) + '\n');
|
||||||
|
|
||||||
|
// get config
|
||||||
|
process.stdout.write(JSON.stringify(["get", "httpd"]) + '\n');
|
||||||
|
process.stdout.write(JSON.stringify(["get", pkg.name]) + '\n');
|
||||||
|
};
|
@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"name": "couchmagick",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "Run ImageMagicks `convert` on CouchDB documents.",
|
||||||
|
"main": "index.js",
|
||||||
|
"preferGlobal": true,
|
||||||
|
"bin": "bin/couchmagick",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/null2/couchmagick"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"jshint": "jshint -c .jshintrc index.js"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"couchdb",
|
||||||
|
"worker",
|
||||||
|
"convert",
|
||||||
|
"imagemagick",
|
||||||
|
"image-processing",
|
||||||
|
"os_daemon"
|
||||||
|
],
|
||||||
|
"author": "Johannes J. Schmidt",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/null2/couchmagick/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/null2/couchmagick",
|
||||||
|
"dependencies": {
|
||||||
|
"couchdb-worker": "~3.1.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"jshint": "~2.3.0"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue