diff options
author | Chocobozzz <me@florianbigard.com> | 2018-09-11 16:27:07 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-09-13 14:05:49 +0200 |
commit | c48e82b5e0478434de30626d14594a97f2402e7c (patch) | |
tree | a78e5272bd0fe4f5b41831e571e02d05f1515b82 /server/controllers/api | |
parent | a651038487faa838bda3ce04695b08bc65baff70 (diff) | |
download | PeerTube-c48e82b5e0478434de30626d14594a97f2402e7c.tar.gz PeerTube-c48e82b5e0478434de30626d14594a97f2402e7c.tar.zst PeerTube-c48e82b5e0478434de30626d14594a97f2402e7c.zip |
Basic video redundancy implementation
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/search.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/server/follows.ts | 5 | ||||
-rw-r--r-- | server/controllers/api/server/index.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/server/redundancy.ts | 32 | ||||
-rw-r--r-- | server/controllers/api/videos/abuse.ts | 2 |
5 files changed, 40 insertions, 3 deletions
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 { | |||
17 | import { VideoChannelsSearchQuery, VideosSearchQuery } from '../../../shared/models/search' | 17 | import { VideoChannelsSearchQuery, VideosSearchQuery } from '../../../shared/models/search' |
18 | import { getOrCreateActorAndServerAndModel, getOrCreateVideoAndAccountAndChannel } from '../../lib/activitypub' | 18 | import { getOrCreateActorAndServerAndModel, getOrCreateVideoAndAccountAndChannel } from '../../lib/activitypub' |
19 | import { logger } from '../../helpers/logger' | 19 | import { logger } from '../../helpers/logger' |
20 | import { User } from '../../../shared/models/users' | ||
21 | import { CONFIG } from '../../initializers/constants' | ||
22 | import { VideoChannelModel } from '../../models/video/video-channel' | 20 | import { VideoChannelModel } from '../../models/video/video-channel' |
23 | import { loadActorUrlOrGetFromWebfinger } from '../../helpers/webfinger' | 21 | import { 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { serverFollowsRouter } from './follows' | 2 | import { serverFollowsRouter } from './follows' |
3 | import { statsRouter } from './stats' | 3 | import { statsRouter } from './stats' |
4 | import { serverRedundancyRouter } from './redundancy' | ||
4 | 5 | ||
5 | const serverRouter = express.Router() | 6 | const serverRouter = express.Router() |
6 | 7 | ||
7 | serverRouter.use('/', serverFollowsRouter) | 8 | serverRouter.use('/', serverFollowsRouter) |
9 | serverRouter.use('/', serverRedundancyRouter) | ||
8 | serverRouter.use('/', statsRouter) | 10 | serverRouter.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 @@ | |||
1 | import * as express from 'express' | ||
2 | import { UserRight } from '../../../../shared/models/users' | ||
3 | import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../../middlewares' | ||
4 | import { updateServerRedundancyValidator } from '../../../middlewares/validators/redundancy' | ||
5 | import { ServerModel } from '../../../models/server/server' | ||
6 | |||
7 | const serverRedundancyRouter = express.Router() | ||
8 | |||
9 | serverRedundancyRouter.put('/redundancy/:host', | ||
10 | authenticate, | ||
11 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), | ||
12 | asyncMiddleware(updateServerRedundancyValidator), | ||
13 | asyncMiddleware(updateRedundancy) | ||
14 | ) | ||
15 | |||
16 | // --------------------------------------------------------------------------- | ||
17 | |||
18 | export { | ||
19 | serverRedundancyRouter | ||
20 | } | ||
21 | |||
22 | // --------------------------------------------------------------------------- | ||
23 | |||
24 | async 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())) |