}
}
-async function videoController (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function videoController (req: express.Request, res: express.Response) {
const video: VideoModel = res.locals.video
- if (video.isOwned() === false) return res.redirect(video.url)
+ if (video.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(video.url)
// We need captions to render AP object
video.VideoCaptions = await VideoCaptionModel.listVideoCaptions(video.id)
return activityPubResponse(activityPubContextify(videoObject), res)
}
-async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function videoAnnounceController (req: express.Request, res: express.Response) {
const share = res.locals.videoShare as VideoShareModel
- if (share.Actor.isOwned() === false) return res.redirect(share.url)
+ if (share.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(share.url)
const { activity } = await buildAnnounceWithVideoAudience(share.Actor, share, res.locals.video, undefined)
return activityPubResponse(activityPubContextify(activity), res)
}
-async function videoAnnouncesController (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function videoAnnouncesController (req: express.Request, res: express.Response) {
const video: VideoModel = res.locals.video
const handler = async (start: number, count: number) => {
return activityPubResponse(activityPubContextify(json), res)
}
-async function videoLikesController (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function videoLikesController (req: express.Request, res: express.Response) {
const video: VideoModel = res.locals.video
const json = await videoRates(req, 'like', video, getVideoLikesActivityPubUrl(video))
return activityPubResponse(activityPubContextify(json), res)
}
-async function videoDislikesController (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function videoDislikesController (req: express.Request, res: express.Response) {
const video: VideoModel = res.locals.video
const json = await videoRates(req, 'dislike', video, getVideoDislikesActivityPubUrl(video))
return activityPubResponse(activityPubContextify(json), res)
}
-async function videoCommentsController (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function videoCommentsController (req: express.Request, res: express.Response) {
const video: VideoModel = res.locals.video
const handler = async (start: number, count: number) => {
return activityPubResponse(activityPubContextify(json), res)
}
-async function videoChannelController (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function videoChannelController (req: express.Request, res: express.Response) {
const videoChannel: VideoChannelModel = res.locals.videoChannel
return activityPubResponse(activityPubContextify(videoChannel.toActivityPubObject()), res)
}
-async function videoChannelFollowersController (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function videoChannelFollowersController (req: express.Request, res: express.Response) {
const videoChannel: VideoChannelModel = res.locals.videoChannel
const activityPubResult = await actorFollowers(req, videoChannel.Actor)
return activityPubResponse(activityPubContextify(activityPubResult), res)
}
-async function videoChannelFollowingController (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function videoChannelFollowingController (req: express.Request, res: express.Response) {
const videoChannel: VideoChannelModel = res.locals.videoChannel
const activityPubResult = await actorFollowing(req, videoChannel.Actor)
return activityPubResponse(activityPubContextify(activityPubResult), res)
}
-async function videoCommentController (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function videoCommentController (req: express.Request, res: express.Response) {
const videoComment: VideoCommentModel = res.locals.videoComment
- if (videoComment.isOwned() === false) return res.redirect(videoComment.url)
+ if (videoComment.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(videoComment.url)
const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, undefined)
const isPublic = true // Comments are always public
async function videoRedundancyController (req: express.Request, res: express.Response) {
const videoRedundancy: VideoRedundancyModel = res.locals.videoRedundancy
- if (videoRedundancy.isOwned() === false) return res.redirect(videoRedundancy.url)
+ if (videoRedundancy.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(videoRedundancy.url)
const serverActor = await getServerActor()
import * as chai from 'chai'
import 'mocha'
-import { flushTests, killallServers, makeActivityPubGetRequest, runServer, ServerInfo, setAccessTokensToServers } from '../../utils'
+import {
+ doubleFollow,
+ flushAndRunMultipleServers,
+ flushTests,
+ killallServers,
+ makeActivityPubGetRequest,
+ runServer,
+ ServerInfo,
+ setAccessTokensToServers, uploadVideo
+} from '../../utils'
const expect = chai.expect
describe('Test activitypub', function () {
- let server: ServerInfo = null
+ let servers: ServerInfo[] = []
+ let videoUUID: string
before(async function () {
this.timeout(30000)
await flushTests()
- server = await runServer(1)
+ servers = await flushAndRunMultipleServers(2)
- await setAccessTokensToServers([ server ])
+ await setAccessTokensToServers(servers)
+
+ {
+ const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
+ videoUUID = res.body.video.uuid
+ }
+
+ await doubleFollow(servers[0], servers[1])
})
it('Should return the account object', async function () {
- const res = await makeActivityPubGetRequest(server.url, '/accounts/root')
+ const res = await makeActivityPubGetRequest(servers[0].url, '/accounts/root')
const object = res.body
expect(object.type).to.equal('Person')
expect(object.preferredUsername).to.equal('root')
})
+ it('Should return the video object', async function () {
+ const res = await makeActivityPubGetRequest(servers[0].url, '/videos/watch/' + videoUUID)
+ const object = res.body
+
+ expect(object.type).to.equal('Video')
+ expect(object.id).to.equal('http://localhost:9001/videos/watch/' + videoUUID)
+ expect(object.name).to.equal('video')
+ })
+
+ it('Should redirect to the origin video object', async function () {
+ const res = await makeActivityPubGetRequest(servers[1].url, '/videos/watch/' + videoUUID, 302)
+
+ expect(res.header.location).to.equal('http://localhost:9001/videos/watch/' + videoUUID)
+ })
+
after(async function () {
- killallServers([ server ])
+ killallServers(servers)
})
})