2.4.1 • Published 11 years ago
immerdu v2.4.1
node immerdu
immerdu for node.
Installation
npm install immerduUsage
var nacl = require('tweetnacl')
var immerdu = require('immerdu')
var server = 'http://localhost:5984'
var username = 'my-account'
var filename = '/path/to/an/image.jpg'
api.signup(server, username, function(err, response) {
api.signin(server, username, response.accountKey, function(err, dbkey) {
api.upload(server, username, dbkey, filename, function(err) {
api.thumbs(server, username, dbkey, 'x256', function(err, response) {
// response is a couchdb view response
// with decrypted thumbnails
})
})
})
})API
Sign Up
signup(server, username, accountKey, callback)Create permit. If the database does not exist, it gets created. If no
accountKey is given, a new key gets created.
server: couchdb server urlusername: account nameaccountKey: account key pair (optional. if given, only public key required)
callback(err, response) is called with permit id, dbKey and accountKey on success:
{
ok: true,
id: '3d132659-0b26-4f50-92c5-de4c63ffa3c5',
accountKey: {
publicKey: ..., // Uint8Array with 32-byte public key
secretKey: ... // Uint8Array with 32-byte secret key
},
dbKey: {
publicKey: ..., // Uint8Array with 32-byte public key
secretKey: ... // Uint8Array with 32-byte secret key
}
}Sign In
signin(server, username, accountKey, callback)Open immerdu database.
server: couchdb server urlusername: account nameaccountKey: account key pair (only secret key required)
callback(err, response) is called with the database key pair on success:
{
publicKey: ..., // Uint8Array with 32-byte public key
secretKey: ... // Uint8Array with 32-byte secret key
}Upload
upload(server, username, dbKey, filename, options, callback)Import an image.
server: couchdb server urlusername: account namedbKey: database key pair (only public key required)filename: filename of the imageoptions.overwrite: reimport existing imagesoptions.exclude: array of versions which should not be imported
callback(err, response) is called with the photo id on success:
{
ok: true,
id: 'de59be4c5a2e0ec09246b7210dfd6d5634421188'
}Thumbs
thumbs(url, username, dbKey, size, options, callback)Retrieve an index with thumbnails.
server: couchdb server urlusername: account namedbKey: database key pair (both public and secret keys are required)size: thumbnails size can bex256or256x256options: CouchDB view query options, exceptstartkeyandendkey
callback(err, response) is called with the thumbnails view response on
success:
{
total_rows: 2,
offset: 1,
rows: [
{
id: 'photo/de59be4c5a2e0ec09246b7210dfd6d5634421188',
key: [
kz8O8lMMAs1nQYIgckje4FLMDVqJaePyUnsG2v9OT3M=',
x256',
2014:11:12 13:04:00'
],
value: {
photoKey: 'aEOUhJwLn4OTMdzGa3bbK5L6BqI2w21vYIt4KuiayzM=',
image: {
format: 'jpeg',
width: 384,
height: 256,
buffer: ... // Buffer with image data
}
}
}
]
}Images
images(server, username, dbKey, ids, size, callback)Retrieve photos.
server: couchdb server urlusername: account namedbKey: database key pair (both public and secret keys are required)ids: photo id or array of photo idssize: image size can be1920x1080ororiginal
callback(err, response) is called with the images view response on success:
{
total_rows: 1,
offset: 0,
rows: [
{
id: 'photo/de59be4c5a2e0ec09246b7210dfd6d5634421188',
key: [
Xz65xL8uqkKx26ea8l/ff0Pb1DMOb7WJoj9qC/WAMEw=',
de59be4c5a2e0ec09246b7210dfd6d5634421188'
],
value: {
photoKey: 'FRZRp7SpK84KSe9DhjEq2ZaOE+FoBz3rcZ7KB3Iruig=',
image: {
format: 'jpeg',
width: 600,
height: 400,
buffer: ... // Buffer with image data
}
}
}
]
}Tests
Run the testsuite with npm test or a single test with node
test/lib/test-signin.js
(c) 2014 Johannes J. Schmidt