|
@@ -3,17 +3,22 @@ import * as express from 'express'
|
|
|
import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos'
|
|
|
import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub'
|
|
|
import { CONFIG, ROUTE_CACHE_LIFETIME } from '../../initializers'
|
|
|
-import { buildAnnounceWithVideoAudience } from '../../lib/activitypub/send'
|
|
|
+import { buildAnnounceWithVideoAudience, buildDislikeActivity, buildLikeActivity } from '../../lib/activitypub/send'
|
|
|
import { audiencify, getAudience } from '../../lib/activitypub/audience'
|
|
|
import { buildCreateActivity } from '../../lib/activitypub/send/send-create'
|
|
|
import {
|
|
|
asyncMiddleware,
|
|
|
+ videosShareValidator,
|
|
|
executeIfActivityPub,
|
|
|
localAccountValidator,
|
|
|
localVideoChannelValidator,
|
|
|
videosCustomGetValidator
|
|
|
} from '../../middlewares'
|
|
|
-import { videoCommentGetValidator, videosGetValidator, videosShareValidator } from '../../middlewares/validators'
|
|
|
+import {
|
|
|
+ getAccountVideoRateValidator,
|
|
|
+ videoCommentGetValidator,
|
|
|
+ videosGetValidator
|
|
|
+} from '../../middlewares/validators'
|
|
|
import { AccountModel } from '../../models/account/account'
|
|
|
import { ActorModel } from '../../models/activitypub/actor'
|
|
|
import { ActorFollowModel } from '../../models/activitypub/actor-follow'
|
|
@@ -25,6 +30,7 @@ import { cacheRoute } from '../../middlewares/cache'
|
|
|
import { activityPubResponse } from './utils'
|
|
|
import { AccountVideoRateModel } from '../../models/account/account-video-rate'
|
|
|
import {
|
|
|
+ getRateUrl,
|
|
|
getVideoCommentsActivityPubUrl,
|
|
|
getVideoDislikesActivityPubUrl,
|
|
|
getVideoLikesActivityPubUrl,
|
|
@@ -48,6 +54,14 @@ activityPubClientRouter.get('/accounts?/:name/following',
|
|
|
executeIfActivityPub(asyncMiddleware(localAccountValidator)),
|
|
|
executeIfActivityPub(asyncMiddleware(accountFollowingController))
|
|
|
)
|
|
|
+activityPubClientRouter.get('/accounts?/:name/likes/:videoId',
|
|
|
+ executeIfActivityPub(asyncMiddleware(getAccountVideoRateValidator('like'))),
|
|
|
+ executeIfActivityPub(getAccountVideoRate('like'))
|
|
|
+)
|
|
|
+activityPubClientRouter.get('/accounts?/:name/dislikes/:videoId',
|
|
|
+ executeIfActivityPub(asyncMiddleware(getAccountVideoRateValidator('dislike'))),
|
|
|
+ executeIfActivityPub(getAccountVideoRate('dislike'))
|
|
|
+)
|
|
|
|
|
|
activityPubClientRouter.get('/videos/watch/:id',
|
|
|
executeIfActivityPub(asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS))),
|
|
@@ -62,7 +76,7 @@ activityPubClientRouter.get('/videos/watch/:id/announces',
|
|
|
executeIfActivityPub(asyncMiddleware(videosCustomGetValidator('only-video'))),
|
|
|
executeIfActivityPub(asyncMiddleware(videoAnnouncesController))
|
|
|
)
|
|
|
-activityPubClientRouter.get('/videos/watch/:id/announces/:accountId',
|
|
|
+activityPubClientRouter.get('/videos/watch/:id/announces/:actorId',
|
|
|
executeIfActivityPub(asyncMiddleware(videosShareValidator)),
|
|
|
executeIfActivityPub(asyncMiddleware(videoAnnounceController))
|
|
|
)
|
|
@@ -133,6 +147,20 @@ async function accountFollowingController (req: express.Request, res: express.Re
|
|
|
return activityPubResponse(activityPubContextify(activityPubResult), res)
|
|
|
}
|
|
|
|
|
|
+function getAccountVideoRate (rateType: VideoRateType) {
|
|
|
+ return (req: express.Request, res: express.Response) => {
|
|
|
+ const accountVideoRate: AccountVideoRateModel = res.locals.accountVideoRate
|
|
|
+
|
|
|
+ const byActor = accountVideoRate.Account.Actor
|
|
|
+ const url = getRateUrl(rateType, byActor, accountVideoRate.Video)
|
|
|
+ const APObject = rateType === 'like'
|
|
|
+ ? buildLikeActivity(url, byActor, accountVideoRate.Video)
|
|
|
+ : buildCreateActivity(url, byActor, buildDislikeActivity(url, byActor, accountVideoRate.Video))
|
|
|
+
|
|
|
+ return activityPubResponse(activityPubContextify(APObject), res)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
async function videoController (req: express.Request, res: express.Response, next: express.NextFunction) {
|
|
|
const video: VideoModel = res.locals.video
|
|
|
|
|
@@ -276,7 +304,7 @@ function videoRates (req: express.Request, rateType: VideoRateType, video: Video
|
|
|
const result = await AccountVideoRateModel.listAndCountAccountUrlsByVideoId(rateType, video.id, start, count)
|
|
|
return {
|
|
|
total: result.count,
|
|
|
- data: result.rows.map(r => r.Account.Actor.url)
|
|
|
+ data: result.rows.map(r => r.url)
|
|
|
}
|
|
|
}
|
|
|
return activityPubCollectionPagination(url, handler, req.query.page)
|