diff options
Diffstat (limited to 'server/controllers/api/videos/index.ts')
-rw-r--r-- | server/controllers/api/videos/index.ts | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 101183eab..c9365da08 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -5,6 +5,7 @@ import { renamePromise } from '../../../helpers/core-utils' | |||
5 | import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' | 5 | import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' |
6 | import { processImage } from '../../../helpers/image-utils' | 6 | import { processImage } from '../../../helpers/image-utils' |
7 | import { logger } from '../../../helpers/logger' | 7 | import { logger } from '../../../helpers/logger' |
8 | import { auditLoggerFactory, VideoAuditView } from '../../../helpers/audit-logger' | ||
8 | import { getFormattedObjects, getServerActor, resetSequelizeInstance } from '../../../helpers/utils' | 9 | import { getFormattedObjects, getServerActor, resetSequelizeInstance } from '../../../helpers/utils' |
9 | import { | 10 | import { |
10 | CONFIG, | 11 | CONFIG, |
@@ -53,7 +54,9 @@ import { VideoFilter } from '../../../../shared/models/videos/video-query.type' | |||
53 | import { createReqFiles, buildNSFWFilter } from '../../../helpers/express-utils' | 54 | import { createReqFiles, buildNSFWFilter } from '../../../helpers/express-utils' |
54 | import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' | 55 | import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' |
55 | import { videoCaptionsRouter } from './captions' | 56 | import { videoCaptionsRouter } from './captions' |
57 | import { videoImportsRouter } from './import' | ||
56 | 58 | ||
59 | const auditLogger = auditLoggerFactory('videos') | ||
57 | const videosRouter = express.Router() | 60 | const videosRouter = express.Router() |
58 | 61 | ||
59 | const reqVideoFileAdd = createReqFiles( | 62 | const reqVideoFileAdd = createReqFiles( |
@@ -79,6 +82,7 @@ videosRouter.use('/', blacklistRouter) | |||
79 | videosRouter.use('/', rateVideoRouter) | 82 | videosRouter.use('/', rateVideoRouter) |
80 | videosRouter.use('/', videoCommentRouter) | 83 | videosRouter.use('/', videoCommentRouter) |
81 | videosRouter.use('/', videoCaptionsRouter) | 84 | videosRouter.use('/', videoCaptionsRouter) |
85 | videosRouter.use('/', videoImportsRouter) | ||
82 | 86 | ||
83 | videosRouter.get('/categories', listVideoCategories) | 87 | videosRouter.get('/categories', listVideoCategories) |
84 | videosRouter.get('/licences', listVideoLicences) | 88 | videosRouter.get('/licences', listVideoLicences) |
@@ -158,7 +162,6 @@ async function addVideo (req: express.Request, res: express.Response) { | |||
158 | const videoData = { | 162 | const videoData = { |
159 | name: videoInfo.name, | 163 | name: videoInfo.name, |
160 | remote: false, | 164 | remote: false, |
161 | extname: extname(videoPhysicalFile.filename), | ||
162 | category: videoInfo.category, | 165 | category: videoInfo.category, |
163 | licence: videoInfo.licence, | 166 | licence: videoInfo.licence, |
164 | language: videoInfo.language, | 167 | language: videoInfo.language, |
@@ -247,6 +250,7 @@ async function addVideo (req: express.Request, res: express.Response) { | |||
247 | 250 | ||
248 | await federateVideoIfNeeded(video, true, t) | 251 | await federateVideoIfNeeded(video, true, t) |
249 | 252 | ||
253 | auditLogger.create(res.locals.oauth.token.User.Account.Actor.getIdentifier(), new VideoAuditView(videoCreated.toFormattedDetailsJSON())) | ||
250 | logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoCreated.uuid) | 254 | logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoCreated.uuid) |
251 | 255 | ||
252 | return videoCreated | 256 | return videoCreated |
@@ -273,6 +277,7 @@ async function addVideo (req: express.Request, res: express.Response) { | |||
273 | async function updateVideo (req: express.Request, res: express.Response) { | 277 | async function updateVideo (req: express.Request, res: express.Response) { |
274 | const videoInstance: VideoModel = res.locals.video | 278 | const videoInstance: VideoModel = res.locals.video |
275 | const videoFieldsSave = videoInstance.toJSON() | 279 | const videoFieldsSave = videoInstance.toJSON() |
280 | const oldVideoAuditView = new VideoAuditView(videoInstance.toFormattedDetailsJSON()) | ||
276 | const videoInfoToUpdate: VideoUpdate = req.body | 281 | const videoInfoToUpdate: VideoUpdate = req.body |
277 | const wasPrivateVideo = videoInstance.privacy === VideoPrivacy.PRIVATE | 282 | const wasPrivateVideo = videoInstance.privacy === VideoPrivacy.PRIVATE |
278 | 283 | ||
@@ -344,9 +349,14 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
344 | 349 | ||
345 | const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE | 350 | const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE |
346 | await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t) | 351 | await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t) |
347 | }) | ||
348 | 352 | ||
349 | logger.info('Video with name %s and uuid %s updated.', videoInstance.name, videoInstance.uuid) | 353 | auditLogger.update( |
354 | res.locals.oauth.token.User.Account.Actor.getIdentifier(), | ||
355 | new VideoAuditView(videoInstanceUpdated.toFormattedDetailsJSON()), | ||
356 | oldVideoAuditView | ||
357 | ) | ||
358 | logger.info('Video with name %s and uuid %s updated.', videoInstance.name, videoInstance.uuid) | ||
359 | }) | ||
350 | } catch (err) { | 360 | } catch (err) { |
351 | // Force fields we want to update | 361 | // Force fields we want to update |
352 | // If the transaction is retried, sequelize will think the object has not changed | 362 | // If the transaction is retried, sequelize will think the object has not changed |
@@ -423,6 +433,7 @@ async function removeVideo (req: express.Request, res: express.Response) { | |||
423 | await videoInstance.destroy({ transaction: t }) | 433 | await videoInstance.destroy({ transaction: t }) |
424 | }) | 434 | }) |
425 | 435 | ||
436 | auditLogger.delete(res.locals.oauth.token.User.Account.Actor.getIdentifier(), new VideoAuditView(videoInstance.toFormattedDetailsJSON())) | ||
426 | logger.info('Video with name %s and uuid %s deleted.', videoInstance.name, videoInstance.uuid) | 437 | logger.info('Video with name %s and uuid %s deleted.', videoInstance.name, videoInstance.uuid) |
427 | 438 | ||
428 | return res.type('json').status(204).end() | 439 | return res.type('json').status(204).end() |