]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/feeds.ts
Translated using Weblate (Polish)
[github/Chocobozzz/PeerTube.git] / server / controllers / feeds.ts
index 960085af1af685d017c79e71fd324959105453a6..fa6c7ac714869a6ecba7795fe791d83025a1c6f9 100644 (file)
@@ -1,6 +1,5 @@
 import * as express from 'express'
-import { CONFIG, FEEDS, ROUTE_CACHE_LIFETIME } from '../initializers/constants'
-import { THUMBNAILS_SIZE } from '../initializers'
+import { FEEDS, ROUTE_CACHE_LIFETIME, THUMBNAILS_SIZE, WEBSERVER } from '../initializers/constants'
 import {
   asyncMiddleware,
   commonVideosFiltersValidator,
@@ -11,11 +10,10 @@ import {
 } from '../middlewares'
 import { VideoModel } from '../models/video/video'
 import * as Feed from 'pfeed'
-import { AccountModel } from '../models/account/account'
 import { cacheRoute } from '../middlewares/cache'
-import { VideoChannelModel } from '../models/video/video-channel'
 import { VideoCommentModel } from '../models/video/video-comment'
 import { buildNSFWFilter } from '../helpers/express-utils'
+import { CONFIG } from '../initializers/config'
 
 const feedsRouter = express.Router()
 
@@ -42,10 +40,10 @@ export {
 
 // ---------------------------------------------------------------------------
 
-async function generateVideoCommentsFeed (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function generateVideoCommentsFeed (req: express.Request, res: express.Response) {
   const start = 0
 
-  const video = res.locals.video as VideoModel
+  const video = res.locals.videoAll
   const videoId: number = video ? video.id : undefined
 
   const comments = await VideoCommentModel.listForFeed(start, FEEDS.COUNT, videoId)
@@ -56,19 +54,25 @@ async function generateVideoCommentsFeed (req: express.Request, res: express.Res
 
   // Adding video items to the feed, one at a time
   comments.forEach(comment => {
-    const link = CONFIG.WEBSERVER.URL + comment.getCommentStaticPath()
+    const link = WEBSERVER.URL + comment.getCommentStaticPath()
+
+    let title = comment.Video.name
+    const author: { name: string, link: string }[] = []
+
+    if (comment.Account) {
+      title += ` - ${comment.Account.getDisplayName()}`
+      author.push({
+        name: comment.Account.getDisplayName(),
+        link: comment.Account.Actor.url
+      })
+    }
 
     feed.addItem({
-      title: `${comment.Video.name} - ${comment.Account.getDisplayName()}`,
+      title,
       id: comment.url,
       link,
       content: comment.text,
-      author: [
-        {
-          name: comment.Account.getDisplayName(),
-          link: comment.Account.Actor.url
-        }
-      ],
+      author,
       date: comment.createdAt
     })
   })
@@ -77,11 +81,11 @@ async function generateVideoCommentsFeed (req: express.Request, res: express.Res
   return sendFeed(feed, req, res)
 }
 
-async function generateVideoFeed (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function generateVideoFeed (req: express.Request, res: express.Response) {
   const start = 0
 
-  const account: AccountModel = res.locals.account
-  const videoChannel: VideoChannelModel = res.locals.videoChannel
+  const account = res.locals.account
+  const videoChannel = res.locals.videoChannel
   const nsfw = buildNSFWFilter(res, req.query.nsfw)
 
   let name: string
@@ -115,16 +119,41 @@ async function generateVideoFeed (req: express.Request, res: express.Response, n
   // Adding video items to the feed, one at a time
   resultList.data.forEach(video => {
     const formattedVideoFiles = video.getFormattedVideoFilesJSON()
+
     const torrents = formattedVideoFiles.map(videoFile => ({
       title: video.name,
       url: videoFile.torrentUrl,
       size_in_bytes: videoFile.size
     }))
 
+    const videos = formattedVideoFiles.map(videoFile => {
+      const result = {
+        type: 'video/mp4',
+        medium: 'video',
+        height: videoFile.resolution.label.replace('p', ''),
+        fileSize: videoFile.size,
+        url: videoFile.fileUrl,
+        framerate: videoFile.fps,
+        duration: video.duration
+      }
+
+      if (video.language) Object.assign(result, { lang: video.language })
+
+      return result
+    })
+
+    const categories: { value: number, label: string }[] = []
+    if (video.category) {
+      categories.push({
+        value: video.category,
+        label: VideoModel.getCategoryLabel(video.category)
+      })
+    }
+
     feed.addItem({
       title: video.name,
       id: video.url,
-      link: CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid,
+      link: WEBSERVER.URL + '/videos/watch/' + video.uuid,
       description: video.getTruncatedDescription(),
       content: video.description,
       author: [
@@ -134,12 +163,25 @@ async function generateVideoFeed (req: express.Request, res: express.Response, n
         }
       ],
       date: video.publishedAt,
-      language: video.language,
       nsfw: video.nsfw,
       torrent: torrents,
+      videos,
+      embed: {
+        url: video.getEmbedStaticPath(),
+        allowFullscreen: true
+      },
+      player: {
+        url: video.getWatchStaticPath()
+      },
+      categories,
+      community: {
+        statistics: {
+          views: video.views
+        }
+      },
       thumbnail: [
         {
-          url: CONFIG.WEBSERVER.URL + video.getThumbnailStaticPath(),
+          url: WEBSERVER.URL + video.getMiniatureStaticPath(),
           height: THUMBNAILS_SIZE.height,
           width: THUMBNAILS_SIZE.width
         }
@@ -152,7 +194,7 @@ async function generateVideoFeed (req: express.Request, res: express.Response, n
 }
 
 function initFeed (name: string, description: string) {
-  const webserverUrl = CONFIG.WEBSERVER.URL
+  const webserverUrl = WEBSERVER.URL
 
   return new Feed({
     title: name,