From 0cadac6dca48c6ff6856d2d7e5cb3915d5022300 Mon Sep 17 00:00:00 2001 From: Aiko Mastboom Date: Sat, 27 Apr 2013 10:21:45 +0200 Subject: [PATCH] code cleanup --- importer.js | 10 +++++++--- mongodata.js | 2 +- routes.js | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/importer.js b/importer.js index eef8ff2..7e39ab9 100644 --- a/importer.js +++ b/importer.js @@ -5,7 +5,7 @@ var path = require('path'); var fs = require('fs'); -module.exports = function (config, mongoInstance, shareModel) { +module.exports = function (config, mongoInstance) { var import_leftovers_tag = 'import_leftovers__([A-Za-z0-9]+)_([A-Za-z0-9]+)_([A-Za-z0-9]+)'; var import_leftovers_regexp = new RegExp(helpers.marker_prefix + import_leftovers_tag + helpers.marker_postfix); @@ -164,11 +164,15 @@ module.exports = function (config, mongoInstance, shareModel) { delete data._id; } _.extend(parent_result, data); - return mongoInstance.setMongoContent(parent_result, context, function (err, result) { + return mongoInstance.setMongoContent(parent_result, context, function (err) { + if (err) { + config.errors && console.log('ERR importer.importRemainder setMongoContent', err); + return callback(err); + } var documentId = 'json:' + context.collection + ':' + context.name; var keys = _.keys(parent_result); // reset all attributes; return mongoInstance.updateShareDocument(documentId, parent_result, keys, function () { - return replaceWithEmptyContent(err); + return replaceWithEmptyContent(null); }); }); } else { diff --git a/mongodata.js b/mongodata.js index e1a65fb..4ceab24 100644 --- a/mongodata.js +++ b/mongodata.js @@ -292,7 +292,7 @@ module.exports = function (db, shareModel, config) { }); return shareModel.applyOp(documentId, { op: ops, v: doc.v }, function (err, result) { if (err) { - config.errors && console.log('ERR setMongoAttribute createShareDocument shareModel.applyOp', documentId, err); + config.errors && console.log('WARN setMongoAttribute createShareDocument shareModel.applyOp', documentId, err); return callback && callback(); } config.debug && console.log('createShareDocument shareModel.applyOp', documentId, ops, err, result); diff --git a/routes.js b/routes.js index e88ffc3..4a65301 100644 --- a/routes.js +++ b/routes.js @@ -291,6 +291,7 @@ module.exports = function (app, db, config) { var attribute_parts = options.query.name.split('.'); var markdownTag = 'markdown__' + options.collection + '_' + attribute_parts[0] + '_' + attribute_parts[1]; //var markdownDocument=helpers.marker_prefix + markdownTag + helpers.marker_postfix; + // TODO: remove hardcoded marker var markdownDocument = ''; return previewInstance.getPreviewHTML(markdownDocument, { req: options.req }, responder(options, res, next) @@ -328,7 +329,7 @@ module.exports = function (app, db, config) { } ); - var importerInstance = importer(config, mongoDataInstance, model); + var importerInstance = importer(config, mongoDataInstance); route = config.api.importer + '/:filename'; app.get(route, function importFile(req, res, next) {