mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-02-25 18:55:32 -06:00
Adapt feeds content-type to accept header
This commit is contained in:
@@ -74,7 +74,7 @@ activityPubClientRouter.get('/accounts?/:name/dislikes/:videoId',
|
||||
|
||||
activityPubClientRouter.get('/videos/watch/:id',
|
||||
executeIfActivityPub,
|
||||
asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS)),
|
||||
asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS)),
|
||||
asyncMiddleware(videosCustomGetValidator('only-video-with-rights')),
|
||||
asyncMiddleware(videoController)
|
||||
)
|
||||
|
||||
@@ -11,7 +11,7 @@ import * as memoizee from 'memoizee'
|
||||
const overviewsRouter = express.Router()
|
||||
|
||||
overviewsRouter.get('/videos',
|
||||
asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.OVERVIEWS.VIDEOS)),
|
||||
asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.OVERVIEWS.VIDEOS)),
|
||||
asyncMiddleware(getVideosOverview)
|
||||
)
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import { CONFIG } from '../../../initializers/config'
|
||||
const statsRouter = express.Router()
|
||||
|
||||
statsRouter.get('/stats',
|
||||
asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.STATS)),
|
||||
asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.STATS)),
|
||||
asyncMiddleware(getStats)
|
||||
)
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ const botsRouter = express.Router()
|
||||
// Special route that add OpenGraph and oEmbed tags
|
||||
// Do not use a template engine for a so little thing
|
||||
botsRouter.use('/sitemap.xml',
|
||||
asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.SITEMAP)),
|
||||
asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.SITEMAP)),
|
||||
asyncMiddleware(getSitemap)
|
||||
)
|
||||
|
||||
|
||||
@@ -6,7 +6,9 @@ import {
|
||||
setDefaultSort,
|
||||
videoCommentsFeedsValidator,
|
||||
videoFeedsValidator,
|
||||
videosSortValidator
|
||||
videosSortValidator,
|
||||
feedsFormatValidator,
|
||||
setFeedFormatContentType
|
||||
} from '../middlewares'
|
||||
import { VideoModel } from '../models/video/video'
|
||||
import * as Feed from 'pfeed'
|
||||
@@ -18,7 +20,13 @@ import { CONFIG } from '../initializers/config'
|
||||
const feedsRouter = express.Router()
|
||||
|
||||
feedsRouter.get('/feeds/video-comments.:format',
|
||||
asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.FEEDS)),
|
||||
feedsFormatValidator,
|
||||
setFeedFormatContentType,
|
||||
asyncMiddleware(cacheRoute({
|
||||
headerBlacklist: [
|
||||
'Content-Type'
|
||||
]
|
||||
})(ROUTE_CACHE_LIFETIME.FEEDS)),
|
||||
asyncMiddleware(videoCommentsFeedsValidator),
|
||||
asyncMiddleware(generateVideoCommentsFeed)
|
||||
)
|
||||
@@ -26,7 +34,13 @@ feedsRouter.get('/feeds/video-comments.:format',
|
||||
feedsRouter.get('/feeds/videos.:format',
|
||||
videosSortValidator,
|
||||
setDefaultSort,
|
||||
asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.FEEDS)),
|
||||
feedsFormatValidator,
|
||||
setFeedFormatContentType,
|
||||
asyncMiddleware(cacheRoute({
|
||||
headerBlacklist: [
|
||||
'Content-Type'
|
||||
]
|
||||
})(ROUTE_CACHE_LIFETIME.FEEDS)),
|
||||
commonVideosFiltersValidator,
|
||||
asyncMiddleware(videoFeedsValidator),
|
||||
asyncMiddleware(generateVideoFeed)
|
||||
@@ -224,26 +238,21 @@ function sendFeed (feed, req: express.Request, res: express.Response) {
|
||||
const format = req.params.format
|
||||
|
||||
if (format === 'atom' || format === 'atom1') {
|
||||
res.set('Content-Type', 'application/atom+xml')
|
||||
return res.send(feed.atom1()).end()
|
||||
}
|
||||
|
||||
if (format === 'json' || format === 'json1') {
|
||||
res.set('Content-Type', 'application/json')
|
||||
return res.send(feed.json1()).end()
|
||||
}
|
||||
|
||||
if (format === 'rss' || format === 'rss2') {
|
||||
res.set('Content-Type', 'application/rss+xml')
|
||||
return res.send(feed.rss2()).end()
|
||||
}
|
||||
|
||||
// We're in the ambiguous '.xml' case and we look at the format query parameter
|
||||
if (req.query.format === 'atom' || req.query.format === 'atom1') {
|
||||
res.set('Content-Type', 'application/atom+xml')
|
||||
return res.send(feed.atom1()).end()
|
||||
}
|
||||
|
||||
res.set('Content-Type', 'application/rss+xml')
|
||||
return res.send(feed.rss2()).end()
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ staticRouter.use(
|
||||
|
||||
// robots.txt service
|
||||
staticRouter.get('/robots.txt',
|
||||
asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.ROBOTS)),
|
||||
asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.ROBOTS)),
|
||||
(_, res: express.Response) => {
|
||||
res.type('text/plain')
|
||||
return res.send(CONFIG.INSTANCE.ROBOTS)
|
||||
@@ -127,7 +127,7 @@ staticRouter.get('/security.txt',
|
||||
)
|
||||
|
||||
staticRouter.get('/.well-known/security.txt',
|
||||
asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.SECURITYTXT)),
|
||||
asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.SECURITYTXT)),
|
||||
(_, res: express.Response) => {
|
||||
res.type('text/plain')
|
||||
return res.send(CONFIG.INSTANCE.SECURITYTXT + CONFIG.INSTANCE.SECURITYTXT_CONTACT)
|
||||
@@ -136,7 +136,7 @@ staticRouter.get('/.well-known/security.txt',
|
||||
|
||||
// nodeinfo service
|
||||
staticRouter.use('/.well-known/nodeinfo',
|
||||
asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.NODEINFO)),
|
||||
asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.NODEINFO)),
|
||||
(_, res: express.Response) => {
|
||||
return res.json({
|
||||
links: [
|
||||
@@ -149,13 +149,13 @@ staticRouter.use('/.well-known/nodeinfo',
|
||||
}
|
||||
)
|
||||
staticRouter.use('/nodeinfo/:version.json',
|
||||
asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.NODEINFO)),
|
||||
asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.NODEINFO)),
|
||||
asyncMiddleware(generateNodeinfo)
|
||||
)
|
||||
|
||||
// dnt-policy.txt service (see https://www.eff.org/dnt-policy)
|
||||
staticRouter.use('/.well-known/dnt-policy.txt',
|
||||
asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.DNT_POLICY)),
|
||||
asyncMiddleware(cacheRoute()(ROUTE_CACHE_LIFETIME.DNT_POLICY)),
|
||||
(_, res: express.Response) => {
|
||||
res.type('text/plain')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user