aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/feeds.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-08-13 15:07:23 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-11-25 11:07:56 +0100
commitafff310e50f2fa8419bb4242470cbde46ab54463 (patch)
tree34efda2daf8f7cdfd89ef6616a79e2222082f93a /server/controllers/feeds.ts
parentf619de0e435f7ac3abad2ec772397486358b56e7 (diff)
downloadPeerTube-afff310e50f2fa8419bb4242470cbde46ab54463.tar.gz
PeerTube-afff310e50f2fa8419bb4242470cbde46ab54463.tar.zst
PeerTube-afff310e50f2fa8419bb4242470cbde46ab54463.zip
allow private syndication feeds via a user feedToken
Diffstat (limited to 'server/controllers/feeds.ts')
-rw-r--r--server/controllers/feeds.ts32
1 files changed, 27 insertions, 5 deletions
diff --git a/server/controllers/feeds.ts b/server/controllers/feeds.ts
index f14c0d316..6e9f7e60c 100644
--- a/server/controllers/feeds.ts
+++ b/server/controllers/feeds.ts
@@ -11,11 +11,14 @@ import {
11 setFeedFormatContentType, 11 setFeedFormatContentType,
12 videoCommentsFeedsValidator, 12 videoCommentsFeedsValidator,
13 videoFeedsValidator, 13 videoFeedsValidator,
14 videosSortValidator 14 videosSortValidator,
15 videoSubscriptonFeedsValidator
15} from '../middlewares' 16} from '../middlewares'
16import { cacheRoute } from '../middlewares/cache' 17import { cacheRoute } from '../middlewares/cache'
17import { VideoModel } from '../models/video/video' 18import { VideoModel } from '../models/video/video'
18import { VideoCommentModel } from '../models/video/video-comment' 19import { VideoCommentModel } from '../models/video/video-comment'
20import { VideoFilter } from '../../shared/models/videos/video-query.type'
21import { logger } from '../helpers/logger'
19 22
20const feedsRouter = express.Router() 23const feedsRouter = express.Router()
21 24
@@ -44,6 +47,7 @@ feedsRouter.get('/feeds/videos.:format',
44 })(ROUTE_CACHE_LIFETIME.FEEDS)), 47 })(ROUTE_CACHE_LIFETIME.FEEDS)),
45 commonVideosFiltersValidator, 48 commonVideosFiltersValidator,
46 asyncMiddleware(videoFeedsValidator), 49 asyncMiddleware(videoFeedsValidator),
50 asyncMiddleware(videoSubscriptonFeedsValidator),
47 asyncMiddleware(generateVideoFeed) 51 asyncMiddleware(generateVideoFeed)
48) 52)
49 53
@@ -124,6 +128,7 @@ async function generateVideoFeed (req: express.Request, res: express.Response) {
124 128
125 const account = res.locals.account 129 const account = res.locals.account
126 const videoChannel = res.locals.videoChannel 130 const videoChannel = res.locals.videoChannel
131 const token = req.query.token
127 const nsfw = buildNSFWFilter(res, req.query.nsfw) 132 const nsfw = buildNSFWFilter(res, req.query.nsfw)
128 133
129 let name: string 134 let name: string
@@ -147,19 +152,36 @@ async function generateVideoFeed (req: express.Request, res: express.Response) {
147 queryString: new URL(WEBSERVER.URL + req.url).search 152 queryString: new URL(WEBSERVER.URL + req.url).search
148 }) 153 })
149 154
155 /**
156 * We have two ways to query video results:
157 * - one with account and token -> get subscription videos
158 * - one with either account, channel, or nothing: just videos with these filters
159 */
160 const options = token && token !== '' && res.locals.user
161 ? {
162 followerActorId: res.locals.user.Account.Actor.id,
163 user: res.locals.user,
164 includeLocalVideos: false
165 }
166 : {
167 accountId: account ? account.id : null,
168 videoChannelId: videoChannel ? videoChannel.id : null
169 }
170
150 const resultList = await VideoModel.listForApi({ 171 const resultList = await VideoModel.listForApi({
151 start, 172 start,
152 count: FEEDS.COUNT, 173 count: FEEDS.COUNT,
153 sort: req.query.sort, 174 sort: req.query.sort,
154 includeLocalVideos: true, 175 includeLocalVideos: true,
155 nsfw, 176 nsfw,
156 filter: req.query.filter, 177 filter: req.query.filter as VideoFilter,
157 withFiles: true, 178 withFiles: true,
158 accountId: account ? account.id : null, 179 ...options
159 videoChannelId: videoChannel ? videoChannel.id : null
160 }) 180 })
161 181
162 // Adding video items to the feed, one at a time 182 /**
183 * Adding video items to the feed object, one at a time
184 */
163 resultList.data.forEach(video => { 185 resultList.data.forEach(video => {
164 const formattedVideoFiles = video.getFormattedVideoFilesJSON() 186 const formattedVideoFiles = video.getFormattedVideoFilesJSON()
165 187