X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fvideos%2Fownership.ts;h=88355b289501e3a7434958d4c449511d0a420128;hb=HEAD;hp=a85d7c30b692fdc5f6c4b7ece9e87dbb29f2b7a4;hpb=4024c44f9027a32809931de0692d40d001df721c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/videos/ownership.ts b/server/controllers/api/videos/ownership.ts index a85d7c30b..88355b289 100644 --- a/server/controllers/api/videos/ownership.ts +++ b/server/controllers/api/videos/ownership.ts @@ -1,6 +1,12 @@ -import * as express from 'express' +import express from 'express' +import { MVideoFullLight } from '@server/types/models' +import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' +import { VideoChangeOwnershipStatus, VideoState } from '../../../../shared/models/videos' import { logger } from '../../../helpers/logger' +import { getFormattedObjects } from '../../../helpers/utils' import { sequelizeTypescript } from '../../../initializers/database' +import { sendUpdateVideo } from '../../../lib/activitypub/send' +import { changeVideoChannelShare } from '../../../lib/activitypub/share' import { asyncMiddleware, asyncRetryTransactionMiddleware, @@ -11,15 +17,9 @@ import { videosChangeOwnershipValidator, videosTerminateChangeOwnershipValidator } from '../../../middlewares' +import { VideoModel } from '../../../models/video/video' import { VideoChangeOwnershipModel } from '../../../models/video/video-change-ownership' -import { VideoChangeOwnershipStatus, VideoState } from '../../../../shared/models/videos' import { VideoChannelModel } from '../../../models/video/video-channel' -import { getFormattedObjects } from '../../../helpers/utils' -import { changeVideoChannelShare } from '../../../lib/activitypub/share' -import { sendUpdateVideo } from '../../../lib/activitypub/send' -import { VideoModel } from '../../../models/video/video' -import { MVideoFullLight } from '@server/types/models' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const ownershipVideoRouter = express.Router() @@ -99,15 +99,15 @@ async function listVideoOwnership (req: express.Request, res: express.Response) return res.json(getFormattedObjects(resultList.data, resultList.total)) } -async function acceptOwnership (req: express.Request, res: express.Response) { +function acceptOwnership (req: express.Request, res: express.Response) { return sequelizeTypescript.transaction(async t => { const videoChangeOwnership = res.locals.videoChangeOwnership const channel = res.locals.videoChannel // We need more attributes for federation - const targetVideo = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoChangeOwnership.Video.id) + const targetVideo = await VideoModel.loadFull(videoChangeOwnership.Video.id, t) - const oldVideoChannel = await VideoChannelModel.loadAndPopulateAccount(targetVideo.channelId) + const oldVideoChannel = await VideoChannelModel.loadAndPopulateAccount(targetVideo.channelId, t) targetVideo.channelId = channel.id @@ -122,17 +122,17 @@ async function acceptOwnership (req: express.Request, res: express.Response) { videoChangeOwnership.status = VideoChangeOwnershipStatus.ACCEPTED await videoChangeOwnership.save({ transaction: t }) - return res.sendStatus(HttpStatusCode.NO_CONTENT_204) + return res.status(HttpStatusCode.NO_CONTENT_204).end() }) } -async function refuseOwnership (req: express.Request, res: express.Response) { +function refuseOwnership (req: express.Request, res: express.Response) { return sequelizeTypescript.transaction(async t => { const videoChangeOwnership = res.locals.videoChangeOwnership videoChangeOwnership.status = VideoChangeOwnershipStatus.REFUSED await videoChangeOwnership.save({ transaction: t }) - return res.sendStatus(HttpStatusCode.NO_CONTENT_204) + return res.status(HttpStatusCode.NO_CONTENT_204).end() }) }