2021-08-27 07:32:44 -05:00
|
|
|
import cors from 'cors'
|
|
|
|
import express from 'express'
|
2022-03-23 08:24:50 -05:00
|
|
|
import { activityPubCollectionPagination } from '@server/lib/activitypub/collection'
|
|
|
|
import { activityPubContextify } from '@server/lib/activitypub/context'
|
2020-11-06 03:57:40 -06:00
|
|
|
import { getServerActor } from '@server/models/application/application'
|
2020-11-20 04:34:49 -06:00
|
|
|
import { MAccountId, MActorId, MChannelId, MVideoId } from '@server/types/models'
|
2023-06-05 08:51:16 -05:00
|
|
|
import { VideoCommentObject } from '@shared/models'
|
2018-05-25 09:21:16 -05:00
|
|
|
import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos'
|
2020-11-06 03:57:40 -06:00
|
|
|
import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
|
2019-04-11 07:26:41 -05:00
|
|
|
import { ROUTE_CACHE_LIFETIME, WEBSERVER } from '../../initializers/constants'
|
2018-05-25 04:32:36 -05:00
|
|
|
import { audiencify, getAudience } from '../../lib/activitypub/audience'
|
2020-11-06 03:57:40 -06:00
|
|
|
import { buildAnnounceWithVideoAudience, buildLikeActivity } from '../../lib/activitypub/send'
|
2018-09-11 09:27:07 -05:00
|
|
|
import { buildCreateActivity } from '../../lib/activitypub/send/send-create'
|
2020-11-06 03:57:40 -06:00
|
|
|
import { buildDislikeActivity } from '../../lib/activitypub/send/send-dislike'
|
|
|
|
import {
|
2020-11-20 04:21:08 -06:00
|
|
|
getLocalVideoCommentsActivityPubUrl,
|
|
|
|
getLocalVideoDislikesActivityPubUrl,
|
|
|
|
getLocalVideoLikesActivityPubUrl,
|
|
|
|
getLocalVideoSharesActivityPubUrl
|
2020-11-06 03:57:40 -06:00
|
|
|
} from '../../lib/activitypub/url'
|
2018-09-19 03:16:44 -05:00
|
|
|
import {
|
|
|
|
asyncMiddleware,
|
2022-02-28 01:34:43 -06:00
|
|
|
ensureIsLocalChannel,
|
2018-09-19 03:16:44 -05:00
|
|
|
executeIfActivityPub,
|
|
|
|
localAccountValidator,
|
2021-12-13 08:29:13 -06:00
|
|
|
videoChannelsNameWithHostValidator,
|
2019-01-15 07:52:33 -06:00
|
|
|
videosCustomGetValidator,
|
|
|
|
videosShareValidator
|
2018-09-19 03:16:44 -05:00
|
|
|
} from '../../middlewares'
|
2021-07-22 04:15:17 -05:00
|
|
|
import { cacheRoute } from '../../middlewares/cache/cache'
|
2022-03-24 07:36:47 -05:00
|
|
|
import { getAccountVideoRateValidatorFactory, getVideoLocalViewerValidator, videoCommentGetValidator } from '../../middlewares/validators'
|
2020-11-06 03:57:40 -06:00
|
|
|
import { videoFileRedundancyGetValidator, videoPlaylistRedundancyGetValidator } from '../../middlewares/validators/redundancy'
|
|
|
|
import { videoPlaylistElementAPGetValidator, videoPlaylistsGetValidator } from '../../middlewares/validators/videos/video-playlists'
|
2017-12-12 10:53:50 -06:00
|
|
|
import { AccountModel } from '../../models/account/account'
|
2020-11-06 03:57:40 -06:00
|
|
|
import { AccountVideoRateModel } from '../../models/account/account-video-rate'
|
2021-05-11 04:15:29 -05:00
|
|
|
import { ActorFollowModel } from '../../models/actor/actor-follow'
|
2017-12-28 04:16:08 -06:00
|
|
|
import { VideoCommentModel } from '../../models/video/video-comment'
|
2020-11-06 03:57:40 -06:00
|
|
|
import { VideoPlaylistModel } from '../../models/video/video-playlist'
|
2017-12-12 10:53:50 -06:00
|
|
|
import { VideoShareModel } from '../../models/video/video-share'
|
2018-05-25 09:21:16 -05:00
|
|
|
import { activityPubResponse } from './utils'
|
2017-11-09 10:51:58 -06:00
|
|
|
|
|
|
|
const activityPubClientRouter = express.Router()
|
2020-04-10 08:52:01 -05:00
|
|
|
activityPubClientRouter.use(cors())
|
2017-11-09 10:51:58 -06:00
|
|
|
|
2020-02-04 09:14:33 -06:00
|
|
|
// Intercept ActivityPub client requests
|
|
|
|
|
2021-01-20 04:48:59 -06:00
|
|
|
activityPubClientRouter.get(
|
2021-06-11 07:50:01 -05:00
|
|
|
[ '/accounts?/:name', '/accounts?/:name/video-channels', '/a/:name', '/a/:name/video-channels' ],
|
2019-03-19 03:34:29 -05:00
|
|
|
executeIfActivityPub,
|
|
|
|
asyncMiddleware(localAccountValidator),
|
2023-03-10 05:01:21 -06:00
|
|
|
asyncMiddleware(accountController)
|
2017-11-09 10:51:58 -06:00
|
|
|
)
|
2018-01-15 02:46:46 -06:00
|
|
|
activityPubClientRouter.get('/accounts?/:name/followers',
|
2019-03-19 03:34:29 -05:00
|
|
|
executeIfActivityPub,
|
|
|
|
asyncMiddleware(localAccountValidator),
|
|
|
|
asyncMiddleware(accountFollowersController)
|
2017-11-09 10:51:58 -06:00
|
|
|
)
|
2018-01-15 02:46:46 -06:00
|
|
|
activityPubClientRouter.get('/accounts?/:name/following',
|
2019-03-19 03:34:29 -05:00
|
|
|
executeIfActivityPub,
|
|
|
|
asyncMiddleware(localAccountValidator),
|
|
|
|
asyncMiddleware(accountFollowingController)
|
2017-11-09 10:51:58 -06:00
|
|
|
)
|
2019-02-26 03:55:40 -06:00
|
|
|
activityPubClientRouter.get('/accounts?/:name/playlists',
|
2019-03-19 03:34:29 -05:00
|
|
|
executeIfActivityPub,
|
|
|
|
asyncMiddleware(localAccountValidator),
|
|
|
|
asyncMiddleware(accountPlaylistsController)
|
2019-02-26 03:55:40 -06:00
|
|
|
)
|
2018-11-14 08:01:28 -06:00
|
|
|
activityPubClientRouter.get('/accounts?/:name/likes/:videoId',
|
2019-03-19 03:34:29 -05:00
|
|
|
executeIfActivityPub,
|
2022-03-18 05:17:35 -05:00
|
|
|
cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS),
|
2020-01-29 08:17:42 -06:00
|
|
|
asyncMiddleware(getAccountVideoRateValidatorFactory('like')),
|
2023-03-10 05:01:21 -06:00
|
|
|
asyncMiddleware(getAccountVideoRateFactory('like'))
|
2018-11-14 08:01:28 -06:00
|
|
|
)
|
|
|
|
activityPubClientRouter.get('/accounts?/:name/dislikes/:videoId',
|
2019-03-19 03:34:29 -05:00
|
|
|
executeIfActivityPub,
|
2022-03-18 05:17:35 -05:00
|
|
|
cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS),
|
2020-01-29 08:17:42 -06:00
|
|
|
asyncMiddleware(getAccountVideoRateValidatorFactory('dislike')),
|
2023-03-10 05:01:21 -06:00
|
|
|
asyncMiddleware(getAccountVideoRateFactory('dislike'))
|
2018-11-14 08:01:28 -06:00
|
|
|
)
|
2017-11-09 10:51:58 -06:00
|
|
|
|
2021-06-11 07:50:01 -05:00
|
|
|
activityPubClientRouter.get(
|
|
|
|
[ '/videos/watch/:id', '/w/:id' ],
|
2019-03-19 03:34:29 -05:00
|
|
|
executeIfActivityPub,
|
2021-07-22 04:15:17 -05:00
|
|
|
cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS),
|
2021-06-11 07:09:33 -05:00
|
|
|
asyncMiddleware(videosCustomGetValidator('all')),
|
2019-03-19 03:34:29 -05:00
|
|
|
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-03-19 03:34:29 -05:00
|
|
|
executeIfActivityPub,
|
2021-06-11 07:09:33 -05:00
|
|
|
asyncMiddleware(videosCustomGetValidator('all')),
|
2019-03-19 03:34:29 -05:00
|
|
|
asyncMiddleware(videoController)
|
2018-03-22 11:08:02 -05:00
|
|
|
)
|
2018-01-29 03:52:19 -06:00
|
|
|
activityPubClientRouter.get('/videos/watch/:id/announces',
|
2019-03-19 03:34:29 -05:00
|
|
|
executeIfActivityPub,
|
2020-02-04 08:00:47 -06:00
|
|
|
asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')),
|
2019-03-19 03:34:29 -05:00
|
|
|
asyncMiddleware(videoAnnouncesController)
|
2018-01-29 03:52:19 -06:00
|
|
|
)
|
2018-11-14 08:01:28 -06:00
|
|
|
activityPubClientRouter.get('/videos/watch/:id/announces/:actorId',
|
2019-03-19 03:34:29 -05:00
|
|
|
executeIfActivityPub,
|
|
|
|
asyncMiddleware(videosShareValidator),
|
|
|
|
asyncMiddleware(videoAnnounceController)
|
2017-11-16 08:22:39 -06:00
|
|
|
)
|
2018-01-29 03:52:19 -06:00
|
|
|
activityPubClientRouter.get('/videos/watch/:id/likes',
|
2019-03-19 03:34:29 -05:00
|
|
|
executeIfActivityPub,
|
2020-02-04 08:00:47 -06:00
|
|
|
asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')),
|
2019-03-19 03:34:29 -05:00
|
|
|
asyncMiddleware(videoLikesController)
|
2018-01-29 03:52:19 -06:00
|
|
|
)
|
|
|
|
activityPubClientRouter.get('/videos/watch/:id/dislikes',
|
2019-03-19 03:34:29 -05:00
|
|
|
executeIfActivityPub,
|
2020-02-04 08:00:47 -06:00
|
|
|
asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')),
|
2019-03-19 03:34:29 -05:00
|
|
|
asyncMiddleware(videoDislikesController)
|
2018-01-29 03:52:19 -06:00
|
|
|
)
|
|
|
|
activityPubClientRouter.get('/videos/watch/:id/comments',
|
2019-03-19 03:34:29 -05:00
|
|
|
executeIfActivityPub,
|
2020-02-04 08:00:47 -06:00
|
|
|
asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')),
|
2019-03-19 03:34:29 -05:00
|
|
|
asyncMiddleware(videoCommentsController)
|
2018-01-29 03:52:19 -06:00
|
|
|
)
|
2017-12-28 04:16:08 -06:00
|
|
|
activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId',
|
2019-03-19 03:34:29 -05:00
|
|
|
executeIfActivityPub,
|
|
|
|
asyncMiddleware(videoCommentGetValidator),
|
|
|
|
asyncMiddleware(videoCommentController)
|
2017-12-28 04:16:08 -06:00
|
|
|
)
|
2018-03-22 11:08:02 -05:00
|
|
|
activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId/activity',
|
2019-03-19 03:34:29 -05:00
|
|
|
executeIfActivityPub,
|
|
|
|
asyncMiddleware(videoCommentGetValidator),
|
|
|
|
asyncMiddleware(videoCommentController)
|
2018-03-22 11:08:02 -05:00
|
|
|
)
|
2017-12-28 04:16:08 -06:00
|
|
|
|
2021-01-20 04:48:59 -06:00
|
|
|
activityPubClientRouter.get(
|
2021-12-13 08:29:13 -06:00
|
|
|
[ '/video-channels/:nameWithHost', '/video-channels/:nameWithHost/videos', '/c/:nameWithHost', '/c/:nameWithHost/videos' ],
|
2019-03-19 03:34:29 -05:00
|
|
|
executeIfActivityPub,
|
2021-12-13 08:29:13 -06:00
|
|
|
asyncMiddleware(videoChannelsNameWithHostValidator),
|
|
|
|
ensureIsLocalChannel,
|
2023-03-10 05:01:21 -06:00
|
|
|
asyncMiddleware(videoChannelController)
|
2017-11-16 08:22:39 -06:00
|
|
|
)
|
2021-12-13 08:29:13 -06:00
|
|
|
activityPubClientRouter.get('/video-channels/:nameWithHost/followers',
|
2019-03-19 03:34:29 -05:00
|
|
|
executeIfActivityPub,
|
2021-12-13 08:29:13 -06:00
|
|
|
asyncMiddleware(videoChannelsNameWithHostValidator),
|
|
|
|
ensureIsLocalChannel,
|
2019-03-19 03:34:29 -05:00
|
|
|
asyncMiddleware(videoChannelFollowersController)
|
2018-01-15 02:46:46 -06:00
|
|
|
)
|
2021-12-13 08:29:13 -06:00
|
|
|
activityPubClientRouter.get('/video-channels/:nameWithHost/following',
|
2019-03-19 03:34:29 -05:00
|
|
|
executeIfActivityPub,
|
2021-12-13 08:29:13 -06:00
|
|
|
asyncMiddleware(videoChannelsNameWithHostValidator),
|
|
|
|
ensureIsLocalChannel,
|
2019-03-19 03:34:29 -05:00
|
|
|
asyncMiddleware(videoChannelFollowingController)
|
2018-01-15 02:46:46 -06:00
|
|
|
)
|
2021-12-13 08:29:13 -06:00
|
|
|
activityPubClientRouter.get('/video-channels/:nameWithHost/playlists',
|
2020-05-13 07:49:11 -05:00
|
|
|
executeIfActivityPub,
|
2021-12-13 08:29:13 -06:00
|
|
|
asyncMiddleware(videoChannelsNameWithHostValidator),
|
|
|
|
ensureIsLocalChannel,
|
2020-05-13 07:49:11 -05:00
|
|
|
asyncMiddleware(videoChannelPlaylistsController)
|
|
|
|
)
|
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-03-19 03:34:29 -05:00
|
|
|
executeIfActivityPub,
|
|
|
|
asyncMiddleware(videoFileRedundancyGetValidator),
|
|
|
|
asyncMiddleware(videoRedundancyController)
|
2019-01-29 01:37:25 -06:00
|
|
|
)
|
2019-03-05 05:00:31 -06:00
|
|
|
activityPubClientRouter.get('/redundancy/streaming-playlists/:streamingPlaylistType/:videoId',
|
2019-03-19 03:34:29 -05:00
|
|
|
executeIfActivityPub,
|
|
|
|
asyncMiddleware(videoPlaylistRedundancyGetValidator),
|
|
|
|
asyncMiddleware(videoRedundancyController)
|
2018-09-11 09:27:07 -05:00
|
|
|
)
|
|
|
|
|
2021-06-17 09:02:38 -05:00
|
|
|
activityPubClientRouter.get(
|
|
|
|
[ '/video-playlists/:playlistId', '/videos/watch/playlist/:playlistId', '/w/p/:playlistId' ],
|
2019-03-19 03:34:29 -05:00
|
|
|
executeIfActivityPub,
|
2019-08-15 04:53:26 -05:00
|
|
|
asyncMiddleware(videoPlaylistsGetValidator('all')),
|
2019-03-19 03:34:29 -05:00
|
|
|
asyncMiddleware(videoPlaylistController)
|
2019-02-26 03:55:40 -06:00
|
|
|
)
|
2020-08-17 09:39:32 -05:00
|
|
|
activityPubClientRouter.get('/video-playlists/:playlistId/videos/:playlistElementId',
|
2019-03-19 03:34:29 -05:00
|
|
|
executeIfActivityPub,
|
|
|
|
asyncMiddleware(videoPlaylistElementAPGetValidator),
|
2023-03-10 05:01:21 -06:00
|
|
|
asyncMiddleware(videoPlaylistElementController)
|
2019-02-26 03:55:40 -06:00
|
|
|
)
|
|
|
|
|
2022-03-24 07:36:47 -05:00
|
|
|
activityPubClientRouter.get('/videos/local-viewer/:localViewerId',
|
|
|
|
executeIfActivityPub,
|
|
|
|
asyncMiddleware(getVideoLocalViewerValidator),
|
2023-03-10 05:01:21 -06:00
|
|
|
asyncMiddleware(getVideoLocalViewerController)
|
2022-03-24 07:36:47 -05:00
|
|
|
)
|
|
|
|
|
2017-11-09 10:51:58 -06:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
activityPubClientRouter
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2023-03-10 05:01:21 -06:00
|
|
|
async function accountController (req: express.Request, res: express.Response) {
|
2019-03-19 04:35:15 -05:00
|
|
|
const account = res.locals.account
|
2017-11-09 10:51:58 -06:00
|
|
|
|
2023-03-10 05:01:21 -06:00
|
|
|
return activityPubResponse(activityPubContextify(await account.toActivityPubObject(), 'Actor'), 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) {
|
2019-03-19 04:35:15 -05:00
|
|
|
const account = 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
|
|
|
|
2022-03-23 10:14:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(activityPubResult, 'Collection'), 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) {
|
2019-03-19 04:35:15 -05:00
|
|
|
const account = 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
|
|
|
|
2022-03-23 10:14:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(activityPubResult, 'Collection'), 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) {
|
2019-03-19 04:35:15 -05:00
|
|
|
const account = res.locals.account
|
2020-05-13 07:49:11 -05:00
|
|
|
const activityPubResult = await actorPlaylists(req, { account })
|
|
|
|
|
2022-03-23 10:14:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(activityPubResult, 'Collection'), res)
|
2020-05-13 07:49:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
async function videoChannelPlaylistsController (req: express.Request, res: express.Response) {
|
|
|
|
const channel = res.locals.videoChannel
|
|
|
|
const activityPubResult = await actorPlaylists(req, { channel })
|
2019-02-26 03:55:40 -06:00
|
|
|
|
2022-03-23 10:14:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(activityPubResult, 'Collection'), res)
|
2019-02-26 03:55:40 -06:00
|
|
|
}
|
|
|
|
|
2020-01-29 08:17:42 -06:00
|
|
|
function getAccountVideoRateFactory (rateType: VideoRateType) {
|
2018-11-14 08:01:28 -06:00
|
|
|
return (req: express.Request, res: express.Response) => {
|
2019-03-19 04:35:15 -05:00
|
|
|
const accountVideoRate = res.locals.accountVideoRate
|
2018-11-14 08:01:28 -06:00
|
|
|
|
|
|
|
const byActor = accountVideoRate.Account.Actor
|
|
|
|
const APObject = rateType === 'like'
|
2020-11-20 04:21:08 -06:00
|
|
|
? buildLikeActivity(accountVideoRate.url, byActor, accountVideoRate.Video)
|
|
|
|
: buildDislikeActivity(accountVideoRate.url, byActor, accountVideoRate.Video)
|
2018-11-14 08:01:28 -06:00
|
|
|
|
2022-03-23 10:14:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(APObject, 'Rate'), res)
|
2018-11-14 08:01:28 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-30 08:06:06 -06:00
|
|
|
async function videoController (req: express.Request, res: express.Response) {
|
2021-06-11 07:09:33 -05:00
|
|
|
const video = res.locals.videoAll
|
2017-11-16 08:22:39 -06:00
|
|
|
|
2020-11-20 04:21:08 -06:00
|
|
|
if (redirectIfNotOwned(video.url, res)) return
|
2018-11-16 04:18:13 -06:00
|
|
|
|
2018-07-12 12:02:00 -05:00
|
|
|
// We need captions to render AP object
|
2023-06-01 07:51:16 -05:00
|
|
|
const videoAP = await video.lightAPToFullAP(undefined)
|
2018-07-12 12:02:00 -05:00
|
|
|
|
2023-06-01 07:51:16 -05:00
|
|
|
const audience = getAudience(videoAP.VideoChannel.Account.Actor, videoAP.privacy === VideoPrivacy.PUBLIC)
|
|
|
|
const videoObject = audiencify(await videoAP.toActivityPubObject(), audience)
|
2018-01-10 10:18:12 -06:00
|
|
|
|
2018-03-22 11:08:02 -05:00
|
|
|
if (req.path.endsWith('/activity')) {
|
2023-06-01 07:51:16 -05:00
|
|
|
const data = buildCreateActivity(videoAP.url, video.VideoChannel.Account.Actor, videoObject, audience)
|
2022-03-23 10:14:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(data, 'Video'), res)
|
2018-03-22 11:08:02 -05:00
|
|
|
}
|
|
|
|
|
2022-03-23 10:14:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(videoObject, 'Video'), 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) {
|
2019-03-19 04:35:15 -05:00
|
|
|
const share = res.locals.videoShare
|
2018-11-16 04:18:13 -06:00
|
|
|
|
2020-11-20 04:21:08 -06:00
|
|
|
if (redirectIfNotOwned(share.url, res)) return
|
2018-11-16 04:18:13 -06:00
|
|
|
|
2019-08-15 04:53:26 -05:00
|
|
|
const { activity } = await buildAnnounceWithVideoAudience(share.Actor, share, res.locals.videoAll, undefined)
|
2017-11-27 07:44:51 -06:00
|
|
|
|
2020-02-03 04:12:29 -06:00
|
|
|
return activityPubResponse(activityPubContextify(activity, 'Announce'), 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) {
|
2020-02-04 08:00:47 -06:00
|
|
|
const video = res.locals.onlyImmutableVideo
|
2018-01-29 03:52:19 -06:00
|
|
|
|
2020-11-20 04:21:08 -06:00
|
|
|
if (redirectIfNotOwned(video.url, res)) return
|
|
|
|
|
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 {
|
2022-02-28 01:34:43 -06:00
|
|
|
total: result.total,
|
|
|
|
data: result.data.map(r => r.url)
|
2018-05-25 09:21:16 -05:00
|
|
|
}
|
|
|
|
}
|
2020-11-20 04:21:08 -06:00
|
|
|
const json = await activityPubCollectionPagination(getLocalVideoSharesActivityPubUrl(video), handler, req.query.page)
|
2018-01-29 03:52:19 -06:00
|
|
|
|
2022-03-23 10:14:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(json, 'Collection'), 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) {
|
2020-02-04 08:00:47 -06:00
|
|
|
const video = res.locals.onlyImmutableVideo
|
2020-11-20 04:21:08 -06:00
|
|
|
|
|
|
|
if (redirectIfNotOwned(video.url, res)) return
|
|
|
|
|
|
|
|
const json = await videoRates(req, 'like', video, getLocalVideoLikesActivityPubUrl(video))
|
2018-01-29 03:52:19 -06:00
|
|
|
|
2022-03-23 10:14:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(json, 'Collection'), 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) {
|
2020-02-04 08:00:47 -06:00
|
|
|
const video = res.locals.onlyImmutableVideo
|
2020-11-20 04:21:08 -06:00
|
|
|
|
|
|
|
if (redirectIfNotOwned(video.url, res)) return
|
|
|
|
|
|
|
|
const json = await videoRates(req, 'dislike', video, getLocalVideoDislikesActivityPubUrl(video))
|
2018-01-29 03:52:19 -06:00
|
|
|
|
2022-03-23 10:14:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(json, 'Collection'), 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) {
|
2020-02-04 08:00:47 -06:00
|
|
|
const video = res.locals.onlyImmutableVideo
|
2018-01-29 03:52:19 -06:00
|
|
|
|
2020-11-20 04:21:08 -06:00
|
|
|
if (redirectIfNotOwned(video.url, res)) return
|
|
|
|
|
2018-05-25 09:21:16 -05:00
|
|
|
const handler = async (start: number, count: number) => {
|
2023-01-05 08:31:51 -06:00
|
|
|
const result = await VideoCommentModel.listAndCountByVideoForAP({ video, start, count })
|
2022-02-28 01:34:43 -06:00
|
|
|
|
2018-05-25 09:21:16 -05:00
|
|
|
return {
|
2022-02-28 01:34:43 -06:00
|
|
|
total: result.total,
|
|
|
|
data: result.data.map(r => r.url)
|
2018-05-25 09:21:16 -05:00
|
|
|
}
|
|
|
|
}
|
2020-11-20 04:21:08 -06:00
|
|
|
const json = await activityPubCollectionPagination(getLocalVideoCommentsActivityPubUrl(video), handler, req.query.page)
|
2018-01-29 03:52:19 -06:00
|
|
|
|
2022-03-23 10:14:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(json, 'Collection'), res)
|
2018-01-29 03:52:19 -06:00
|
|
|
}
|
|
|
|
|
2023-03-10 05:01:21 -06:00
|
|
|
async function videoChannelController (req: express.Request, res: express.Response) {
|
2019-03-19 04:35:15 -05:00
|
|
|
const videoChannel = res.locals.videoChannel
|
2017-11-16 08:22:39 -06:00
|
|
|
|
2023-03-10 05:01:21 -06:00
|
|
|
return activityPubResponse(activityPubContextify(await videoChannel.toActivityPubObject(), 'Actor'), 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) {
|
2019-03-19 04:35:15 -05:00
|
|
|
const videoChannel = res.locals.videoChannel
|
2018-01-15 02:46:46 -06:00
|
|
|
const activityPubResult = await actorFollowers(req, videoChannel.Actor)
|
|
|
|
|
2022-03-23 10:14:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(activityPubResult, 'Collection'), 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) {
|
2019-03-19 04:35:15 -05:00
|
|
|
const videoChannel = res.locals.videoChannel
|
2018-01-15 02:46:46 -06:00
|
|
|
const activityPubResult = await actorFollowing(req, videoChannel.Actor)
|
|
|
|
|
2022-03-23 10:14:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(activityPubResult, 'Collection'), 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) {
|
2019-08-15 04:53:26 -05:00
|
|
|
const videoComment = res.locals.videoCommentFull
|
2017-12-28 04:16:08 -06:00
|
|
|
|
2020-11-20 04:21:08 -06:00
|
|
|
if (redirectIfNotOwned(videoComment.url, res)) return
|
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
|
2019-11-15 12:05:08 -06:00
|
|
|
let videoCommentObject = videoComment.toActivityPubObject(threadParentComments)
|
2018-01-26 04:44:08 -06:00
|
|
|
|
2019-11-15 12:05:08 -06:00
|
|
|
if (videoComment.Account) {
|
|
|
|
const audience = getAudience(videoComment.Account.Actor, isPublic)
|
|
|
|
videoCommentObject = audiencify(videoCommentObject, audience)
|
2018-01-26 04:44:08 -06:00
|
|
|
|
2019-11-15 12:05:08 -06:00
|
|
|
if (req.path.endsWith('/activity')) {
|
2023-06-05 08:51:16 -05:00
|
|
|
const data = buildCreateActivity(videoComment.url, videoComment.Account.Actor, videoCommentObject as VideoCommentObject, audience)
|
2022-03-23 10:14:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(data, 'Comment'), res)
|
2019-11-15 12:05:08 -06:00
|
|
|
}
|
2018-03-22 11:08:02 -05:00
|
|
|
}
|
|
|
|
|
2022-03-23 10:14:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(videoCommentObject, 'Comment'), 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) {
|
2019-03-19 04:35:15 -05:00
|
|
|
const videoRedundancy = res.locals.videoRedundancy
|
2020-11-20 04:21:08 -06:00
|
|
|
|
|
|
|
if (redirectIfNotOwned(videoRedundancy.url, res)) return
|
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)
|
2020-02-04 09:34:46 -06:00
|
|
|
return activityPubResponse(activityPubContextify(data, 'CacheFile'), res)
|
2018-09-11 09:27:07 -05:00
|
|
|
}
|
|
|
|
|
2020-02-04 09:34:46 -06:00
|
|
|
return activityPubResponse(activityPubContextify(object, 'CacheFile'), res)
|
2018-09-11 09:27:07 -05:00
|
|
|
}
|
|
|
|
|
2019-02-26 03:55:40 -06:00
|
|
|
async function videoPlaylistController (req: express.Request, res: express.Response) {
|
2019-08-15 04:53:26 -05:00
|
|
|
const playlist = res.locals.videoPlaylistFull
|
2019-02-26 03:55:40 -06:00
|
|
|
|
2020-11-20 04:21:08 -06:00
|
|
|
if (redirectIfNotOwned(playlist.url, res)) return
|
|
|
|
|
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)
|
|
|
|
|
2022-03-23 10:14:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(object, 'Playlist'), res)
|
2019-02-26 03:55:40 -06:00
|
|
|
}
|
|
|
|
|
2020-01-31 09:56:52 -06:00
|
|
|
function videoPlaylistElementController (req: express.Request, res: express.Response) {
|
2019-08-21 07:31:57 -05:00
|
|
|
const videoPlaylistElement = res.locals.videoPlaylistElementAP
|
2019-02-26 03:55:40 -06:00
|
|
|
|
2020-11-20 04:21:08 -06:00
|
|
|
if (redirectIfNotOwned(videoPlaylistElement.url, res)) return
|
|
|
|
|
2019-02-26 03:55:40 -06:00
|
|
|
const json = videoPlaylistElement.toActivityPubObject()
|
2022-03-23 10:14:33 -05:00
|
|
|
return activityPubResponse(activityPubContextify(json, 'Playlist'), res)
|
2019-02-26 03:55:40 -06:00
|
|
|
}
|
|
|
|
|
2022-03-24 07:36:47 -05:00
|
|
|
function getVideoLocalViewerController (req: express.Request, res: express.Response) {
|
|
|
|
const localViewer = res.locals.localViewerFull
|
|
|
|
|
|
|
|
return activityPubResponse(activityPubContextify(localViewer.toActivityPubObject(), 'WatchAction'), res)
|
|
|
|
}
|
|
|
|
|
2018-01-15 02:46:46 -06:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2022-03-23 08:24:50 -05:00
|
|
|
function actorFollowing (req: express.Request, actor: MActorId) {
|
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
|
|
|
|
2019-04-11 04:33:44 -05:00
|
|
|
return activityPubCollectionPagination(WEBSERVER.URL + req.path, handler, req.query.page)
|
2018-01-15 02:46:46 -06:00
|
|
|
}
|
|
|
|
|
2022-03-23 08:24:50 -05:00
|
|
|
function actorFollowers (req: express.Request, actor: MActorId) {
|
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)
|
|
|
|
}
|
|
|
|
|
2019-04-11 04:33:44 -05:00
|
|
|
return activityPubCollectionPagination(WEBSERVER.URL + req.path, handler, req.query.page)
|
2019-02-26 03:55:40 -06:00
|
|
|
}
|
|
|
|
|
2022-03-23 08:24:50 -05:00
|
|
|
function actorPlaylists (req: express.Request, options: { account: MAccountId } | { channel: MChannelId }) {
|
2019-02-26 03:55:40 -06:00
|
|
|
const handler = (start: number, count: number) => {
|
2020-05-13 07:49:11 -05:00
|
|
|
return VideoPlaylistModel.listPublicUrlsOfForAP(options, start, count)
|
2018-05-25 09:21:16 -05:00
|
|
|
}
|
2018-01-15 02:46:46 -06:00
|
|
|
|
2019-04-11 04:33:44 -05:00
|
|
|
return activityPubCollectionPagination(WEBSERVER.URL + req.path, handler, req.query.page)
|
2018-01-15 02:46:46 -06:00
|
|
|
}
|
2018-03-27 07:28:33 -05:00
|
|
|
|
2020-02-04 08:00:47 -06:00
|
|
|
function videoRates (req: express.Request, rateType: VideoRateType, video: MVideoId, url: string) {
|
2018-05-25 09:21:16 -05:00
|
|
|
const handler = async (start: number, count: number) => {
|
|
|
|
const result = await AccountVideoRateModel.listAndCountAccountUrlsByVideoId(rateType, video.id, start, count)
|
|
|
|
return {
|
2022-02-28 01:34:43 -06:00
|
|
|
total: result.total,
|
|
|
|
data: result.data.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
|
|
|
}
|
2020-11-20 04:21:08 -06:00
|
|
|
|
|
|
|
function redirectIfNotOwned (url: string, res: express.Response) {
|
|
|
|
if (url.startsWith(WEBSERVER.URL) === false) {
|
|
|
|
res.redirect(url)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|