|
@ -8,7 +8,7 @@ const mongoose = require('mongoose'); |
|
|
const Feed = mongoose.model('Feed'); |
|
|
const Feed = mongoose.model('Feed'); |
|
|
const FeedEntry = mongoose.model('FeedEntry'); |
|
|
const FeedEntry = mongoose.model('FeedEntry'); |
|
|
|
|
|
|
|
|
const { SiteService, SiteError } = require('../../lib/site-lib'); |
|
|
const { SiteService, SiteError, SiteAsync } = require('../../lib/site-lib'); |
|
|
const { read: feedReader } = require('feed-reader'); |
|
|
const { read: feedReader } = require('feed-reader'); |
|
|
|
|
|
|
|
|
class FeedService extends SiteService { |
|
|
class FeedService extends SiteService { |
|
@ -23,6 +23,10 @@ class FeedService extends SiteService { |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async start ( ) { |
|
|
|
|
|
this.jobQueue = this.getJobQueue('newsroom', this.dtp.config.jobQueues.newsroom); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
async create (feedDefinition) { |
|
|
async create (feedDefinition) { |
|
|
feedDefinition.url = feedDefinition.url.trim(); |
|
|
feedDefinition.url = feedDefinition.url.trim(); |
|
|
const feedContent = await this.load(feedDefinition.url); |
|
|
const feedContent = await this.load(feedDefinition.url); |
|
@ -63,7 +67,8 @@ class FeedService extends SiteService { |
|
|
await Feed.updateOne({ _id: feed._id }, updateOp); |
|
|
await Feed.updateOne({ _id: feed._id }, updateOp); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async getFeeds (pagination) { |
|
|
async getFeeds (pagination, options) { |
|
|
|
|
|
options = Object.assign({ withEntries: false, entryCount: 3 }, options); |
|
|
pagination = Object.assign({ skip: 0, cpp: 10 }, pagination); |
|
|
pagination = Object.assign({ skip: 0, cpp: 10 }, pagination); |
|
|
const feeds = await Feed |
|
|
const feeds = await Feed |
|
|
.find() |
|
|
.find() |
|
@ -71,7 +76,21 @@ class FeedService extends SiteService { |
|
|
.skip(pagination.skip) |
|
|
.skip(pagination.skip) |
|
|
.limit(pagination.cpp) |
|
|
.limit(pagination.cpp) |
|
|
.lean(); |
|
|
.lean(); |
|
|
|
|
|
|
|
|
|
|
|
if (options.withEntries) { |
|
|
|
|
|
await SiteAsync.each(feeds, async (feed) => { |
|
|
|
|
|
try { |
|
|
|
|
|
feed.recent = await this.getFeedEntries(feed, { skip: 0, cpp: options.entryCount }); |
|
|
|
|
|
this.log.debug('feed entries', { count: feed.recent.entries.length }); |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
this.log.error('failed to populate recent entries for feed', { feedId: feed._id, error }); |
|
|
|
|
|
// fall through
|
|
|
|
|
|
} |
|
|
|
|
|
}, 2); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const totalFeedCount = await Feed.countDocuments(); |
|
|
const totalFeedCount = await Feed.countDocuments(); |
|
|
|
|
|
|
|
|
return { feeds, totalFeedCount }; |
|
|
return { feeds, totalFeedCount }; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|