-// Intercept ActivityPub client requests
import * as express from 'express'
import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos'
import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub'
import { videoPlaylistElementAPGetValidator, videoPlaylistsGetValidator } from '../../middlewares/validators/videos/video-playlists'
import { VideoPlaylistModel } from '../../models/video/video-playlist'
import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
-import { MAccountId, MActorId, MVideo, MVideoAPWithoutCaption, MVideoId } from '@server/typings/models'
+import { MAccountId, MActorId, MVideoAPWithoutCaption, MVideoId } from '@server/typings/models'
const activityPubClientRouter = express.Router()
+// Intercept ActivityPub client requests
+
activityPubClientRouter.get('/accounts?/:name',
executeIfActivityPub,
asyncMiddleware(localAccountValidator),
asyncMiddleware(getVideo)
)
videosRouter.post('/:id/views',
- asyncMiddleware(videosGetValidator),
+ asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')),
asyncMiddleware(viewVideo)
)
}
async function viewVideo (req: express.Request, res: express.Response) {
- const videoInstance = res.locals.videoAll
+ const videoInstance = res.locals.onlyImmutableVideo
const ip = req.ip
const exists = await Redis.Instance.doesVideoIPViewExist(ip, videoInstance.uuid)
import { ActorModel } from '../../models/activitypub/actor'
import { VideoModel } from '../../models/video/video'
import { VideoShareModel } from '../../models/video/video-share'
-import {
- MActorFollowersUrl,
- MActorLight,
- MCommentOwner,
- MCommentOwnerVideo,
- MVideo,
- MVideoAccountLight,
- MVideoId
-} from '../../typings/models'
-
-function getRemoteVideoAudience (video: MVideoAccountLight, actorsInvolvedInVideo: MActorFollowersUrl[]): ActivityAudience {
+import { MActorFollowersUrl, MActorLight, MActorUrl, MCommentOwner, MCommentOwnerVideo, MVideoId } from '../../typings/models'
+
+function getRemoteVideoAudience (accountActor: MActorUrl, actorsInvolvedInVideo: MActorFollowersUrl[]): ActivityAudience {
return {
- to: [ video.VideoChannel.Account.Actor.url ],
+ to: [ accountActor.url ],
cc: actorsInvolvedInVideo.map(a => a.followersUrl)
}
}
import { sendVideoRelatedActivity } from './utils'
import { audiencify, getAudience } from '../audience'
import { logger } from '../../../helpers/logger'
-import { MActorAudience, MVideoAccountLight, MVideoUrl } from '@server/typings/models'
+import { MActorAudience, MVideoImmutable, MVideoUrl } from '@server/typings/models'
-async function sendView (byActor: ActorModel, video: MVideoAccountLight, t: Transaction) {
+async function sendView (byActor: ActorModel, video: MVideoImmutable, t: Transaction) {
logger.info('Creating job to send view of %s.', video.url)
const activityBuilder = (audience: ActivityAudience) => {
import { getActorsInvolvedInVideo, getAudienceFromFollowersOf, getRemoteVideoAudience } from '../audience'
import { getServerActor } from '../../../helpers/utils'
import { afterCommitIfTransaction } from '../../../helpers/database-utils'
-import { MActorWithInboxes, MActor, MActorId, MActorLight, MVideo, MVideoAccountLight, MVideoId } from '../../../typings/models'
+import { MActor, MActorId, MActorLight, MActorWithInboxes, MVideoAccountLight, MVideoId, MVideoImmutable } from '../../../typings/models'
import { ContextType } from '@server/helpers/activitypub'
async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAudience) => Activity, options: {
byActor: MActorLight
- video: MVideoAccountLight
+ video: MVideoImmutable | MVideoAccountLight
transaction?: Transaction
contextType?: ContextType
}) {
// Send to origin
if (video.isOwned() === false) {
- const audience = getRemoteVideoAudience(video, actorsInvolvedInVideo)
+ const accountActor = (video as MVideoAccountLight).VideoChannel?.Account?.Actor || await ActorModel.loadAccountActorByVideoId(video.id)
+
+ const audience = getRemoteVideoAudience(accountActor, actorsInvolvedInVideo)
const activity = activityBuilder(audience)
return afterCommitIfTransaction(transaction, () => {
- return unicastTo(activity, byActor, video.VideoChannel.Account.Actor.getSharedInbox(), contextType)
+ return unicastTo(activity, byActor, accountActor.getSharedInbox(), contextType)
})
}
}, { where, transaction })
}
+ static loadAccountActorByVideoId (videoId: number): Bluebird<MActor> {
+ const query = {
+ include: [
+ {
+ attributes: [ 'id' ],
+ model: AccountModel.unscoped(),
+ required: true,
+ include: [
+ {
+ attributes: [ 'id', 'accountId' ],
+ model: VideoChannelModel.unscoped(),
+ required: true,
+ include: [
+ {
+ attributes: [ 'id', 'channelId' ],
+ model: VideoModel.unscoped(),
+ where: {
+ id: videoId
+ }
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+
+ return ActorModel.unscoped().findOne(query)
+ }
+
getSharedInbox (this: MActorWithInboxes) {
return this.sharedInboxUrl || this.inboxUrl
}