From 50d6de9c286abcb34ff4234d56d9cbb803db7665 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 14 Dec 2017 17:38:41 +0100 Subject: Begin moving video channel to actor --- server/controllers/api/videos/abuse.ts | 20 ++++++++------------ server/controllers/api/videos/channel.ts | 28 ++++++++++++++++------------ server/controllers/api/videos/index.ts | 13 +++++++------ 3 files changed, 31 insertions(+), 30 deletions(-) (limited to 'server/controllers/api/videos') diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts index 08cc4d0b4..fecdaf5a3 100644 --- a/server/controllers/api/videos/abuse.ts +++ b/server/controllers/api/videos/abuse.ts @@ -1,22 +1,18 @@ import * as express from 'express' -import { - logger, - getFormattedObjects, - retryTransactionWrapper -} from '../../../helpers' +import { UserRight, VideoAbuseCreate } from '../../../../shared' +import { getFormattedObjects, logger, retryTransactionWrapper } from '../../../helpers' import { sequelizeTypescript } from '../../../initializers' +import { sendVideoAbuse } from '../../../lib/activitypub/send' import { + asyncMiddleware, authenticate, ensureUserHasRight, paginationValidator, - videoAbuseReportValidator, - videoAbusesSortValidator, - setVideoAbusesSort, setPagination, - asyncMiddleware + setVideoAbusesSort, + videoAbuseReportValidator, + videoAbusesSortValidator } from '../../../middlewares' -import { VideoAbuseCreate, UserRight } from '../../../../shared' -import { sendVideoAbuse } from '../../../lib/index' import { AccountModel } from '../../../models/account/account' import { VideoModel } from '../../../models/video/video' import { VideoAbuseModel } from '../../../models/video/video-abuse' @@ -80,7 +76,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, videoAbuseInstance, videoInstance, t) + await sendVideoAbuse(reporterAccount.Actor, videoAbuseInstance, videoInstance, t) } }) diff --git a/server/controllers/api/videos/channel.ts b/server/controllers/api/videos/channel.ts index 315469115..cc00d9f8d 100644 --- a/server/controllers/api/videos/channel.ts +++ b/server/controllers/api/videos/channel.ts @@ -2,8 +2,8 @@ import * as express from 'express' import { VideoChannelCreate, VideoChannelUpdate } from '../../../../shared' import { getFormattedObjects, logger, resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers' import { sequelizeTypescript } from '../../../initializers' -import { createVideoChannel } from '../../../lib' -import { sendUpdateVideoChannel } from '../../../lib/activitypub/send/send-update' +import { setAsyncActorKeys } from '../../../lib/activitypub' +import { createVideoChannel } from '../../../lib/video-channel' import { asyncMiddleware, authenticate, @@ -92,15 +92,17 @@ async function addVideoChannelRetryWrapper (req: express.Request, res: express.R return res.type('json').status(204).end() } -function addVideoChannel (req: express.Request, res: express.Response) { +async function addVideoChannel (req: express.Request, res: express.Response) { const videoChannelInfo: VideoChannelCreate = req.body const account: AccountModel = res.locals.oauth.token.User.Account - return sequelizeTypescript.transaction(async t => { - const videoChannelCreated = await createVideoChannel(videoChannelInfo, account, t) - - logger.info('Video channel with uuid %s created.', videoChannelCreated.uuid) + const videoChannelCreated = await sequelizeTypescript.transaction(async t => { + return createVideoChannel(videoChannelInfo, account, t) }) + + setAsyncActorKeys(videoChannelCreated.Actor) + + logger.info('Video channel with uuid %s created.', videoChannelCreated.Actor.uuid) } async function updateVideoChannelRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { @@ -128,12 +130,13 @@ async function updateVideoChannel (req: express.Request, res: express.Response) if (videoChannelInfoToUpdate.name !== undefined) videoChannelInstance.set('name', videoChannelInfoToUpdate.name) if (videoChannelInfoToUpdate.description !== undefined) videoChannelInstance.set('description', videoChannelInfoToUpdate.description) - const videoChannelInstanceUpdated = await videoChannelInstance.save(sequelizeOptions) + await videoChannelInstance.save(sequelizeOptions) - await sendUpdateVideoChannel(videoChannelInstanceUpdated, t) + // TODO + // await sendUpdateVideoChannel(videoChannelInstanceUpdated, t) }) - logger.info('Video channel with name %s and uuid %s updated.', videoChannelInstance.name, videoChannelInstance.uuid) + logger.info('Video channel with name %s and uuid %s updated.', videoChannelInstance.name, videoChannelInstance.Actor.uuid) } catch (err) { logger.debug('Cannot update the video channel.', err) @@ -160,11 +163,12 @@ async function removeVideoChannelRetryWrapper (req: express.Request, res: expres async function removeVideoChannel (req: express.Request, res: express.Response) { const videoChannelInstance: VideoChannelModel = res.locals.videoChannel - await sequelizeTypescript.transaction(async t => { + return sequelizeTypescript.transaction(async t => { await videoChannelInstance.destroy({ transaction: t }) + + logger.info('Video channel with name %s and uuid %s deleted.', videoChannelInstance.name, videoChannelInstance.Actor.uuid) }) - logger.info('Video channel with name %s and uuid %s deleted.', videoChannelInstance.name, videoChannelInstance.uuid) } async function getVideoChannel (req: express.Request, res: express.Response, next: express.NextFunction) { diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 91ab8c66a..d6934748f 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -11,7 +11,7 @@ import { resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers' -import { getServerAccount } from '../../../helpers/utils' +import { getServerActor } from '../../../helpers/utils' import { CONFIG, sequelizeTypescript, @@ -22,8 +22,7 @@ import { VIDEO_PRIVACIES } from '../../../initializers' import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServer } from '../../../lib/activitypub' -import { sendAddVideo, sendCreateViewToOrigin, sendUpdateVideo } from '../../../lib/activitypub/send' -import { sendCreateViewToVideoFollowers } from '../../../lib/index' +import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send' import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler' import { asyncMiddleware, @@ -248,7 +247,8 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi // Don't send video to remote servers, it is private if (video.privacy === VideoPrivacy.PRIVATE) return videoCreated - await sendAddVideo(video, t) + await sendCreateVideo(video, t) + // TODO: share by video channel await shareVideoByServer(video, t) logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoCreated.uuid) @@ -304,7 +304,8 @@ async function updateVideo (req: express.Request, res: express.Response) { // Video is not private anymore, send a create action to remote servers if (wasPrivateVideo === true && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE) { - await sendAddVideo(videoInstanceUpdated, t) + await sendCreateVideo(videoInstanceUpdated, t) + // TODO: Send by video channel await shareVideoByServer(videoInstanceUpdated, t) } }) @@ -330,7 +331,7 @@ async function viewVideo (req: express.Request, res: express.Response) { const videoInstance = res.locals.video await videoInstance.increment('views') - const serverAccount = await getServerAccount() + const serverAccount = await getServerActor() if (videoInstance.isOwned()) { await sendCreateViewToVideoFollowers(serverAccount, videoInstance, undefined) -- cgit v1.2.3