mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-06 03:50:26 +02:00
server/server -> server/core
This commit is contained in:
parent
114327d4ce
commit
5a3d0650c9
838 changed files with 111 additions and 111 deletions
96
server/core/controllers/feeds/comment-feeds.ts
Normal file
96
server/core/controllers/feeds/comment-feeds.ts
Normal file
|
@ -0,0 +1,96 @@
|
|||
import express from 'express'
|
||||
import { toSafeHtml } from '@server/helpers/markdown.js'
|
||||
import { cacheRouteFactory } from '@server/middlewares/index.js'
|
||||
import { CONFIG } from '../../initializers/config.js'
|
||||
import { ROUTE_CACHE_LIFETIME, WEBSERVER } from '../../initializers/constants.js'
|
||||
import {
|
||||
asyncMiddleware,
|
||||
feedsFormatValidator,
|
||||
setFeedFormatContentType,
|
||||
videoCommentsFeedsValidator,
|
||||
feedsAccountOrChannelFiltersValidator
|
||||
} from '../../middlewares/index.js'
|
||||
import { VideoCommentModel } from '../../models/video/video-comment.js'
|
||||
import { buildFeedMetadata, initFeed, sendFeed } from './shared/index.js'
|
||||
|
||||
const commentFeedsRouter = express.Router()
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const { middleware: cacheRouteMiddleware } = cacheRouteFactory({
|
||||
headerBlacklist: [ 'Content-Type' ]
|
||||
})
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
commentFeedsRouter.get('/video-comments.:format',
|
||||
feedsFormatValidator,
|
||||
setFeedFormatContentType,
|
||||
cacheRouteMiddleware(ROUTE_CACHE_LIFETIME.FEEDS),
|
||||
asyncMiddleware(feedsAccountOrChannelFiltersValidator),
|
||||
asyncMiddleware(videoCommentsFeedsValidator),
|
||||
asyncMiddleware(generateVideoCommentsFeed)
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
commentFeedsRouter
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function generateVideoCommentsFeed (req: express.Request, res: express.Response) {
|
||||
const start = 0
|
||||
const video = res.locals.videoAll
|
||||
const account = res.locals.account
|
||||
const videoChannel = res.locals.videoChannel
|
||||
|
||||
const comments = await VideoCommentModel.listForFeed({
|
||||
start,
|
||||
count: CONFIG.FEEDS.COMMENTS.COUNT,
|
||||
videoId: video ? video.id : undefined,
|
||||
accountId: account ? account.id : undefined,
|
||||
videoChannelId: videoChannel ? videoChannel.id : undefined
|
||||
})
|
||||
|
||||
const { name, description, imageUrl, link } = await buildFeedMetadata({ video, account, videoChannel })
|
||||
|
||||
const feed = initFeed({
|
||||
name,
|
||||
description,
|
||||
imageUrl,
|
||||
isPodcast: false,
|
||||
link,
|
||||
resourceType: 'video-comments',
|
||||
queryString: new URL(WEBSERVER.URL + req.originalUrl).search
|
||||
})
|
||||
|
||||
// Adding video items to the feed, one at a time
|
||||
for (const comment of comments) {
|
||||
const localLink = 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,
|
||||
id: localLink,
|
||||
link: localLink,
|
||||
content: toSafeHtml(comment.text),
|
||||
author,
|
||||
date: comment.createdAt
|
||||
})
|
||||
}
|
||||
|
||||
// Now the feed generation is done, let's send it!
|
||||
return sendFeed(feed, req, res)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue