2017-11-09 10:51:58 -06:00
|
|
|
// Intercept ActivityPub client requests
|
|
|
|
import * as express from 'express'
|
2018-05-25 09:21:16 -05:00
|
|
|
import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos'
|
2018-01-26 04:44:08 -06:00
|
|
|
import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub'
|
2018-05-25 09:21:16 -05:00
|
|
|
import { CONFIG, ROUTE_CACHE_LIFETIME } from '../../initializers'
|
2019-01-15 07:52:33 -06:00
|
|
|
import { buildAnnounceWithVideoAudience, buildLikeActivity } from '../../lib/activitypub/send'
|
2018-05-25 04:32:36 -05:00
|
|
|
import { audiencify, getAudience } from '../../lib/activitypub/audience'
|
2018-09-11 09:27:07 -05:00
|
|
|
import { buildCreateActivity } from '../../lib/activitypub/send/send-create'
|
2018-09-19 03:16:44 -05:00
|
|
|
import {
|
|
|
|
asyncMiddleware,
|
|
|
|
executeIfActivityPub,
|
|
|
|
localAccountValidator,
|
|
|
|
localVideoChannelValidator,
|
2019-01-15 07:52:33 -06:00
|
|
|
videosCustomGetValidator,
|
|
|
|
videosShareValidator
|
2018-09-19 03:16:44 -05:00
|
|
|
} from '../../middlewares'
|
2019-02-26 03:55:40 -06:00
|
|
|
import { getAccountVideoRateValidator, videoCommentGetValidator } from '../../middlewares/validators'
|
2017-12-12 10:53:50 -06:00
|
|
|
import { AccountModel } from '../../models/account/account'
|
2018-01-15 02:46:46 -06:00
|
|
|
import { ActorModel } from '../../models/activitypub/actor'
|
2017-12-14 10:38:41 -06:00
|
|
|
import { ActorFollowModel } from '../../models/activitypub/actor-follow'
|
2017-12-12 10:53:50 -06:00
|
|
|
import { VideoModel } from '../../models/video/video'
|
|
|
|
import { VideoChannelModel } from '../../models/video/video-channel'
|
2017-12-28 04:16:08 -06:00
|
|
|
import { VideoCommentModel } from '../../models/video/video-comment'
|
2017-12-12 10:53:50 -06:00
|
|
|
import { VideoShareModel } from '../../models/video/video-share'
|
2018-07-24 07:35:11 -05:00
|
|
|
import { cacheRoute } from '../../middlewares/cache'
|
2018-05-25 09:21:16 -05:00
|
|
|
import { activityPubResponse } from './utils'
|
|
|
|
import { AccountVideoRateModel } from '../../models/account/account-video-rate'
|
|
|
|
import {
|
2018-11-14 08:01:28 -06:00
|
|
|
getRateUrl,
|
2018-05-25 09:21:16 -05:00
|
|
|
getVideoCommentsActivityPubUrl,
|
|
|
|
getVideoDislikesActivityPubUrl,
|
|
|
|
getVideoLikesActivityPubUrl,
|
|
|
|
getVideoSharesActivityPubUrl
|
|
|
|
} from '../../lib/activitypub'
|
2018-07-12 12:02:00 -05:00
|
|
|
import { VideoCaptionModel } from '../../models/video/video-caption'
|
2019-01-29 01:37:25 -06:00
|
|
|
import { videoFileRedundancyGetValidator, videoPlaylistRedundancyGetValidator } from '../../middlewares/validators/redundancy'
|
2018-09-11 09:27:07 -05:00
|
|
|
import { getServerActor } from '../../helpers/utils'
|
2018-11-16 04:18:13 -06:00
|
|
|
import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy'
|
2019-01-15 07:52:33 -06:00
|
|
|
import { buildDislikeActivity } from '../../lib/activitypub/send/send-dislike'
|
2019-02-26 03:55:40 -06:00
|
|
|
import { videoPlaylistElementAPGetValidator, videoPlaylistsGetValidator } from '../../middlewares/validators/videos/video-playlists'
|
|
|
|
import { VideoPlaylistModel } from '../../models/video/video-playlist'
|
|
|
|
import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element'
|
|
|
|
import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
|
2017-11-09 10:51:58 -06:00
|
|
|
|
|
|
|
const activityPubClientRouter = express.Router()
|
|
|
|
|
2018-01-08 04:30:48 -06:00
|
|
|
activityPubClientRouter.get('/accounts?/:name',
|
2017-11-27 10:30:46 -06:00
|
|
|
executeIfActivityPub(asyncMiddleware(localAccountValidator)),
|
2017-11-27 07:44:51 -06:00
|
|
|
executeIfActivityPub(accountController)
|
2017-11-09 10:51:58 -06:00
|
|
|
)
|
2018-01-15 02:46:46 -06:00
|
|
|
activityPubClientRouter.get('/accounts?/:name/followers',
|
2017-11-27 10:30:46 -06:00
|
|
|
executeIfActivityPub(asyncMiddleware(localAccountValidator)),
|
2017-11-09 10:51:58 -06:00
|
|
|
executeIfActivityPub(asyncMiddleware(accountFollowersController))
|
|
|
|
)
|
2018-01-15 02:46:46 -06:00
|
|
|
activityPubClientRouter.get('/accounts?/:name/following',
|
2017-11-27 10:30:46 -06:00
|
|
|
executeIfActivityPub(asyncMiddleware(localAccountValidator)),
|
2017-11-09 10:51:58 -06:00
|
|
|
executeIfActivityPub(asyncMiddleware(accountFollowingController))
|
|
|
|
)
|
2019-02-26 03:55:40 -06:00
|
|
|
activityPubClientRouter.get('/accounts?/:name/playlists',
|
|
|
|
executeIfActivityPub(asyncMiddleware(localAccountValidator)),
|
|
|
|
executeIfActivityPub(asyncMiddleware(accountPlaylistsController))
|
|
|
|
)
|
2018-11-14 08:01:28 -06:00
|
|
|
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'))
|
|
|
|
)
|
2017-11-09 10:51:58 -06:00
|
|
|
|
2017-11-16 08:22:39 -06:00
|
|
|
activityPubClientRouter.get('/videos/watch/:id',
|
2018-07-24 07:35:11 -05:00
|
|
|
executeIfActivityPub(asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS))),
|
2019-01-29 01:37:25 -06:00
|
|
|
executeIfActivityPub(asyncMiddleware(videosCustomGetValidator('only-video-with-rights'))),
|
2017-12-28 04:16:08 -06:00
|
|
|
executeIfActivityPub(asyncMiddleware(videoController))
|
2017-11-27 07:44:51 -06:00
|
|
|
)
|
2018-03-22 11:08:02 -05:00
|
|
|
activityPubClientRouter.get('/videos/watch/:id/activity',
|
2019-01-29 01:37:25 -06:00
|
|
|
executeIfActivityPub(asyncMiddleware(videosCustomGetValidator('only-video-with-rights'))),
|
2018-03-22 11:08:02 -05:00
|
|
|
executeIfActivityPub(asyncMiddleware(videoController))
|
|
|
|
)
|
2018-01-29 03:52:19 -06:00
|
|
|
activityPubClientRouter.get('/videos/watch/:id/announces',
|
2018-09-19 03:16:44 -05:00
|
|
|
executeIfActivityPub(asyncMiddleware(videosCustomGetValidator('only-video'))),
|
2018-01-29 03:52:19 -06:00
|
|
|
executeIfActivityPub(asyncMiddleware(videoAnnouncesController))
|
|
|
|
)
|
2018-11-14 08:01:28 -06:00
|
|
|
activityPubClientRouter.get('/videos/watch/:id/announces/:actorId',
|
2017-11-27 07:44:51 -06:00
|
|
|
executeIfActivityPub(asyncMiddleware(videosShareValidator)),
|
|
|
|
executeIfActivityPub(asyncMiddleware(videoAnnounceController))
|
2017-11-16 08:22:39 -06:00
|
|
|
)
|
2018-01-29 03:52:19 -06:00
|
|
|
activityPubClientRouter.get('/videos/watch/:id/likes',
|
2018-09-19 03:16:44 -05:00
|
|
|
executeIfActivityPub(asyncMiddleware(videosCustomGetValidator('only-video'))),
|
2018-01-29 03:52:19 -06:00
|
|
|
executeIfActivityPub(asyncMiddleware(videoLikesController))
|
|
|
|
)
|
|
|
|
activityPubClientRouter.get('/videos/watch/:id/dislikes',
|
2018-09-19 03:16:44 -05:00
|
|
|
executeIfActivityPub(asyncMiddleware(videosCustomGetValidator('only-video'))),
|
2018-01-29 03:52:19 -06:00
|
|
|
executeIfActivityPub(asyncMiddleware(videoDislikesController))
|
|
|
|
)
|
|
|
|
activityPubClientRouter.get('/videos/watch/:id/comments',
|
2018-09-19 03:16:44 -05:00
|
|
|
executeIfActivityPub(asyncMiddleware(videosCustomGetValidator('only-video'))),
|
2018-01-29 03:52:19 -06:00
|
|
|
executeIfActivityPub(asyncMiddleware(videoCommentsController))
|
|
|
|
)
|
2017-12-28 04:16:08 -06:00
|
|
|
activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId',
|
|
|
|
executeIfActivityPub(asyncMiddleware(videoCommentGetValidator)),
|
|
|
|
executeIfActivityPub(asyncMiddleware(videoCommentController))
|
|
|
|
)
|
2018-03-22 11:08:02 -05:00
|
|
|
activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId/activity',
|
|
|
|
executeIfActivityPub(asyncMiddleware(videoCommentGetValidator)),
|
|
|
|
executeIfActivityPub(asyncMiddleware(videoCommentController))
|
|
|
|
)
|
2017-12-28 04:16:08 -06:00
|
|
|
|
2018-08-17 08:45:42 -05:00
|
|
|
activityPubClientRouter.get('/video-channels/:name',
|
|
|
|
executeIfActivityPub(asyncMiddleware(localVideoChannelValidator)),
|
2017-11-16 08:22:39 -06:00
|
|
|
executeIfActivityPub(asyncMiddleware(videoChannelController))
|
|
|
|
)
|
2018-08-17 08:45:42 -05:00
|
|
|
activityPubClientRouter.get('/video-channels/:name/followers',
|
|
|
|
executeIfActivityPub(asyncMiddleware(localVideoChannelValidator)),
|
2018-01-15 02:46:46 -06:00
|
|
|
executeIfActivityPub(asyncMiddleware(videoChannelFollowersController))
|
|
|
|
)
|
2018-08-17 08:45:42 -05:00
|
|
|
activityPubClientRouter.get('/video-channels/:name/following',
|
|
|
|
executeIfActivityPub(asyncMiddleware(localVideoChannelValidator)),
|
2018-01-15 02:46:46 -06:00
|
|
|
executeIfActivityPub(asyncMiddleware(videoChannelFollowingController))
|
|
|
|
)
|
2017-11-16 08:22:39 -06:00
|
|
|
|
2018-09-11 09:27:07 -05:00
|
|
|
activityPubClientRouter.get('/redundancy/videos/:videoId/:resolution([0-9]+)(-:fps([0-9]+))?',
|
2019-01-29 01:37:25 -06:00
|
|
|
executeIfActivityPub(asyncMiddleware(videoFileRedundancyGetValidator)),
|
|
|
|
executeIfActivityPub(asyncMiddleware(videoRedundancyController))
|
|
|
|
)
|
2019-03-05 05:00:31 -06:00
|
|
|
activityPubClientRouter.get('/redundancy/streaming-playlists/:streamingPlaylistType/:videoId',
|
2019-01-29 01:37:25 -06:00
|
|
|
executeIfActivityPub(asyncMiddleware(videoPlaylistRedundancyGetValidator)),
|
2018-09-11 09:27:07 -05:00
|
|
|
executeIfActivityPub(asyncMiddleware(videoRedundancyController))
|
|
|
|
)
|
|
|
|
|
2019-02-26 03:55:40 -06:00
|
|
|
activityPubClientRouter.get('/video-playlists/:playlistId',
|
|
|
|
executeIfActivityPub(asyncMiddleware(videoPlaylistsGetValidator)),
|
|
|
|
executeIfActivityPub(asyncMiddleware(videoPlaylistController))
|
|
|
|
)
|
|
|
|
activityPubClientRouter.get('/video-playlists/:playlistId/:videoId',
|
|
|
|
executeIfActivityPub(asyncMiddleware(videoPlaylistElementAPGetValidator)),
|
|
|
|
executeIfActivityPub(asyncMiddleware(videoPlaylistElementController))
|
|
|
|
)
|
|
|
|
|
2017-11-09 10:51:58 -06:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
activityPubClientRouter
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2019-02-26 03:55:40 -06:00
|
|
|
function accountController (req: express.Request, res: express.Response) {
|
2017-12-12 10:53:50 -06:00
|
|
|
const account: AccountModel = res.locals.account
|
2017-11-09 10:51:58 -06:00
|
|
|
|
2018-03-27 07:28:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(account.toActivityPubObject()), res)
|
2017-11-09 10:51:58 -06:00
|
|
|
}
|
|
|
|
|
2019-02-26 03:55:40 -06:00
|
|
|
async function accountFollowersController (req: express.Request, res: express.Response) {
|
2017-12-12 10:53:50 -06:00
|
|
|
const account: AccountModel = res.locals.account
|
2018-01-15 02:46:46 -06:00
|
|
|
const activityPubResult = await actorFollowers(req, account.Actor)
|
2017-11-09 10:51:58 -06:00
|
|
|
|
2018-03-27 07:28:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(activityPubResult), res)
|
2017-11-09 10:51:58 -06:00
|
|
|
}
|
|
|
|
|
2019-02-26 03:55:40 -06:00
|
|
|
async function accountFollowingController (req: express.Request, res: express.Response) {
|
2017-12-12 10:53:50 -06:00
|
|
|
const account: AccountModel = res.locals.account
|
2018-01-15 02:46:46 -06:00
|
|
|
const activityPubResult = await actorFollowing(req, account.Actor)
|
2017-11-09 10:51:58 -06:00
|
|
|
|
2018-03-27 07:28:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(activityPubResult), res)
|
2017-11-09 10:51:58 -06:00
|
|
|
}
|
2017-11-16 08:22:39 -06:00
|
|
|
|
2019-02-26 03:55:40 -06:00
|
|
|
async function accountPlaylistsController (req: express.Request, res: express.Response) {
|
|
|
|
const account: AccountModel = res.locals.account
|
|
|
|
const activityPubResult = await actorPlaylists(req, account)
|
|
|
|
|
|
|
|
return activityPubResponse(activityPubContextify(activityPubResult), res)
|
|
|
|
}
|
|
|
|
|
2018-11-14 08:01:28 -06:00
|
|
|
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)
|
2019-01-15 07:52:33 -06:00
|
|
|
: buildDislikeActivity(url, byActor, accountVideoRate.Video)
|
2018-11-14 08:01:28 -06:00
|
|
|
|
|
|
|
return activityPubResponse(activityPubContextify(APObject), res)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-30 08:06:06 -06:00
|
|
|
async function videoController (req: express.Request, res: express.Response) {
|
2019-01-29 01:37:25 -06:00
|
|
|
// We need more attributes
|
|
|
|
const video: VideoModel = await VideoModel.loadForGetAPI(res.locals.video.id)
|
2017-11-16 08:22:39 -06:00
|
|
|
|
2018-11-30 08:06:06 -06:00
|
|
|
if (video.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(video.url)
|
2018-11-16 04:18:13 -06:00
|
|
|
|
2018-07-12 12:02:00 -05:00
|
|
|
// We need captions to render AP object
|
|
|
|
video.VideoCaptions = await VideoCaptionModel.listVideoCaptions(video.id)
|
|
|
|
|
2018-06-12 13:04:58 -05:00
|
|
|
const audience = getAudience(video.VideoChannel.Account.Actor, video.privacy === VideoPrivacy.PUBLIC)
|
2018-05-25 09:21:16 -05:00
|
|
|
const videoObject = audiencify(video.toActivityPubObject(), audience)
|
2018-01-10 10:18:12 -06:00
|
|
|
|
2018-03-22 11:08:02 -05:00
|
|
|
if (req.path.endsWith('/activity')) {
|
2018-09-11 09:27:07 -05:00
|
|
|
const data = buildCreateActivity(video.url, video.VideoChannel.Account.Actor, videoObject, audience)
|
2018-03-27 07:28:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(data), res)
|
2018-03-22 11:08:02 -05:00
|
|
|
}
|
|
|
|
|
2018-03-27 07:28:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(videoObject), res)
|
2017-11-16 08:22:39 -06:00
|
|
|
}
|
|
|
|
|
2018-11-30 08:06:06 -06:00
|
|
|
async function videoAnnounceController (req: express.Request, res: express.Response) {
|
2017-12-12 10:53:50 -06:00
|
|
|
const share = res.locals.videoShare as VideoShareModel
|
2018-11-16 04:18:13 -06:00
|
|
|
|
2018-11-30 08:06:06 -06:00
|
|
|
if (share.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(share.url)
|
2018-11-16 04:18:13 -06:00
|
|
|
|
2018-09-11 09:27:07 -05:00
|
|
|
const { activity } = await buildAnnounceWithVideoAudience(share.Actor, share, res.locals.video, undefined)
|
2017-11-27 07:44:51 -06:00
|
|
|
|
2018-09-11 09:27:07 -05:00
|
|
|
return activityPubResponse(activityPubContextify(activity), res)
|
2017-11-27 07:44:51 -06:00
|
|
|
}
|
|
|
|
|
2018-11-30 08:06:06 -06:00
|
|
|
async function videoAnnouncesController (req: express.Request, res: express.Response) {
|
2018-01-29 03:52:19 -06:00
|
|
|
const video: VideoModel = res.locals.video
|
|
|
|
|
2018-05-25 09:21:16 -05:00
|
|
|
const handler = async (start: number, count: number) => {
|
|
|
|
const result = await VideoShareModel.listAndCountByVideoId(video.id, start, count)
|
|
|
|
return {
|
|
|
|
total: result.count,
|
|
|
|
data: result.rows.map(r => r.url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const json = await activityPubCollectionPagination(getVideoSharesActivityPubUrl(video), handler, req.query.page)
|
2018-01-29 03:52:19 -06:00
|
|
|
|
2018-05-25 09:21:16 -05:00
|
|
|
return activityPubResponse(activityPubContextify(json), res)
|
2018-01-29 03:52:19 -06:00
|
|
|
}
|
|
|
|
|
2018-11-30 08:06:06 -06:00
|
|
|
async function videoLikesController (req: express.Request, res: express.Response) {
|
2018-01-29 03:52:19 -06:00
|
|
|
const video: VideoModel = res.locals.video
|
2018-05-25 09:21:16 -05:00
|
|
|
const json = await videoRates(req, 'like', video, getVideoLikesActivityPubUrl(video))
|
2018-01-29 03:52:19 -06:00
|
|
|
|
2018-05-25 09:21:16 -05:00
|
|
|
return activityPubResponse(activityPubContextify(json), res)
|
2018-01-29 03:52:19 -06:00
|
|
|
}
|
|
|
|
|
2018-11-30 08:06:06 -06:00
|
|
|
async function videoDislikesController (req: express.Request, res: express.Response) {
|
2018-01-29 03:52:19 -06:00
|
|
|
const video: VideoModel = res.locals.video
|
2018-05-25 09:21:16 -05:00
|
|
|
const json = await videoRates(req, 'dislike', video, getVideoDislikesActivityPubUrl(video))
|
2018-01-29 03:52:19 -06:00
|
|
|
|
2018-05-25 09:21:16 -05:00
|
|
|
return activityPubResponse(activityPubContextify(json), res)
|
2018-01-29 03:52:19 -06:00
|
|
|
}
|
|
|
|
|
2018-11-30 08:06:06 -06:00
|
|
|
async function videoCommentsController (req: express.Request, res: express.Response) {
|
2018-01-29 03:52:19 -06:00
|
|
|
const video: VideoModel = res.locals.video
|
|
|
|
|
2018-05-25 09:21:16 -05:00
|
|
|
const handler = async (start: number, count: number) => {
|
|
|
|
const result = await VideoCommentModel.listAndCountByVideoId(video.id, start, count)
|
|
|
|
return {
|
|
|
|
total: result.count,
|
|
|
|
data: result.rows.map(r => r.url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const json = await activityPubCollectionPagination(getVideoCommentsActivityPubUrl(video), handler, req.query.page)
|
2018-01-29 03:52:19 -06:00
|
|
|
|
2018-05-25 09:21:16 -05:00
|
|
|
return activityPubResponse(activityPubContextify(json), res)
|
2018-01-29 03:52:19 -06:00
|
|
|
}
|
|
|
|
|
2018-11-30 08:06:06 -06:00
|
|
|
async function videoChannelController (req: express.Request, res: express.Response) {
|
2017-12-12 10:53:50 -06:00
|
|
|
const videoChannel: VideoChannelModel = res.locals.videoChannel
|
2017-11-16 08:22:39 -06:00
|
|
|
|
2018-03-27 07:28:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(videoChannel.toActivityPubObject()), res)
|
2017-11-16 08:22:39 -06:00
|
|
|
}
|
2017-12-28 04:16:08 -06:00
|
|
|
|
2018-11-30 08:06:06 -06:00
|
|
|
async function videoChannelFollowersController (req: express.Request, res: express.Response) {
|
2018-01-15 02:46:46 -06:00
|
|
|
const videoChannel: VideoChannelModel = res.locals.videoChannel
|
|
|
|
const activityPubResult = await actorFollowers(req, videoChannel.Actor)
|
|
|
|
|
2018-03-27 07:28:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(activityPubResult), res)
|
2018-01-15 02:46:46 -06:00
|
|
|
}
|
|
|
|
|
2018-11-30 08:06:06 -06:00
|
|
|
async function videoChannelFollowingController (req: express.Request, res: express.Response) {
|
2018-01-15 02:46:46 -06:00
|
|
|
const videoChannel: VideoChannelModel = res.locals.videoChannel
|
|
|
|
const activityPubResult = await actorFollowing(req, videoChannel.Actor)
|
|
|
|
|
2018-03-27 07:28:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(activityPubResult), res)
|
2018-01-15 02:46:46 -06:00
|
|
|
}
|
|
|
|
|
2018-11-30 08:06:06 -06:00
|
|
|
async function videoCommentController (req: express.Request, res: express.Response) {
|
2017-12-28 04:16:08 -06:00
|
|
|
const videoComment: VideoCommentModel = res.locals.videoComment
|
|
|
|
|
2018-11-30 08:06:06 -06:00
|
|
|
if (videoComment.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(videoComment.url)
|
2018-11-16 04:18:13 -06:00
|
|
|
|
2018-01-05 04:19:25 -06:00
|
|
|
const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, undefined)
|
2018-01-26 04:44:08 -06:00
|
|
|
const isPublic = true // Comments are always public
|
2018-06-12 13:04:58 -05:00
|
|
|
const audience = getAudience(videoComment.Account.Actor, isPublic)
|
2018-01-26 04:44:08 -06:00
|
|
|
|
|
|
|
const videoCommentObject = audiencify(videoComment.toActivityPubObject(threadParentComments), audience)
|
|
|
|
|
2018-03-22 11:08:02 -05:00
|
|
|
if (req.path.endsWith('/activity')) {
|
2018-09-11 09:27:07 -05:00
|
|
|
const data = buildCreateActivity(videoComment.url, videoComment.Account.Actor, videoCommentObject, audience)
|
2018-03-27 07:28:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(data), res)
|
2018-03-22 11:08:02 -05:00
|
|
|
}
|
|
|
|
|
2018-03-27 07:28:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(videoCommentObject), res)
|
2017-12-28 04:16:08 -06:00
|
|
|
}
|
2018-01-15 02:46:46 -06:00
|
|
|
|
2018-09-11 09:27:07 -05:00
|
|
|
async function videoRedundancyController (req: express.Request, res: express.Response) {
|
2018-11-16 04:18:13 -06:00
|
|
|
const videoRedundancy: VideoRedundancyModel = res.locals.videoRedundancy
|
2018-11-30 08:06:06 -06:00
|
|
|
if (videoRedundancy.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(videoRedundancy.url)
|
2018-11-16 04:18:13 -06:00
|
|
|
|
2018-09-11 09:27:07 -05:00
|
|
|
const serverActor = await getServerActor()
|
|
|
|
|
|
|
|
const audience = getAudience(serverActor)
|
|
|
|
const object = audiencify(videoRedundancy.toActivityPubObject(), audience)
|
|
|
|
|
|
|
|
if (req.path.endsWith('/activity')) {
|
|
|
|
const data = buildCreateActivity(videoRedundancy.url, serverActor, object, audience)
|
|
|
|
return activityPubResponse(activityPubContextify(data), res)
|
|
|
|
}
|
|
|
|
|
|
|
|
return activityPubResponse(activityPubContextify(object), res)
|
|
|
|
}
|
|
|
|
|
2019-02-26 03:55:40 -06:00
|
|
|
async function videoPlaylistController (req: express.Request, res: express.Response) {
|
|
|
|
const playlist: VideoPlaylistModel = res.locals.videoPlaylist
|
|
|
|
|
2019-03-05 03:58:44 -06:00
|
|
|
// We need more attributes
|
|
|
|
playlist.OwnerAccount = await AccountModel.load(playlist.ownerAccountId)
|
|
|
|
|
|
|
|
const json = await playlist.toActivityPubObject(req.query.page, null)
|
2019-02-26 03:55:40 -06:00
|
|
|
const audience = getAudience(playlist.OwnerAccount.Actor, playlist.privacy === VideoPlaylistPrivacy.PUBLIC)
|
|
|
|
const object = audiencify(json, audience)
|
|
|
|
|
|
|
|
return activityPubResponse(activityPubContextify(object), res)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function videoPlaylistElementController (req: express.Request, res: express.Response) {
|
|
|
|
const videoPlaylistElement: VideoPlaylistElementModel = res.locals.videoPlaylistElement
|
|
|
|
|
|
|
|
const json = videoPlaylistElement.toActivityPubObject()
|
|
|
|
return activityPubResponse(activityPubContextify(json), res)
|
|
|
|
}
|
|
|
|
|
2018-01-15 02:46:46 -06:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
async function actorFollowing (req: express.Request, actor: ActorModel) {
|
2018-05-25 09:21:16 -05:00
|
|
|
const handler = (start: number, count: number) => {
|
|
|
|
return ActorFollowModel.listAcceptedFollowingUrlsForApi([ actor.id ], undefined, start, count)
|
|
|
|
}
|
2018-01-15 02:46:46 -06:00
|
|
|
|
2018-11-16 08:38:09 -06:00
|
|
|
return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.path, handler, req.query.page)
|
2018-01-15 02:46:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
async function actorFollowers (req: express.Request, actor: ActorModel) {
|
2018-05-25 09:21:16 -05:00
|
|
|
const handler = (start: number, count: number) => {
|
2019-02-26 03:55:40 -06:00
|
|
|
return ActorFollowModel.listAcceptedFollowerUrlsForAP([ actor.id ], undefined, start, count)
|
|
|
|
}
|
|
|
|
|
|
|
|
return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.path, handler, req.query.page)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function actorPlaylists (req: express.Request, account: AccountModel) {
|
|
|
|
const handler = (start: number, count: number) => {
|
2019-03-13 10:03:03 -05:00
|
|
|
return VideoPlaylistModel.listPublicUrlsOfForAP(account.id, start, count)
|
2018-05-25 09:21:16 -05:00
|
|
|
}
|
2018-01-15 02:46:46 -06:00
|
|
|
|
2018-11-16 08:38:09 -06:00
|
|
|
return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.path, handler, req.query.page)
|
2018-01-15 02:46:46 -06:00
|
|
|
}
|
2018-03-27 07:28:33 -05:00
|
|
|
|
2018-05-25 09:21:16 -05:00
|
|
|
function videoRates (req: express.Request, rateType: VideoRateType, video: VideoModel, url: string) {
|
|
|
|
const handler = async (start: number, count: number) => {
|
|
|
|
const result = await AccountVideoRateModel.listAndCountAccountUrlsByVideoId(rateType, video.id, start, count)
|
|
|
|
return {
|
|
|
|
total: result.count,
|
2018-11-14 08:01:28 -06:00
|
|
|
data: result.rows.map(r => r.url)
|
2018-05-25 09:21:16 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return activityPubCollectionPagination(url, handler, req.query.page)
|
2018-03-27 07:28:33 -05:00
|
|
|
}
|