Fix fetching client comment URL

pull/6633/head
Chocobozzz 2024-10-21 15:14:54 +02:00
parent 69017c6e01
commit a8bc342204
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 53 additions and 28 deletions

View File

@ -2,7 +2,7 @@
import { expect } from 'chai'
import { processViewersStats } from '@tests/shared/views.js'
import { HttpStatusCode, VideoPlaylistPrivacy, WatchActionObject } from '@peertube/peertube-models'
import { HttpStatusCode, VideoComment, VideoPlaylistPrivacy, WatchActionObject } from '@peertube/peertube-models'
import {
cleanupTests,
createMultipleServers,
@ -17,6 +17,7 @@ describe('Test activitypub', function () {
let servers: PeerTubeServer[] = []
let video: { id: number, uuid: string, shortUUID: string }
let playlist: { id: number, uuid: string, shortUUID: string }
let comment: VideoComment
async function testAccount (path: string) {
const res = await makeActivityPubGetRequest(servers[0].url, path)
@ -47,6 +48,18 @@ describe('Test activitypub', function () {
expect(object.name).to.equal('video')
}
async function testComment (path: string) {
const res = await makeActivityPubGetRequest(servers[0].url, path)
const object = res.body
expect(object.type).to.equal('Note')
expect(object.id).to.equal(servers[0].url + '/videos/watch/' + video.uuid + '/comments/' + comment.id)
expect(object.content).to.contain('thread')
expect(object.inReplyTo).to.contain(servers[0].url + '/videos/watch/' + video.uuid)
expect(object.attributedTo).to.equal(servers[0].url + '/accounts/root')
expect(object.replyApproval).to.equal(servers[0].url + '/videos/watch/' + video.uuid + '/comments/' + comment.id + '/approve-reply')
}
async function testPlaylist (path: string) {
const res = await makeActivityPubGetRequest(servers[0].url, path)
const object = res.body
@ -73,6 +86,8 @@ describe('Test activitypub', function () {
playlist = await servers[0].playlists.create({ attributes })
}
comment = await servers[0].comments.createThread({ text: 'thread', videoId: video.id })
await doubleFollow(servers[0], servers[1])
})
@ -86,6 +101,13 @@ describe('Test activitypub', function () {
await testChannel('/c/root_channel')
})
it('Should return the video comment object', async function () {
await testComment('/videos/watch/' + video.id + '/comments/' + comment.id)
await testComment('/videos/watch/' + video.uuid + '/comments/' + comment.id)
await testComment('/videos/watch/' + video.shortUUID + '/comments/' + comment.id)
await testComment('/w/' + video.shortUUID + ';threadId=' + comment.id)
})
it('Should return the video object', async function () {
await testVideo('/videos/watch/' + video.id)
await testVideo('/videos/watch/' + video.uuid)

View File

@ -104,6 +104,36 @@ activityPubClientRouter.get('/accounts?/:name/dislikes/:videoId',
asyncMiddleware(getAccountVideoRateFactory('dislike'))
)
// ---------------------------------------------------------------------------
activityPubClientRouter.get('/videos/watch/:id/comments',
executeIfActivityPub,
activityPubRateLimiter,
asyncMiddleware(videosCustomGetValidator('only-video-and-blacklist')),
asyncMiddleware(videoCommentsController)
)
activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId/approve-reply',
executeIfActivityPub,
activityPubRateLimiter,
asyncMiddleware(videoCommentGetValidator),
asyncMiddleware(videoCommentApprovedController)
)
activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId/activity',
executeIfActivityPub,
activityPubRateLimiter,
asyncMiddleware(videoCommentGetValidator),
asyncMiddleware(videoCommentController)
)
activityPubClientRouter.get(
[ '/videos/watch/:videoId/comments/:commentId', '/w/:videoId([^;]+);threadId=:commentId([0-9]+)' ],
executeIfActivityPub,
activityPubRateLimiter,
asyncMiddleware(videoCommentGetValidator),
asyncMiddleware(videoCommentController)
)
// ---------------------------------------------------------------------------
activityPubClientRouter.get(
[ '/videos/watch/:id', '/w/:id' ],
executeIfActivityPub,
@ -145,33 +175,6 @@ activityPubClientRouter.get('/videos/watch/:id/dislikes',
// ---------------------------------------------------------------------------
activityPubClientRouter.get('/videos/watch/:id/comments',
executeIfActivityPub,
activityPubRateLimiter,
asyncMiddleware(videosCustomGetValidator('only-video-and-blacklist')),
asyncMiddleware(videoCommentsController)
)
activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId/approve-reply',
executeIfActivityPub,
activityPubRateLimiter,
asyncMiddleware(videoCommentGetValidator),
asyncMiddleware(videoCommentApprovedController)
)
activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId/activity',
executeIfActivityPub,
activityPubRateLimiter,
asyncMiddleware(videoCommentGetValidator),
asyncMiddleware(videoCommentController)
)
activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId',
executeIfActivityPub,
activityPubRateLimiter,
asyncMiddleware(videoCommentGetValidator),
asyncMiddleware(videoCommentController)
)
// ---------------------------------------------------------------------------
const { middleware: chaptersCacheRouteMiddleware, instance: chaptersApiCache } = cacheRouteFactory()
InternalEventEmitter.Instance.on('chapters-updated', ({ video }) => {