Implement video channel feeds

pull/525/head
Chocobozzz 2018-04-25 17:30:46 +02:00
parent 170726f523
commit e0ea4b1d55
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 8 additions and 9 deletions

View File

@ -3,10 +3,9 @@ import { CONFIG, FEEDS } from '../initializers/constants'
import { asyncMiddleware, feedsValidator, setDefaultSort, videosSortValidator } from '../middlewares' import { asyncMiddleware, feedsValidator, setDefaultSort, videosSortValidator } from '../middlewares'
import { VideoModel } from '../models/video/video' import { VideoModel } from '../models/video/video'
import * as Feed from 'pfeed' import * as Feed from 'pfeed'
import { ResultList } from '../../shared/models'
import { AccountModel } from '../models/account/account' import { AccountModel } from '../models/account/account'
import { cacheRoute } from '../middlewares/cache' import { cacheRoute } from '../middlewares/cache'
import { VideoSortField } from '../../client/src/app/shared/video/sort-field.type' import { VideoChannelModel } from '../models/video/video-channel'
const feedsRouter = express.Router() const feedsRouter = express.Router()
@ -31,6 +30,7 @@ async function generateFeed (req: express.Request, res: express.Response, next:
const start = 0 const start = 0
const account: AccountModel = res.locals.account const account: AccountModel = res.locals.account
const videoChannel: VideoChannelModel = res.locals.videoChannel
const hideNSFW = CONFIG.INSTANCE.DEFAULT_NSFW_POLICY === 'do_not_list' const hideNSFW = CONFIG.INSTANCE.DEFAULT_NSFW_POLICY === 'do_not_list'
const resultList = await VideoModel.listForApi({ const resultList = await VideoModel.listForApi({
@ -40,7 +40,8 @@ async function generateFeed (req: express.Request, res: express.Response, next:
hideNSFW, hideNSFW,
filter: req.query.filter, filter: req.query.filter,
withFiles: true, withFiles: true,
accountId: account ? account.id : null accountId: account ? account.id : null,
videoChannelId: videoChannel ? videoChannel.id : null
}) })
// Adding video items to the feed, one at a time // Adding video items to the feed, one at a time

View File

@ -1,11 +1,12 @@
import * as express from 'express' import * as express from 'express'
import { param, query } from 'express-validator/check' import { param, query } from 'express-validator/check'
import { isAccountIdExist, isAccountNameValid, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts' import { isAccountIdExist, isAccountNameValid } from '../../helpers/custom-validators/accounts'
import { join } from 'path' import { join } from 'path'
import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
import { logger } from '../../helpers/logger' import { logger } from '../../helpers/logger'
import { areValidationErrors } from './utils' import { areValidationErrors } from './utils'
import { isValidRSSFeed } from '../../helpers/custom-validators/feeds' import { isValidRSSFeed } from '../../helpers/custom-validators/feeds'
import { isVideoChannelExist } from '../../helpers/custom-validators/video-channels'
const feedsValidator = [ const feedsValidator = [
param('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'), param('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'),
@ -18,11 +19,8 @@ const feedsValidator = [
if (areValidationErrors(req, res)) return if (areValidationErrors(req, res)) return
if (req.query.accountId) { if (req.query.accountId && !await isAccountIdExist(req.query.accountId, res)) return
if (!await isAccountIdExist(req.query.accountId, res)) return if (req.query.videoChannelId && !await isVideoChannelExist(req.query.videoChannelId, res)) return
} else if (req.query.accountName) {
if (!await isLocalAccountNameExist(req.query.accountName, res)) return
}
return next() return next()
} }