diff options
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | server/controllers/feeds.ts | 30 | ||||
-rw-r--r-- | server/tests/feeds/feeds.ts | 9 | ||||
-rw-r--r-- | yarn.lock | 29 |
4 files changed, 40 insertions, 30 deletions
diff --git a/package.json b/package.json index 67ea2be75..76b8fe636 100644 --- a/package.json +++ b/package.json | |||
@@ -79,6 +79,7 @@ | |||
79 | "dependencies": { | 79 | "dependencies": { |
80 | "@aws-sdk/client-s3": "^3.23.0", | 80 | "@aws-sdk/client-s3": "^3.23.0", |
81 | "@babel/parser": "7.16.8", | 81 | "@babel/parser": "7.16.8", |
82 | "@peertube/feed": "^5.0.0", | ||
82 | "@peertube/http-signature": "^1.4.0", | 83 | "@peertube/http-signature": "^1.4.0", |
83 | "@uploadx/core": "^5.0.0", | 84 | "@uploadx/core": "^5.0.0", |
84 | "async": "^3.0.1", | 85 | "async": "^3.0.1", |
@@ -129,7 +130,6 @@ | |||
129 | "parse-torrent": "^9.1.0", | 130 | "parse-torrent": "^9.1.0", |
130 | "password-generator": "^2.0.2", | 131 | "password-generator": "^2.0.2", |
131 | "pem": "^1.12.3", | 132 | "pem": "^1.12.3", |
132 | "pfeed": "1.1.11", | ||
133 | "pg": "^8.2.1", | 133 | "pg": "^8.2.1", |
134 | "prompt": "^1.0.0", | 134 | "prompt": "^1.0.0", |
135 | "proxy-addr": "^2.0.7", | 135 | "proxy-addr": "^2.0.7", |
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 | ||
@@ -1449,6 +1449,13 @@ | |||
1449 | "@nodelib/fs.scandir" "2.1.5" | 1449 | "@nodelib/fs.scandir" "2.1.5" |
1450 | fastq "^1.6.0" | 1450 | fastq "^1.6.0" |
1451 | 1451 | ||
1452 | "@peertube/feed@^5.0.0": | ||
1453 | version "5.0.0" | ||
1454 | resolved "https://registry.yarnpkg.com/@peertube/feed/-/feed-5.0.0.tgz#f8cbc1e526a7af3112fca6d1859362b0bea13024" | ||
1455 | integrity sha512-YR78vHocVJsHWETz1US1+A4BZlu7Bykd0GuwCTdIQ1nfrfMXDBOiC/HM8+TYBqkp5oAqAbVyeVo6VxhpZzE3sw== | ||
1456 | dependencies: | ||
1457 | xml-js "^1.6.11" | ||
1458 | |||
1452 | "@peertube/http-signature@^1.4.0": | 1459 | "@peertube/http-signature@^1.4.0": |
1453 | version "1.4.0" | 1460 | version "1.4.0" |
1454 | resolved "https://registry.yarnpkg.com/@peertube/http-signature/-/http-signature-1.4.0.tgz#5d2bab08dfeca55490d926d145b3ec0cfb392d63" | 1461 | resolved "https://registry.yarnpkg.com/@peertube/http-signature/-/http-signature-1.4.0.tgz#5d2bab08dfeca55490d926d145b3ec0cfb392d63" |
@@ -5602,7 +5609,7 @@ lodash@4.17.19: | |||
5602 | resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b" | 5609 | resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b" |
5603 | integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ== | 5610 | integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ== |
5604 | 5611 | ||
5605 | lodash@>=4.17.13, lodash@^4.17.10, lodash@^4.17.15, lodash@^4.17.20, lodash@^4.17.21: | 5612 | lodash@>=4.17.13, lodash@^4.17.10, lodash@^4.17.20, lodash@^4.17.21: |
5606 | version "4.17.21" | 5613 | version "4.17.21" |
5607 | resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" | 5614 | resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" |
5608 | integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== | 5615 | integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== |
@@ -6654,14 +6661,6 @@ pem@^1.12.3: | |||
6654 | os-tmpdir "^1.0.1" | 6661 | os-tmpdir "^1.0.1" |
6655 | which "^2.0.2" | 6662 | which "^2.0.2" |
6656 | 6663 | ||
6657 | pfeed@1.1.11: | ||
6658 | version "1.1.11" | ||
6659 | resolved "https://registry.yarnpkg.com/pfeed/-/pfeed-1.1.11.tgz#a52f6b18aa01dfd3c8ff3c7189c456dc1b66d28f" | ||
6660 | integrity sha512-EheEV1A3xCQ61irXBvqy+V2vAEpeKjw7bTqH2Ck64LFMcGh9yOwncESreaWfUftRf6djRa0sXP6kkOnGWX/P7g== | ||
6661 | dependencies: | ||
6662 | lodash "^4.17.15" | ||
6663 | xml "^1.0.1" | ||
6664 | |||
6665 | pg-connection-string@^2.5.0: | 6664 | pg-connection-string@^2.5.0: |
6666 | version "2.5.0" | 6665 | version "2.5.0" |
6667 | resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.5.0.tgz#538cadd0f7e603fc09a12590f3b8a452c2c0cf34" | 6666 | resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.5.0.tgz#538cadd0f7e603fc09a12590f3b8a452c2c0cf34" |
@@ -8776,6 +8775,13 @@ xhr@^2.0.1: | |||
8776 | parse-headers "^2.0.0" | 8775 | parse-headers "^2.0.0" |
8777 | xtend "^4.0.0" | 8776 | xtend "^4.0.0" |
8778 | 8777 | ||
8778 | xml-js@^1.6.11: | ||
8779 | version "1.6.11" | ||
8780 | resolved "https://registry.yarnpkg.com/xml-js/-/xml-js-1.6.11.tgz#927d2f6947f7f1c19a316dd8eea3614e8b18f8e9" | ||
8781 | integrity sha512-7rVi2KMfwfWFl+GpPg6m80IVMWXLRjO+PxTq7V2CDhoGak0wzYzFgUY2m4XJ47OGdXd8eLE8EmwfAmdjw7lC1g== | ||
8782 | dependencies: | ||
8783 | sax "^1.2.4" | ||
8784 | |||
8779 | xml-parse-from-string@^1.0.0: | 8785 | xml-parse-from-string@^1.0.0: |
8780 | version "1.0.1" | 8786 | version "1.0.1" |
8781 | resolved "https://registry.yarnpkg.com/xml-parse-from-string/-/xml-parse-from-string-1.0.1.tgz#a9029e929d3dbcded169f3c6e28238d95a5d5a28" | 8787 | resolved "https://registry.yarnpkg.com/xml-parse-from-string/-/xml-parse-from-string-1.0.1.tgz#a9029e929d3dbcded169f3c6e28238d95a5d5a28" |
@@ -8789,11 +8795,6 @@ xml2js@^0.4.23, xml2js@^0.4.5: | |||
8789 | sax ">=0.6.0" | 8795 | sax ">=0.6.0" |
8790 | xmlbuilder "~11.0.0" | 8796 | xmlbuilder "~11.0.0" |
8791 | 8797 | ||
8792 | xml@^1.0.1: | ||
8793 | version "1.0.1" | ||
8794 | resolved "https://registry.yarnpkg.com/xml/-/xml-1.0.1.tgz#78ba72020029c5bc87b8a81a3cfcd74b4a2fc1e5" | ||
8795 | integrity sha1-eLpyAgApxbyHuKgaPPzXS0ovweU= | ||
8796 | |||
8797 | xmlbuilder@~11.0.0: | 8798 | xmlbuilder@~11.0.0: |
8798 | version "11.0.1" | 8799 | version "11.0.1" |
8799 | resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-11.0.1.tgz#be9bae1c8a046e76b31127726347d0ad7002beb3" | 8800 | resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-11.0.1.tgz#be9bae1c8a046e76b31127726347d0ad7002beb3" |