2.4.1 • Published 10 years ago

immerdu v2.4.1

Weekly downloads
34
License
-
Repository
github
Last release
10 years ago

node immerdu

immerdu for node.

Installation

npm install immerdu

Usage

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 url
  • username: account name
  • accountKey: 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 url
  • username: account name
  • accountKey: 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 url
  • username: account name
  • dbKey: database key pair (only public key required)
  • filename: filename of the image
  • options.overwrite: reimport existing images
  • options.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 url
  • username: account name
  • dbKey: database key pair (both public and secret keys are required)
  • size: thumbnails size can be x256 or 256x256
  • options: CouchDB view query options, except startkey and endkey

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 url
  • username: account name
  • dbKey: database key pair (both public and secret keys are required)
  • ids: photo id or array of photo ids
  • size: image size can be 1920x1080 or original

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

2.4.1

10 years ago

2.4.0

11 years ago

2.3.0

11 years ago

2.2.0

11 years ago

2.1.2

11 years ago

2.1.1

11 years ago

2.1.0

11 years ago

2.0.0

11 years ago

1.1.0

11 years ago

1.0.1

11 years ago

1.0.0

11 years ago