From c48e82b5e0478434de30626d14594a97f2402e7c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 11 Sep 2018 16:27:07 +0200 Subject: Basic video redundancy implementation --- server/controllers/api/search.ts | 2 -- server/controllers/api/server/follows.ts | 5 +++++ server/controllers/api/server/index.ts | 2 ++ server/controllers/api/server/redundancy.ts | 32 +++++++++++++++++++++++++++++ server/controllers/api/videos/abuse.ts | 2 +- 5 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 server/controllers/api/server/redundancy.ts (limited to 'server/controllers/api') 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 { import { VideoChannelsSearchQuery, VideosSearchQuery } from '../../../shared/models/search' import { getOrCreateActorAndServerAndModel, getOrCreateVideoAndAccountAndChannel } from '../../lib/activitypub' import { logger } from '../../helpers/logger' -import { User } from '../../../shared/models/users' -import { CONFIG } from '../../initializers/constants' import { VideoChannelModel } from '../../models/video/video-channel' import { loadActorUrlOrGetFromWebfinger } from '../../helpers/webfinger' 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: await sequelizeTypescript.transaction(async t => { if (follow.state === 'accepted') await sendUndoFollow(follow, t) + // Disable redundancy on unfollowed instances + const server = follow.ActorFollowing.Server + server.redundancyAllowed = false + await server.save({ transaction: t }) + await follow.destroy({ transaction: t }) }) 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 @@ import * as express from 'express' import { serverFollowsRouter } from './follows' import { statsRouter } from './stats' +import { serverRedundancyRouter } from './redundancy' const serverRouter = express.Router() serverRouter.use('/', serverFollowsRouter) +serverRouter.use('/', serverRedundancyRouter) serverRouter.use('/', statsRouter) // --------------------------------------------------------------------------- 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 @@ +import * as express from 'express' +import { UserRight } from '../../../../shared/models/users' +import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../../middlewares' +import { updateServerRedundancyValidator } from '../../../middlewares/validators/redundancy' +import { ServerModel } from '../../../models/server/server' + +const serverRedundancyRouter = express.Router() + +serverRedundancyRouter.put('/redundancy/:host', + authenticate, + ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), + asyncMiddleware(updateServerRedundancyValidator), + asyncMiddleware(updateRedundancy) +) + +// --------------------------------------------------------------------------- + +export { + serverRedundancyRouter +} + +// --------------------------------------------------------------------------- + +async function updateRedundancy (req: express.Request, res: express.Response, next: express.NextFunction) { + const server = res.locals.server as ServerModel + + server.redundancyAllowed = req.body.redundancyAllowed + + await server.save() + + return res.sendStatus(204) +} 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) { // We send the video abuse to the origin server if (videoInstance.isOwned() === false) { - await sendVideoAbuse(reporterAccount.Actor, videoAbuseInstance, videoInstance, t) + await sendVideoAbuse(reporterAccount.Actor, videoAbuseInstance, videoInstance) } auditLogger.create(reporterAccount.Actor.getIdentifier(), new VideoAbuseAuditView(videoAbuseInstance.toFormattedJSON())) -- cgit v1.2.3