aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/activitypub/inbox.ts15
-rw-r--r--server/controllers/api/server/follows.ts30
-rw-r--r--server/controllers/api/videos/channel.ts6
-rw-r--r--server/controllers/api/videos/index.ts11
4 files changed, 43 insertions, 19 deletions
diff --git a/server/controllers/activitypub/inbox.ts b/server/controllers/activitypub/inbox.ts
index fd3695886..807d0bdf4 100644
--- a/server/controllers/activitypub/inbox.ts
+++ b/server/controllers/activitypub/inbox.ts
@@ -2,12 +2,12 @@ import * as express from 'express'
2import { Activity, ActivityPubCollection, ActivityPubOrderedCollection, ActivityType, RootActivity } from '../../../shared' 2import { Activity, ActivityPubCollection, ActivityPubOrderedCollection, ActivityType, RootActivity } from '../../../shared'
3import { logger } from '../../helpers' 3import { logger } from '../../helpers'
4import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity' 4import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity'
5import { processCreateActivity, processUpdateActivity } from '../../lib' 5import { processCreateActivity, processUpdateActivity, processUndoActivity } from '../../lib'
6import { processAcceptActivity } from '../../lib/activitypub/process-accept' 6import { processAcceptActivity } from '../../lib/activitypub/process/process-accept'
7import { processAddActivity } from '../../lib/activitypub/process-add' 7import { processAddActivity } from '../../lib/activitypub/process/process-add'
8import { processAnnounceActivity } from '../../lib/activitypub/process-announce' 8import { processAnnounceActivity } from '../../lib/activitypub/process/process-announce'
9import { processDeleteActivity } from '../../lib/activitypub/process-delete' 9import { processDeleteActivity } from '../../lib/activitypub/process/process-delete'
10import { processFollowActivity } from '../../lib/activitypub/process-follow' 10import { processFollowActivity } from '../../lib/activitypub/process/process-follow'
11import { asyncMiddleware, checkSignature, localAccountValidator, signatureValidator } from '../../middlewares' 11import { asyncMiddleware, checkSignature, localAccountValidator, signatureValidator } from '../../middlewares'
12import { activityPubValidator } from '../../middlewares/validators/activitypub/activity' 12import { activityPubValidator } from '../../middlewares/validators/activitypub/activity'
13import { AccountInstance } from '../../models/account/account-interface' 13import { AccountInstance } from '../../models/account/account-interface'
@@ -19,7 +19,8 @@ const processActivity: { [ P in ActivityType ]: (activity: Activity, inboxAccoun
19 Delete: processDeleteActivity, 19 Delete: processDeleteActivity,
20 Follow: processFollowActivity, 20 Follow: processFollowActivity,
21 Accept: processAcceptActivity, 21 Accept: processAcceptActivity,
22 Announce: processAnnounceActivity 22 Announce: processAnnounceActivity,
23 Undo: processUndoActivity
23} 24}
24 25
25const inboxRouter = express.Router() 26const inboxRouter = express.Router()
diff --git a/server/controllers/api/server/follows.ts b/server/controllers/api/server/follows.ts
index 3d184ec1f..8fc70f34f 100644
--- a/server/controllers/api/server/follows.ts
+++ b/server/controllers/api/server/follows.ts
@@ -6,14 +6,16 @@ import { getServerAccount } from '../../../helpers/utils'
6import { getAccountFromWebfinger } from '../../../helpers/webfinger' 6import { getAccountFromWebfinger } from '../../../helpers/webfinger'
7import { SERVER_ACCOUNT_NAME } from '../../../initializers/constants' 7import { SERVER_ACCOUNT_NAME } from '../../../initializers/constants'
8import { database as db } from '../../../initializers/database' 8import { database as db } from '../../../initializers/database'
9import { sendFollow } from '../../../lib/activitypub/send-request' 9import { asyncMiddleware, paginationValidator, removeFollowingValidator, setFollowersSort, setPagination } from '../../../middlewares'
10import { asyncMiddleware, paginationValidator, setFollowersSort, setPagination } from '../../../middlewares'
11import { authenticate } from '../../../middlewares/oauth' 10import { authenticate } from '../../../middlewares/oauth'
12import { setBodyHostsPort } from '../../../middlewares/servers' 11import { setBodyHostsPort } from '../../../middlewares/servers'
13import { setFollowingSort } from '../../../middlewares/sort' 12import { setFollowingSort } from '../../../middlewares/sort'
14import { ensureUserHasRight } from '../../../middlewares/user-right' 13import { ensureUserHasRight } from '../../../middlewares/user-right'
15import { followValidator } from '../../../middlewares/validators/servers' 14import { followValidator } from '../../../middlewares/validators/follows'
16import { followersSortValidator, followingSortValidator } from '../../../middlewares/validators/sort' 15import { followersSortValidator, followingSortValidator } from '../../../middlewares/validators/sort'
16import { AccountFollowInstance } from '../../../models/index'
17import { sendFollow } from '../../../lib/index'
18import { sendUndoFollow } from '../../../lib/activitypub/send/send-undo'
17 19
18const serverFollowsRouter = express.Router() 20const serverFollowsRouter = express.Router()
19 21
@@ -33,6 +35,13 @@ serverFollowsRouter.post('/following',
33 asyncMiddleware(follow) 35 asyncMiddleware(follow)
34) 36)
35 37
38serverFollowsRouter.delete('/following/:accountId',
39 authenticate,
40 ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW),
41 removeFollowingValidator,
42 asyncMiddleware(removeFollow)
43)
44
36serverFollowsRouter.get('/followers', 45serverFollowsRouter.get('/followers',
37 paginationValidator, 46 paginationValidator,
38 followersSortValidator, 47 followersSortValidator,
@@ -96,10 +105,12 @@ async function follow (req: express.Request, res: express.Response, next: expres
96 }, 105 },
97 transaction: t 106 transaction: t
98 }) 107 })
108 accountFollow.AccountFollowing = targetAccount
109 accountFollow.AccountFollower = fromAccount
99 110
100 // Send a notification to remote server 111 // Send a notification to remote server
101 if (accountFollow.state === 'pending') { 112 if (accountFollow.state === 'pending') {
102 await sendFollow(fromAccount, targetAccount, t) 113 await sendFollow(accountFollow, t)
103 } 114 }
104 }) 115 })
105 }) 116 })
@@ -117,6 +128,17 @@ async function follow (req: express.Request, res: express.Response, next: expres
117 return res.status(204).end() 128 return res.status(204).end()
118} 129}
119 130
131async function removeFollow (req: express.Request, res: express.Response, next: express.NextFunction) {
132 const following: AccountFollowInstance = res.locals.following
133
134 await db.sequelize.transaction(async t => {
135 await sendUndoFollow(following, t)
136 await following.destroy({ transaction: t })
137 })
138
139 return res.status(204).end()
140}
141
120async function loadLocalOrGetAccountFromWebfinger (name: string, host: string) { 142async function loadLocalOrGetAccountFromWebfinger (name: string, host: string) {
121 let loadedFromDB = true 143 let loadedFromDB = true
122 let account = await db.Account.loadByNameAndHost(name, host) 144 let account = await db.Account.loadByNameAndHost(name, host)
diff --git a/server/controllers/api/videos/channel.ts b/server/controllers/api/videos/channel.ts
index 8f3df2550..ce2656e71 100644
--- a/server/controllers/api/videos/channel.ts
+++ b/server/controllers/api/videos/channel.ts
@@ -17,7 +17,7 @@ import {
17 videoChannelsUpdateValidator 17 videoChannelsUpdateValidator
18} from '../../../middlewares' 18} from '../../../middlewares'
19import { AccountInstance, VideoChannelInstance } from '../../../models' 19import { AccountInstance, VideoChannelInstance } from '../../../models'
20import { sendUpdateVideoChannel } from '../../../lib/activitypub/send-request' 20import { sendUpdateVideoChannel } from '../../../lib/activitypub/send/send-update'
21 21
22const videoChannelRouter = express.Router() 22const videoChannelRouter = express.Router()
23 23
@@ -128,9 +128,9 @@ async function updateVideoChannel (req: express.Request, res: express.Response)
128 if (videoChannelInfoToUpdate.name !== undefined) videoChannelInstance.set('name', videoChannelInfoToUpdate.name) 128 if (videoChannelInfoToUpdate.name !== undefined) videoChannelInstance.set('name', videoChannelInfoToUpdate.name)
129 if (videoChannelInfoToUpdate.description !== undefined) videoChannelInstance.set('description', videoChannelInfoToUpdate.description) 129 if (videoChannelInfoToUpdate.description !== undefined) videoChannelInstance.set('description', videoChannelInfoToUpdate.description)
130 130
131 await videoChannelInstance.save(sequelizeOptions) 131 const videoChannelInstanceUpdated = await videoChannelInstance.save(sequelizeOptions)
132 132
133 await sendUpdateVideoChannel(videoChannelInstance, t) 133 await sendUpdateVideoChannel(videoChannelInstanceUpdated, t)
134 }) 134 })
135 135
136 logger.info('Video channel with name %s and uuid %s updated.', videoChannelInstance.name, videoChannelInstance.uuid) 136 logger.info('Video channel with name %s and uuid %s updated.', videoChannelInstance.name, videoChannelInstance.uuid)
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 22a88620a..8c9b0aa50 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -12,10 +12,11 @@ import {
12 resetSequelizeInstance, 12 resetSequelizeInstance,
13 retryTransactionWrapper 13 retryTransactionWrapper
14} from '../../../helpers' 14} from '../../../helpers'
15import { getActivityPubUrl, shareVideoByServer } from '../../../helpers/activitypub' 15import { getVideoActivityPubUrl, shareVideoByServer } from '../../../helpers/activitypub'
16import { CONFIG, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_MIMETYPE_EXT, VIDEO_PRIVACIES } from '../../../initializers' 16import { CONFIG, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_MIMETYPE_EXT, VIDEO_PRIVACIES } from '../../../initializers'
17import { database as db } from '../../../initializers/database' 17import { database as db } from '../../../initializers/database'
18import { sendAddVideo, sendUpdateVideo } from '../../../lib/activitypub/send-request' 18import { sendAddVideo } from '../../../lib/activitypub/send/send-add'
19import { sendUpdateVideo } from '../../../lib/activitypub/send/send-update'
19import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler/transcoding-job-scheduler' 20import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler/transcoding-job-scheduler'
20import { 21import {
21 asyncMiddleware, 22 asyncMiddleware,
@@ -175,7 +176,7 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi
175 channelId: res.locals.videoChannel.id 176 channelId: res.locals.videoChannel.id
176 } 177 }
177 const video = db.Video.build(videoData) 178 const video = db.Video.build(videoData)
178 video.url = getActivityPubUrl('video', video.uuid) 179 video.url = getVideoActivityPubUrl(video)
179 180
180 const videoFilePath = join(CONFIG.STORAGE.VIDEOS_DIR, videoPhysicalFile.filename) 181 const videoFilePath = join(CONFIG.STORAGE.VIDEOS_DIR, videoPhysicalFile.filename)
181 const videoFileHeight = await getVideoFileHeight(videoFilePath) 182 const videoFileHeight = await getVideoFileHeight(videoFilePath)
@@ -274,7 +275,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
274 if (videoInfoToUpdate.privacy !== undefined) videoInstance.set('privacy', videoInfoToUpdate.privacy) 275 if (videoInfoToUpdate.privacy !== undefined) videoInstance.set('privacy', videoInfoToUpdate.privacy)
275 if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description) 276 if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description)
276 277
277 await videoInstance.save(sequelizeOptions) 278 const videoInstanceUpdated = await videoInstance.save(sequelizeOptions)
278 279
279 if (videoInfoToUpdate.tags) { 280 if (videoInfoToUpdate.tags) {
280 const tagInstances = await db.Tag.findOrCreateTags(videoInfoToUpdate.tags, t) 281 const tagInstances = await db.Tag.findOrCreateTags(videoInfoToUpdate.tags, t)
@@ -285,7 +286,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
285 286
286 // Now we'll update the video's meta data to our friends 287 // Now we'll update the video's meta data to our friends
287 if (wasPrivateVideo === false) { 288 if (wasPrivateVideo === false) {
288 await sendUpdateVideo(videoInstance, t) 289 await sendUpdateVideo(videoInstanceUpdated, t)
289 } 290 }
290 291
291 // Video is not private anymore, send a create action to remote servers 292 // Video is not private anymore, send a create action to remote servers