aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/activitypub/client.ts34
-rw-r--r--server/controllers/activitypub/outbox.ts6
-rw-r--r--server/controllers/api/search.ts2
-rw-r--r--server/controllers/api/server/follows.ts5
-rw-r--r--server/controllers/api/server/index.ts2
-rw-r--r--server/controllers/api/server/redundancy.ts32
-rw-r--r--server/controllers/api/videos/abuse.ts2
7 files changed, 71 insertions, 12 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts
index 54cf44419..2e168ea78 100644
--- a/server/controllers/activitypub/client.ts
+++ b/server/controllers/activitypub/client.ts
@@ -3,9 +3,9 @@ import * as express from 'express'
3import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos' 3import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos'
4import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub' 4import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub'
5import { CONFIG, ROUTE_CACHE_LIFETIME } from '../../initializers' 5import { CONFIG, ROUTE_CACHE_LIFETIME } from '../../initializers'
6import { buildVideoAnnounce } from '../../lib/activitypub/send' 6import { buildAnnounceWithVideoAudience } from '../../lib/activitypub/send'
7import { audiencify, getAudience } from '../../lib/activitypub/audience' 7import { audiencify, getAudience } from '../../lib/activitypub/audience'
8import { createActivityData } from '../../lib/activitypub/send/send-create' 8import { buildCreateActivity } from '../../lib/activitypub/send/send-create'
9import { asyncMiddleware, executeIfActivityPub, localAccountValidator, localVideoChannelValidator } from '../../middlewares' 9import { asyncMiddleware, executeIfActivityPub, localAccountValidator, localVideoChannelValidator } from '../../middlewares'
10import { videosGetValidator, videosShareValidator } from '../../middlewares/validators' 10import { videosGetValidator, videosShareValidator } from '../../middlewares/validators'
11import { videoCommentGetValidator } from '../../middlewares/validators/video-comments' 11import { videoCommentGetValidator } from '../../middlewares/validators/video-comments'
@@ -26,6 +26,8 @@ import {
26 getVideoSharesActivityPubUrl 26 getVideoSharesActivityPubUrl
27} from '../../lib/activitypub' 27} from '../../lib/activitypub'
28import { VideoCaptionModel } from '../../models/video/video-caption' 28import { VideoCaptionModel } from '../../models/video/video-caption'
29import { videoRedundancyGetValidator } from '../../middlewares/validators/redundancy'
30import { getServerActor } from '../../helpers/utils'
29 31
30const activityPubClientRouter = express.Router() 32const activityPubClientRouter = express.Router()
31 33
@@ -93,6 +95,11 @@ activityPubClientRouter.get('/video-channels/:name/following',
93 executeIfActivityPub(asyncMiddleware(videoChannelFollowingController)) 95 executeIfActivityPub(asyncMiddleware(videoChannelFollowingController))
94) 96)
95 97
98activityPubClientRouter.get('/redundancy/videos/:videoId/:resolution([0-9]+)(-:fps([0-9]+))?',
99 executeIfActivityPub(asyncMiddleware(videoRedundancyGetValidator)),
100 executeIfActivityPub(asyncMiddleware(videoRedundancyController))
101)
102
96// --------------------------------------------------------------------------- 103// ---------------------------------------------------------------------------
97 104
98export { 105export {
@@ -131,7 +138,7 @@ async function videoController (req: express.Request, res: express.Response, nex
131 const videoObject = audiencify(video.toActivityPubObject(), audience) 138 const videoObject = audiencify(video.toActivityPubObject(), audience)
132 139
133 if (req.path.endsWith('/activity')) { 140 if (req.path.endsWith('/activity')) {
134 const data = createActivityData(video.url, video.VideoChannel.Account.Actor, videoObject, audience) 141 const data = buildCreateActivity(video.url, video.VideoChannel.Account.Actor, videoObject, audience)
135 return activityPubResponse(activityPubContextify(data), res) 142 return activityPubResponse(activityPubContextify(data), res)
136 } 143 }
137 144
@@ -140,9 +147,9 @@ async function videoController (req: express.Request, res: express.Response, nex
140 147
141async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { 148async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) {
142 const share = res.locals.videoShare as VideoShareModel 149 const share = res.locals.videoShare as VideoShareModel
143 const object = await buildVideoAnnounce(share.Actor, share, res.locals.video, undefined) 150 const { activity } = await buildAnnounceWithVideoAudience(share.Actor, share, res.locals.video, undefined)
144 151
145 return activityPubResponse(activityPubContextify(object), res) 152 return activityPubResponse(activityPubContextify(activity), res)
146} 153}
147 154
148async function videoAnnouncesController (req: express.Request, res: express.Response, next: express.NextFunction) { 155async function videoAnnouncesController (req: express.Request, res: express.Response, next: express.NextFunction) {
@@ -219,13 +226,28 @@ async function videoCommentController (req: express.Request, res: express.Respon
219 const videoCommentObject = audiencify(videoComment.toActivityPubObject(threadParentComments), audience) 226 const videoCommentObject = audiencify(videoComment.toActivityPubObject(threadParentComments), audience)
220 227
221 if (req.path.endsWith('/activity')) { 228 if (req.path.endsWith('/activity')) {
222 const data = createActivityData(videoComment.url, videoComment.Account.Actor, videoCommentObject, audience) 229 const data = buildCreateActivity(videoComment.url, videoComment.Account.Actor, videoCommentObject, audience)
223 return activityPubResponse(activityPubContextify(data), res) 230 return activityPubResponse(activityPubContextify(data), res)
224 } 231 }
225 232
226 return activityPubResponse(activityPubContextify(videoCommentObject), res) 233 return activityPubResponse(activityPubContextify(videoCommentObject), res)
227} 234}
228 235
236async function videoRedundancyController (req: express.Request, res: express.Response) {
237 const videoRedundancy = res.locals.videoRedundancy
238 const serverActor = await getServerActor()
239
240 const audience = getAudience(serverActor)
241 const object = audiencify(videoRedundancy.toActivityPubObject(), audience)
242
243 if (req.path.endsWith('/activity')) {
244 const data = buildCreateActivity(videoRedundancy.url, serverActor, object, audience)
245 return activityPubResponse(activityPubContextify(data), res)
246 }
247
248 return activityPubResponse(activityPubContextify(object), res)
249}
250
229// --------------------------------------------------------------------------- 251// ---------------------------------------------------------------------------
230 252
231async function actorFollowing (req: express.Request, actor: ActorModel) { 253async function actorFollowing (req: express.Request, actor: ActorModel) {
diff --git a/server/controllers/activitypub/outbox.ts b/server/controllers/activitypub/outbox.ts
index db69ae54b..bd0e4fe9d 100644
--- a/server/controllers/activitypub/outbox.ts
+++ b/server/controllers/activitypub/outbox.ts
@@ -3,7 +3,7 @@ import { Activity } from '../../../shared/models/activitypub/activity'
3import { VideoPrivacy } from '../../../shared/models/videos' 3import { VideoPrivacy } from '../../../shared/models/videos'
4import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub' 4import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub'
5import { logger } from '../../helpers/logger' 5import { logger } from '../../helpers/logger'
6import { announceActivityData, createActivityData } from '../../lib/activitypub/send' 6import { buildAnnounceActivity, buildCreateActivity } from '../../lib/activitypub/send'
7import { buildAudience } from '../../lib/activitypub/audience' 7import { buildAudience } from '../../lib/activitypub/audience'
8import { asyncMiddleware, localAccountValidator, localVideoChannelValidator } from '../../middlewares' 8import { asyncMiddleware, localAccountValidator, localVideoChannelValidator } from '../../middlewares'
9import { AccountModel } from '../../models/account/account' 9import { AccountModel } from '../../models/account/account'
@@ -60,12 +60,12 @@ async function buildActivities (actor: ActorModel, start: number, count: number)
60 // This is a shared video 60 // This is a shared video
61 if (video.VideoShares !== undefined && video.VideoShares.length !== 0) { 61 if (video.VideoShares !== undefined && video.VideoShares.length !== 0) {
62 const videoShare = video.VideoShares[0] 62 const videoShare = video.VideoShares[0]
63 const announceActivity = announceActivityData(videoShare.url, actor, video.url, createActivityAudience) 63 const announceActivity = buildAnnounceActivity(videoShare.url, actor, video.url, createActivityAudience)
64 64
65 activities.push(announceActivity) 65 activities.push(announceActivity)
66 } else { 66 } else {
67 const videoObject = video.toActivityPubObject() 67 const videoObject = video.toActivityPubObject()
68 const createActivity = createActivityData(video.url, byActor, videoObject, createActivityAudience) 68 const createActivity = buildCreateActivity(video.url, byActor, videoObject, createActivityAudience)
69 69
70 activities.push(createActivity) 70 activities.push(createActivity)
71 } 71 }
diff --git a/server/controllers/api/search.ts b/server/controllers/api/search.ts
index bb7174891..28a7a04ca 100644
--- a/server/controllers/api/search.ts
+++ b/server/controllers/api/search.ts
@@ -17,8 +17,6 @@ import {
17import { VideoChannelsSearchQuery, VideosSearchQuery } from '../../../shared/models/search' 17import { VideoChannelsSearchQuery, VideosSearchQuery } from '../../../shared/models/search'
18import { getOrCreateActorAndServerAndModel, getOrCreateVideoAndAccountAndChannel } from '../../lib/activitypub' 18import { getOrCreateActorAndServerAndModel, getOrCreateVideoAndAccountAndChannel } from '../../lib/activitypub'
19import { logger } from '../../helpers/logger' 19import { logger } from '../../helpers/logger'
20import { User } from '../../../shared/models/users'
21import { CONFIG } from '../../initializers/constants'
22import { VideoChannelModel } from '../../models/video/video-channel' 20import { VideoChannelModel } from '../../models/video/video-channel'
23import { loadActorUrlOrGetFromWebfinger } from '../../helpers/webfinger' 21import { loadActorUrlOrGetFromWebfinger } from '../../helpers/webfinger'
24 22
diff --git a/server/controllers/api/server/follows.ts b/server/controllers/api/server/follows.ts
index 23308445f..a4eae6b45 100644
--- a/server/controllers/api/server/follows.ts
+++ b/server/controllers/api/server/follows.ts
@@ -96,6 +96,11 @@ async function removeFollow (req: express.Request, res: express.Response, next:
96 await sequelizeTypescript.transaction(async t => { 96 await sequelizeTypescript.transaction(async t => {
97 if (follow.state === 'accepted') await sendUndoFollow(follow, t) 97 if (follow.state === 'accepted') await sendUndoFollow(follow, t)
98 98
99 // Disable redundancy on unfollowed instances
100 const server = follow.ActorFollowing.Server
101 server.redundancyAllowed = false
102 await server.save({ transaction: t })
103
99 await follow.destroy({ transaction: t }) 104 await follow.destroy({ transaction: t })
100 }) 105 })
101 106
diff --git a/server/controllers/api/server/index.ts b/server/controllers/api/server/index.ts
index 850a52cdb..43bca2c10 100644
--- a/server/controllers/api/server/index.ts
+++ b/server/controllers/api/server/index.ts
@@ -1,10 +1,12 @@
1import * as express from 'express' 1import * as express from 'express'
2import { serverFollowsRouter } from './follows' 2import { serverFollowsRouter } from './follows'
3import { statsRouter } from './stats' 3import { statsRouter } from './stats'
4import { serverRedundancyRouter } from './redundancy'
4 5
5const serverRouter = express.Router() 6const serverRouter = express.Router()
6 7
7serverRouter.use('/', serverFollowsRouter) 8serverRouter.use('/', serverFollowsRouter)
9serverRouter.use('/', serverRedundancyRouter)
8serverRouter.use('/', statsRouter) 10serverRouter.use('/', statsRouter)
9 11
10// --------------------------------------------------------------------------- 12// ---------------------------------------------------------------------------
diff --git a/server/controllers/api/server/redundancy.ts b/server/controllers/api/server/redundancy.ts
new file mode 100644
index 000000000..4216b9e35
--- /dev/null
+++ b/server/controllers/api/server/redundancy.ts
@@ -0,0 +1,32 @@
1import * as express from 'express'
2import { UserRight } from '../../../../shared/models/users'
3import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../../middlewares'
4import { updateServerRedundancyValidator } from '../../../middlewares/validators/redundancy'
5import { ServerModel } from '../../../models/server/server'
6
7const serverRedundancyRouter = express.Router()
8
9serverRedundancyRouter.put('/redundancy/:host',
10 authenticate,
11 ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW),
12 asyncMiddleware(updateServerRedundancyValidator),
13 asyncMiddleware(updateRedundancy)
14)
15
16// ---------------------------------------------------------------------------
17
18export {
19 serverRedundancyRouter
20}
21
22// ---------------------------------------------------------------------------
23
24async function updateRedundancy (req: express.Request, res: express.Response, next: express.NextFunction) {
25 const server = res.locals.server as ServerModel
26
27 server.redundancyAllowed = req.body.redundancyAllowed
28
29 await server.save()
30
31 return res.sendStatus(204)
32}
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts
index 59bdf6257..08e11b00b 100644
--- a/server/controllers/api/videos/abuse.ts
+++ b/server/controllers/api/videos/abuse.ts
@@ -112,7 +112,7 @@ async function reportVideoAbuse (req: express.Request, res: express.Response) {
112 112
113 // We send the video abuse to the origin server 113 // We send the video abuse to the origin server
114 if (videoInstance.isOwned() === false) { 114 if (videoInstance.isOwned() === false) {
115 await sendVideoAbuse(reporterAccount.Actor, videoAbuseInstance, videoInstance, t) 115 await sendVideoAbuse(reporterAccount.Actor, videoAbuseInstance, videoInstance)
116 } 116 }
117 117
118 auditLogger.create(reporterAccount.Actor.getIdentifier(), new VideoAbuseAuditView(videoAbuseInstance.toFormattedJSON())) 118 auditLogger.create(reporterAccount.Actor.getIdentifier(), new VideoAbuseAuditView(videoAbuseInstance.toFormattedJSON()))