Comparing version 0.0.2 to 0.0.3
@@ -10,2 +10,3 @@ 'use strict'; | ||
var debug = require('debug')('arkivo:controller'); | ||
var trace = require('debug')('arkivo:trace'); | ||
@@ -213,3 +214,3 @@ var B = require('bluebird'); | ||
debug(error.stack); | ||
trace(error.stack); | ||
@@ -294,3 +295,3 @@ return false; | ||
debug(e.stack); | ||
trace(e.stack); | ||
done(e); | ||
@@ -420,3 +421,3 @@ }); | ||
debug('%s: %s', message, error.message); | ||
debug(error.stack); | ||
trace(error.stack); | ||
@@ -423,0 +424,0 @@ throw error; |
@@ -7,2 +7,3 @@ 'use strict'; | ||
var debug = require('debug')('arkivo:plugin'); | ||
var trace = require('debug')('arkivo:trace'); | ||
@@ -126,3 +127,3 @@ var config = require('../config'); | ||
debug('failed to load "%s": %s', plugin, error.message); | ||
debug(error.stack); | ||
trace(error.stack); | ||
} | ||
@@ -129,0 +130,0 @@ } |
@@ -467,3 +467,5 @@ 'use strict'; | ||
this.versions = {}; | ||
this.data = {}; | ||
// Do not reset this.data! | ||
this.touch(); | ||
@@ -470,0 +472,0 @@ |
@@ -8,2 +8,3 @@ 'use strict'; | ||
var debug = require('debug')('arkivo:sync'); | ||
var trace = require('debug')('arkivo:trace'); | ||
@@ -63,2 +64,10 @@ var B = require('bluebird'); | ||
/** | ||
* Cache for downloaded attachments. | ||
* | ||
* @property attachments | ||
* @type Object | ||
*/ | ||
this.attachments = {}; | ||
/** | ||
* The keys of all newly created items. | ||
@@ -195,3 +204,4 @@ * | ||
/** | ||
* Downloads an item's file attachment. | ||
* Downloads an item's file attachment and store | ||
* it in the local attachment cache. | ||
* | ||
@@ -202,5 +212,13 @@ * @method attachment | ||
Session.prototype.attachment = function (item) { | ||
return this.get([ | ||
this.subscription.library, 'items', item.key, 'file', 'view' | ||
].join('/')); | ||
if (this.attachments[item.key]) | ||
return B.resolve(this.attachments[item.key]); | ||
return this | ||
.get([ | ||
this.subscription.library, 'items', item.key, 'file', 'view' | ||
].join('/')) | ||
.tap(function (message) { | ||
this.attachments[item.key] = message; | ||
}.bind(this)); | ||
}; | ||
@@ -333,9 +351,9 @@ | ||
this.version = message.version; | ||
this.version = message.version; | ||
this.versions = message.data; | ||
if (message.multi) { | ||
this.debug('downloading additional versions...'); | ||
while (!message.done) { | ||
this.debug('downloading additional versions...'); | ||
message = yield message.next(); | ||
@@ -412,7 +430,11 @@ | ||
var i, ii, batch, item, key; | ||
var i = 0, batch, item, key; | ||
this.debug('%d items to download', keys.length); | ||
for (i = 0, ii = keys.length; i < ii; ++i) { | ||
// Subtle: the keys array may grow during loop | ||
// execution, because attachment's parent items | ||
// are added on the fly to ensure they will be | ||
// fetched with the next batch! | ||
while (i < keys.length) { | ||
batch = []; | ||
@@ -422,3 +444,3 @@ | ||
// downloaded items if they still have the same version. | ||
for (; i < ii; ++i) { | ||
for (; i < keys.length; ++i) { | ||
key = keys[i]; | ||
@@ -479,3 +501,3 @@ item = this.items[key]; | ||
// parent item's data! | ||
if ((parent = getParent(item))) | ||
if (keys !== undefined && (parent = getParent(item))) { | ||
if (keys.indexOf(parent) === -1) { | ||
@@ -485,2 +507,3 @@ this.debug('requesting additional parent item...'); | ||
} | ||
} | ||
@@ -495,3 +518,3 @@ // Fetch child items since plugin's may need | ||
item.children = | ||
yield this.receive(yield this.children(item), keys); | ||
yield this.receive(yield this.children(item)); | ||
} | ||
@@ -566,3 +589,3 @@ } | ||
sub.update({ | ||
version: session.version, | ||
version: session.version, | ||
versions: session.versions | ||
@@ -624,17 +647,28 @@ }); | ||
function callback(error) { | ||
if (error) return reject(error); | ||
resolve(); | ||
} | ||
function callback(error) { | ||
if (error) return reject(error); | ||
resolve(); | ||
} | ||
var done = plugins | ||
.use(plugin.name, plugin.options || {}) | ||
.process(session, callback); | ||
var done = plugins | ||
.use(plugin.name, plugin.options || {}) | ||
.process(session, callback); | ||
if (done.then) | ||
done.then(resolve, reject); | ||
}); | ||
}); | ||
if (done.then) | ||
done.then(resolve, reject); | ||
}).catch(function (error) { | ||
debug('[%s] plugin %s failed: %s', | ||
session.id, plugin.name, error.message); | ||
trace(error.stack); | ||
// By ignoring the error the subscription will be saved as | ||
// if the sync had succeeded; since plugins don't have a | ||
// rollback mechanism this is probably the best approach. | ||
}); | ||
}, { concurrency: 1 }); | ||
debug('[%s] finished processing plugins', session.id); | ||
@@ -641,0 +675,0 @@ |
{ | ||
"name": "arkivo", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Zotero Archiving Tool", | ||
@@ -5,0 +5,0 @@ "main": "lib/arkivo.js", |
@@ -21,4 +21,6 @@ Arkivo | ||
This will install the `arkivo` executable locally (or globally if | ||
you use the `-g` switch). | ||
This will install the `arkivo` executable locally or globally if | ||
you use the `-g` switch; when installed globally, you can leave out | ||
the `$(npm bin)` in the examples below, as the Arkivo executables | ||
should be in your global path already. | ||
@@ -62,3 +64,3 @@ $ $(npm bin)/arkivo -h | ||
include: `controller`, `db`, `http`, `listener`, `q` `subscription`, and | ||
`sync`. | ||
`sync`. To see stack traces after errors, enable the `arkivo:trace` output. | ||
@@ -95,5 +97,5 @@ By running `arkivo up` you start all Arkivo services, including | ||
"arkivo": { | ||
"plugins": ["arkivo-kindle", "/opt/arkivo/plugins/libnotify.js"] | ||
"plugins": ["arkivo-kindle", "/opt/arkivo/plugins/libnotify"] | ||
} | ||
} | ||
13210875
3323
99