diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/feeds.ts | 30 | ||||
-rw-r--r-- | server/tests/feeds/feeds.ts | 9 |
2 files changed, 24 insertions, 15 deletions
diff --git a/server/controllers/feeds.ts b/server/controllers/feeds.ts index e6cdaf94b..90faaf024 100644 --- a/server/controllers/feeds.ts +++ b/server/controllers/feeds.ts | |||
@@ -1,12 +1,13 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import Feed from 'pfeed' | 2 | import { Feed } from '@peertube/feed' |
3 | import { extname } from 'path' | ||
3 | import { mdToOneLinePlainText, toSafeHtml } from '@server/helpers/markdown' | 4 | import { mdToOneLinePlainText, toSafeHtml } from '@server/helpers/markdown' |
4 | import { getServerActor } from '@server/models/application/application' | 5 | import { getServerActor } from '@server/models/application/application' |
5 | import { getCategoryLabel } from '@server/models/video/formatter/video-format-utils' | 6 | import { getCategoryLabel } from '@server/models/video/formatter/video-format-utils' |
6 | import { VideoInclude } from '@shared/models' | 7 | import { VideoInclude } from '@shared/models' |
7 | import { buildNSFWFilter } from '../helpers/express-utils' | 8 | import { buildNSFWFilter } from '../helpers/express-utils' |
8 | import { CONFIG } from '../initializers/config' | 9 | import { CONFIG } from '../initializers/config' |
9 | import { FEEDS, PREVIEWS_SIZE, ROUTE_CACHE_LIFETIME, WEBSERVER } from '../initializers/constants' | 10 | import { FEEDS, MIMETYPES, PREVIEWS_SIZE, ROUTE_CACHE_LIFETIME, WEBSERVER } from '../initializers/constants' |
10 | import { | 11 | import { |
11 | asyncMiddleware, | 12 | asyncMiddleware, |
12 | commonVideosFiltersValidator, | 13 | commonVideosFiltersValidator, |
@@ -258,10 +259,7 @@ function initFeed (parameters: { | |||
258 | }) | 259 | }) |
259 | } | 260 | } |
260 | 261 | ||
261 | function addVideosToFeed (feed, videos: VideoModel[]) { | 262 | function addVideosToFeed (feed: Feed, videos: VideoModel[]) { |
262 | /** | ||
263 | * Adding video items to the feed object, one at a time | ||
264 | */ | ||
265 | for (const video of videos) { | 263 | for (const video of videos) { |
266 | const formattedVideoFiles = video.getFormattedVideoFilesJSON(false) | 264 | const formattedVideoFiles = video.getFormattedVideoFilesJSON(false) |
267 | 265 | ||
@@ -273,9 +271,9 @@ function addVideosToFeed (feed, videos: VideoModel[]) { | |||
273 | 271 | ||
274 | const videos = formattedVideoFiles.map(videoFile => { | 272 | const videos = formattedVideoFiles.map(videoFile => { |
275 | const result = { | 273 | const result = { |
276 | type: 'video/mp4', | 274 | type: MIMETYPES.VIDEO.EXT_MIMETYPE[extname(videoFile.fileUrl)], |
277 | medium: 'video', | 275 | medium: 'video', |
278 | height: videoFile.resolution.label.replace('p', ''), | 276 | height: videoFile.resolution.id, |
279 | fileSize: videoFile.size, | 277 | fileSize: videoFile.size, |
280 | url: videoFile.fileUrl, | 278 | url: videoFile.fileUrl, |
281 | framerate: videoFile.fps, | 279 | framerate: videoFile.fps, |
@@ -309,8 +307,18 @@ function addVideosToFeed (feed, videos: VideoModel[]) { | |||
309 | ], | 307 | ], |
310 | date: video.publishedAt, | 308 | date: video.publishedAt, |
311 | nsfw: video.nsfw, | 309 | nsfw: video.nsfw, |
312 | torrent: torrents, | 310 | torrents, |
311 | |||
312 | // Enclosure | ||
313 | video: { | ||
314 | url: videos[0].url, | ||
315 | length: videos[0].fileSize, | ||
316 | type: videos[0].type | ||
317 | }, | ||
318 | |||
319 | // Media RSS | ||
313 | videos, | 320 | videos, |
321 | |||
314 | embed: { | 322 | embed: { |
315 | url: video.getEmbedStaticPath(), | 323 | url: video.getEmbedStaticPath(), |
316 | allowFullscreen: true | 324 | allowFullscreen: true |
@@ -324,7 +332,7 @@ function addVideosToFeed (feed, videos: VideoModel[]) { | |||
324 | views: video.views | 332 | views: video.views |
325 | } | 333 | } |
326 | }, | 334 | }, |
327 | thumbnail: [ | 335 | thumbnails: [ |
328 | { | 336 | { |
329 | url: WEBSERVER.URL + video.getPreviewStaticPath(), | 337 | url: WEBSERVER.URL + video.getPreviewStaticPath(), |
330 | height: PREVIEWS_SIZE.height, | 338 | height: PREVIEWS_SIZE.height, |
@@ -335,7 +343,7 @@ function addVideosToFeed (feed, videos: VideoModel[]) { | |||
335 | } | 343 | } |
336 | } | 344 | } |
337 | 345 | ||
338 | function sendFeed (feed, req: express.Request, res: express.Response) { | 346 | function sendFeed (feed: Feed, req: express.Request, res: express.Response) { |
339 | const format = req.params.format | 347 | const format = req.params.format |
340 | 348 | ||
341 | if (format === 'atom' || format === 'atom1') { | 349 | if (format === 'atom' || format === 'atom1') { |
diff --git a/server/tests/feeds/feeds.ts b/server/tests/feeds/feeds.ts index 74cbaeb6d..4dcd77cca 100644 --- a/server/tests/feeds/feeds.ts +++ b/server/tests/feeds/feeds.ts | |||
@@ -156,9 +156,10 @@ describe('Test syndication feeds', () => { | |||
156 | 156 | ||
157 | const enclosure = xmlDoc.rss.channel.item[0].enclosure | 157 | const enclosure = xmlDoc.rss.channel.item[0].enclosure |
158 | expect(enclosure).to.exist | 158 | expect(enclosure).to.exist |
159 | expect(enclosure['@_type']).to.equal('application/x-bittorrent') | 159 | |
160 | expect(enclosure['@_type']).to.equal('video/webm') | ||
160 | expect(enclosure['@_length']).to.equal(218910) | 161 | expect(enclosure['@_length']).to.equal(218910) |
161 | expect(enclosure['@_url']).to.contain('720.torrent') | 162 | expect(enclosure['@_url']).to.contain('-720.webm') |
162 | } | 163 | } |
163 | }) | 164 | }) |
164 | 165 | ||
@@ -274,8 +275,8 @@ describe('Test syndication feeds', () => { | |||
274 | 275 | ||
275 | const jsonObj = JSON.parse(json) | 276 | const jsonObj = JSON.parse(json) |
276 | expect(jsonObj.items.length).to.be.equal(2) | 277 | expect(jsonObj.items.length).to.be.equal(2) |
277 | expect(jsonObj.items[0].html_content).to.contain('<p>super comment 2</p>') | 278 | expect(jsonObj.items[0].content_html).to.contain('<p>super comment 2</p>') |
278 | expect(jsonObj.items[1].html_content).to.contain('<p>super comment 1</p>') | 279 | expect(jsonObj.items[1].content_html).to.contain('<p>super comment 1</p>') |
279 | } | 280 | } |
280 | }) | 281 | }) |
281 | 282 | ||