import * as express from 'express'
-import { CONFIG } from '../initializers'
-import { asyncMiddleware, feedsValidator } from '../middlewares'
+import { CONFIG, FEEDS } from '../initializers/constants'
+import { asyncMiddleware, feedsValidator, setDefaultSort, videosSortValidator } from '../middlewares'
import { VideoModel } from '../models/video/video'
import * as Feed from 'pfeed'
-import { ResultList } from '../../shared/models'
import { AccountModel } from '../models/account/account'
+import { cacheRoute } from '../middlewares/cache'
+import { VideoChannelModel } from '../models/video/video-channel'
const feedsRouter = express.Router()
feedsRouter.get('/feeds/videos.:format',
+ videosSortValidator,
+ setDefaultSort,
asyncMiddleware(feedsValidator),
+ asyncMiddleware(cacheRoute),
asyncMiddleware(generateFeed)
)
async function generateFeed (req: express.Request, res: express.Response, next: express.NextFunction) {
let feed = initFeed()
- let feedStart = 0
- let feedCount = 10
- let feedSort = '-createdAt'
+ const start = 0
- let resultList: ResultList<VideoModel>
const account: AccountModel = res.locals.account
-
- if (account) {
- resultList = await VideoModel.listUserVideosForApi(
- account.id,
- feedStart,
- feedCount,
- feedSort,
- true
- )
- } else {
- resultList = await VideoModel.listForApi(
- feedStart,
- feedCount,
- feedSort,
- req.query.filter,
- true
- )
- }
+ const videoChannel: VideoChannelModel = res.locals.videoChannel
+ const hideNSFW = CONFIG.INSTANCE.DEFAULT_NSFW_POLICY === 'do_not_list'
+
+ const resultList = await VideoModel.listForApi({
+ start,
+ count: FEEDS.COUNT,
+ sort: req.query.sort,
+ hideNSFW,
+ filter: req.query.filter,
+ withFiles: true,
+ accountId: account ? account.id : null,
+ videoChannelId: videoChannel ? videoChannel.id : null
+ })
// Adding video items to the feed, one at a time
resultList.data.forEach(video => {
rss: `${webserverUrl}/feeds/videos.xml`
},
author: {
- name: 'instance admin of ' + CONFIG.INSTANCE.NAME,
+ name: 'Instance admin of ' + CONFIG.INSTANCE.NAME,
email: CONFIG.ADMIN.EMAIL,
link: `${webserverUrl}/about`
}