From 1ed1994fffb18a2b0bd74e49b50067ab047f8ab8 Mon Sep 17 00:00:00 2001 From: Alecks Gates Date: Mon, 5 Jun 2023 02:00:30 -0500 Subject: Use largest avatar in RSS feeds, unique guid for liveItems (#5817) * Attempt to get largest avatar size * WIP live guid changes * Use largest avatar version in feeds * Misc variable names/import changes * Update podcast feed tests for guid changes * More testing * Lint fix * Styling --------- Co-authored-by: Chocobozzz --- server/controllers/feeds/shared/common-feed-utils.ts | 10 +++++++--- server/controllers/feeds/video-podcast-feeds.ts | 20 ++++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) (limited to 'server/controllers/feeds') diff --git a/server/controllers/feeds/shared/common-feed-utils.ts b/server/controllers/feeds/shared/common-feed-utils.ts index 375c2814b..8f35a8b35 100644 --- a/server/controllers/feeds/shared/common-feed-utils.ts +++ b/server/controllers/feeds/shared/common-feed-utils.ts @@ -1,4 +1,5 @@ import express from 'express' +import { maxBy } from 'lodash' import { Feed } from '@peertube/feed' import { CustomTag, CustomXMLNS, Person } from '@peertube/feed/lib/typings' import { mdToOneLinePlainText } from '@server/helpers/markdown' @@ -104,11 +105,13 @@ export async function buildFeedMetadata (options: { accountLink = videoChannel.Account.getClientUrl() if (videoChannel.Actor.hasImage(ActorImageType.AVATAR)) { - imageUrl = WEBSERVER.URL + videoChannel.Actor.Avatars[0].getStaticPath() + const videoChannelAvatar = maxBy(videoChannel.Actor.Avatars, 'width') + imageUrl = WEBSERVER.URL + videoChannelAvatar.getStaticPath() } if (videoChannel.Account.Actor.hasImage(ActorImageType.AVATAR)) { - accountImageUrl = WEBSERVER.URL + videoChannel.Account.Actor.Avatars[0].getStaticPath() + const accountAvatar = maxBy(videoChannel.Account.Actor.Avatars, 'width') + accountImageUrl = WEBSERVER.URL + accountAvatar.getStaticPath() } user = await UserModel.loadById(videoChannel.Account.userId) @@ -120,7 +123,8 @@ export async function buildFeedMetadata (options: { accountLink = link if (account.Actor.hasImage(ActorImageType.AVATAR)) { - imageUrl = WEBSERVER.URL + account.Actor.Avatars[0].getStaticPath() + const accountAvatar = maxBy(account.Actor.Avatars, 'width') + imageUrl = WEBSERVER.URL + accountAvatar?.getStaticPath() accountImageUrl = imageUrl } diff --git a/server/controllers/feeds/video-podcast-feeds.ts b/server/controllers/feeds/video-podcast-feeds.ts index 45d31c781..f63f6ee63 100644 --- a/server/controllers/feeds/video-podcast-feeds.ts +++ b/server/controllers/feeds/video-podcast-feeds.ts @@ -1,4 +1,5 @@ import express from 'express' +import { maxBy } from 'lodash' import { extname } from 'path' import { Feed } from '@peertube/feed' import { CustomTag, CustomXMLNS, LiveItemStatus } from '@peertube/feed/lib/typings' @@ -141,8 +142,21 @@ async function generatePodcastItem (options: { href: account.getClientUrl() } + const commonAttributes = getCommonVideoFeedAttributes(video) + const guid = liveItem + ? `${video.uuid}_${video.publishedAt.toISOString()}` + : commonAttributes.link + + let personImage: string + + if (account.Actor.hasImage(ActorImageType.AVATAR)) { + const avatar = maxBy(account.Actor.Avatars, 'width') + personImage = WEBSERVER.URL + avatar.getStaticPath() + } + return { - ...getCommonVideoFeedAttributes(video), + guid, + ...commonAttributes, trackers: video.getTrackerUrls(), @@ -151,9 +165,7 @@ async function generatePodcastItem (options: { { ...author, - img: account.Actor.hasImage(ActorImageType.AVATAR) - ? WEBSERVER.URL + account.Actor.Avatars[0].getStaticPath() - : undefined + img: personImage } ], -- cgit v1.2.3