cher-tools
Advanced tools
Comparing version 0.5.6 to 0.5.7
{ | ||
"name": "cher-tools", | ||
"version": "0.5.6", | ||
"version": "0.5.7", | ||
"description": "Tools and utilities for the Cher platform", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
'use strict'; | ||
const es = require( 'event-stream' ); | ||
const utils = require( '../utils' ); | ||
const log = require( '../log' )(); | ||
const es = require('event-stream'); | ||
const utils = require('../utils'); | ||
const log = require('../log')(); | ||
module.exports = ( deps ) => { | ||
const DataModel = deps.models.get( 'DataModel' ); | ||
if ( !DataModel ) { | ||
module.exports = (deps) => { | ||
const SocialContent = deps.models.get('SocialContent'); | ||
if (!SocialContent) { | ||
log.error( | ||
'Missing a required dependency for persist stream: DataModel' | ||
); | ||
// return a stream even if the DataModel dependency does not exist so that | ||
'Missing a required dependency for persist stream: SocialContent' | ||
); | ||
// return a stream even if the SocialContent dependency does not exist so that | ||
// we don't break the pipeline. | ||
@@ -19,18 +19,18 @@ return es.through(); | ||
return es.through( function pipelineSaveStream ( data ) { | ||
return es.through(function pipelineSaveStream (data) { | ||
const self = this; | ||
let parsed = utils.parse( data, true ); | ||
let parsed = utils.parse(data, true); | ||
let dup = false; | ||
// We query the database for this particular item. If it's already in the | ||
// database, we ignore it. Otherwise, we store it then emit it as new data | ||
DataModel | ||
.fetchUnique( parsed.source_id ) | ||
.then( function onDataModelFetch ( model ) { | ||
SocialContent | ||
.fetchUnique(parsed.source_id) | ||
.then(function onSocialContentFetch (model) { | ||
let toSave; | ||
if ( !model ) { | ||
toSave = new DataModel( parsed ); | ||
if (!model) { | ||
toSave = new SocialContent(parsed); | ||
} else { | ||
log.debug( | ||
'Found duplicate entry for %s Overwriting blob.', parsed.source_id | ||
); | ||
`Found duplicate entry for %s Overwriting blob ${parsed.source_id}` | ||
); | ||
dup = true; | ||
@@ -41,19 +41,16 @@ toSave = model; | ||
return toSave.save(); | ||
}).then( ( model ) => { | ||
if ( parsed.flagged && !dup ) { | ||
model.moderate( false ) | ||
.catch( ( err ) => { | ||
log.error( | ||
'An error occured while moderating flagged item %s', | ||
parsed.social_id | ||
); | ||
log.error( err ); | ||
self.emit( 'error', err ); | ||
}).then((model) => { | ||
if (parsed.flagged && !dup) { | ||
model.moderate(false) | ||
.catch((err) => { | ||
const message = `An error occured while moderating flagged item ${parsed.source_id}`; | ||
log.error({ err: err }); | ||
self.emit('error', err); | ||
}); | ||
} | ||
if ( !dup ) { | ||
self.emit( 'data', data ); | ||
if (!dup) { | ||
self.emit('data', data); | ||
} | ||
}).catch( ( e ) => { | ||
self.emit( 'error', e ); | ||
}).catch((e) => { | ||
self.emit('error', e); | ||
}); | ||
@@ -60,0 +57,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20417
629