Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then((channelRecommendations) => {
received = _.size(channelRecommendations)
return Logger.debug(`Got ${received} recommendations from ${_.capitalize(channel.name)}`)
.then(() => Promise.map(channelRecommendations, (channelRecommendation) => {
const { channelRecommendationId } = channelRecommendation
return Recommendation.checkOut(channel, channelRecommendationId, channelRecommendation)
.then(({ recommendation, like, pass }) => likePassOrWait(channel, recommendation, like, pass))
.then((recommendation) => recommendation.save())
.catch(AlreadyCheckedOutEarlierError, ({ recommendation }) => {
skipped++
return recommendation.save()
})
.catch(OutOfLikesError, () => {
skipped++
})
.catch((error) => {
failed++
onNotAuthorizedError () {
return Logger.debug(`${_.capitalize(this._name)} got unauthorized`)
.then(() => {
return Database.channels.update({ accessToken: null }, { where: { name: this._name } })
.then(() => this.authorize())
})
}
.then((channel) => {
if (channel.userId && channel.accessToken) {
return { userId: channel.userId, accessToken: channel.accessToken }
}
const { clientId, redirectUri, optionalParams } = this._options.oauth.facebook
return Logger.debug(`Started Facebook Login for ${_.capitalize(this.name)} channel`)
.then(() => {
return facebookLogin.oauthDialog(clientId, redirectUri, optionalParams)
.finally(() => Logger.debug(`Finished Facebook Login for ${_.capitalize(this.name)} channel`))
})
.then(({ facebookAccessToken, facebookUserId }) => authorize({ facebookAccessToken, facebookUserId }))
.then(({ userId, accessToken }) => {
return Database.channels.update({ userId, accessToken }, { where: { name: this._name } })
.then(() => { return { userId, accessToken } })
})
})
}
onOutOfLikesError () {
return Logger.debug(`${_.capitalize(this.name)} is out of likes`)
.then(() => {
return Database.channels.update({
isOutOfLikes: true,
outOfLikesDate: new Date()
}, { where: { name: this._name } })
.then(() => {
throw new OutOfLikesError()
})
})
}
}
.then((collectionIds) => {
this._rekognitionCollection = this._rekognitionCollection ||
_.find(collectionIds, (collectionId) => _.startsWith(collectionId, 'get-me-a-date-')) ||
`get-me-a-date-${_.now()}-${_.random(9)}`
if (!_.includes(collectionIds, this._rekognitionCollection)) {
return Logger.debug(`Creating AWS Rekognition collection ${this._rekognitionCollection}`)
.then(() => this._rekognition.createCollection(this._rekognitionCollection))
}
})
}
authorizeApp (email, password, url) {
Logger.debug('Started authorizing app in Facebook')
return RandomUserAgent.get()
.then((userAgent) => this._authorizeAppCircuitBreaker.exec(email, password, url, userAgent))
.finally(() => Logger.debug('Finished authorizing app in Facebook'))
}
}
.finally(() => Logger.debug('Finished authorizing app in Facebook'))
}