]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/controllers/api/videos/index.ts
Better AP route checker
[github/Chocobozzz/PeerTube.git] / server / controllers / api / videos / index.ts
CommitLineData
4d4e5cd4 1import * as express from 'express'
93e1258c 2import { extname, join } from 'path'
2186386c 3import { VideoCreate, VideoPrivacy, VideoState, VideoUpdate } from '../../../../shared'
3a6f351b 4import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils'
ac81d1a0 5import { processImage } from '../../../helpers/image-utils'
da854ddd 6import { logger } from '../../../helpers/logger'
993cef4b 7import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger'
06215f15 8import { getFormattedObjects, getServerActor } from '../../../helpers/utils'
65fcc311 9import {
cef534ed
C
10 CONFIG,
11 MIMETYPES,
ac81d1a0
C
12 PREVIEWS_SIZE,
13 sequelizeTypescript,
14 THUMBNAILS_SIZE,
15 VIDEO_CATEGORIES,
16 VIDEO_LANGUAGES,
17 VIDEO_LICENCES,
3fd3ab2d
C
18 VIDEO_PRIVACIES
19} from '../../../initializers'
0f320037
C
20import {
21 changeVideoChannelShare,
2186386c 22 federateVideoIfNeeded,
0f320037 23 fetchRemoteVideoDescription,
2186386c 24 getVideoActivityPubUrl
0f320037 25} from '../../../lib/activitypub'
94a5ff8a 26import { JobQueue } from '../../../lib/job-queue'
b5c0e955 27import { Redis } from '../../../lib/redis'
65fcc311 28import {
ac81d1a0 29 asyncMiddleware,
90d4bb81 30 asyncRetryTransactionMiddleware,
ac81d1a0 31 authenticate,
8d427346 32 checkVideoFollowConstraints,
d525fc39 33 commonVideosFiltersValidator,
0883b324 34 optionalAuthenticate,
ac81d1a0
C
35 paginationValidator,
36 setDefaultPagination,
37 setDefaultSort,
38 videosAddValidator,
09209296 39 videosCustomGetValidator,
ac81d1a0
C
40 videosGetValidator,
41 videosRemoveValidator,
ac81d1a0
C
42 videosSortValidator,
43 videosUpdateValidator
65fcc311 44} from '../../../middlewares'
3fd3ab2d
C
45import { TagModel } from '../../../models/video/tag'
46import { VideoModel } from '../../../models/video/video'
47import { VideoFileModel } from '../../../models/video/video-file'
65fcc311
C
48import { abuseVideoRouter } from './abuse'
49import { blacklistRouter } from './blacklist'
bf1f6508 50import { videoCommentRouter } from './comment'
571389d4 51import { rateVideoRouter } from './rate'
74d63469 52import { ownershipVideoRouter } from './ownership'
0883b324 53import { VideoFilter } from '../../../../shared/models/videos/video-query.type'
06215f15 54import { buildNSFWFilter, createReqFiles } from '../../../helpers/express-utils'
2baea0c7 55import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update'
40e87e9e 56import { videoCaptionsRouter } from './captions'
fbad87b0 57import { videoImportsRouter } from './import'
06215f15 58import { resetSequelizeInstance } from '../../../helpers/database-utils'
14e2014a 59import { move } from 'fs-extra'
6e46de09 60import { watchingRouter } from './watching'
cef534ed 61import { Notifier } from '../../../lib/notifier'
1e7eb25f 62import { sendView } from '../../../lib/activitypub/send/send-view'
65fcc311 63
80e36cd9 64const auditLogger = auditLoggerFactory('videos')
65fcc311 65const videosRouter = express.Router()
9f10b292 66
ac81d1a0
C
67const reqVideoFileAdd = createReqFiles(
68 [ 'videofile', 'thumbnailfile', 'previewfile' ],
14e2014a 69 Object.assign({}, MIMETYPES.VIDEO.MIMETYPE_EXT, MIMETYPES.IMAGE.MIMETYPE_EXT),
ac81d1a0 70 {
6040f87d
C
71 videofile: CONFIG.STORAGE.TMP_DIR,
72 thumbnailfile: CONFIG.STORAGE.TMP_DIR,
73 previewfile: CONFIG.STORAGE.TMP_DIR
ac81d1a0
C
74 }
75)
76const reqVideoFileUpdate = createReqFiles(
77 [ 'thumbnailfile', 'previewfile' ],
14e2014a 78 MIMETYPES.IMAGE.MIMETYPE_EXT,
ac81d1a0 79 {
6040f87d
C
80 thumbnailfile: CONFIG.STORAGE.TMP_DIR,
81 previewfile: CONFIG.STORAGE.TMP_DIR
ac81d1a0
C
82 }
83)
8c308c2b 84
65fcc311
C
85videosRouter.use('/', abuseVideoRouter)
86videosRouter.use('/', blacklistRouter)
87videosRouter.use('/', rateVideoRouter)
bf1f6508 88videosRouter.use('/', videoCommentRouter)
40e87e9e 89videosRouter.use('/', videoCaptionsRouter)
fbad87b0 90videosRouter.use('/', videoImportsRouter)
74d63469 91videosRouter.use('/', ownershipVideoRouter)
6e46de09 92videosRouter.use('/', watchingRouter)
d33242b0 93
65fcc311
C
94videosRouter.get('/categories', listVideoCategories)
95videosRouter.get('/licences', listVideoLicences)
96videosRouter.get('/languages', listVideoLanguages)
fd45e8f4 97videosRouter.get('/privacies', listVideoPrivacies)
6e07c3de 98
65fcc311
C
99videosRouter.get('/',
100 paginationValidator,
101 videosSortValidator,
1174a847 102 setDefaultSort,
f05a1c30 103 setDefaultPagination,
0883b324 104 optionalAuthenticate,
d525fc39 105 commonVideosFiltersValidator,
eb080476 106 asyncMiddleware(listVideos)
fbf1134e 107)
65fcc311
C
108videosRouter.put('/:id',
109 authenticate,
ac81d1a0 110 reqVideoFileUpdate,
a2431b7d 111 asyncMiddleware(videosUpdateValidator),
90d4bb81 112 asyncRetryTransactionMiddleware(updateVideo)
7b1f49de 113)
e95561cd 114videosRouter.post('/upload',
65fcc311 115 authenticate,
ac81d1a0 116 reqVideoFileAdd,
3fd3ab2d 117 asyncMiddleware(videosAddValidator),
90d4bb81 118 asyncRetryTransactionMiddleware(addVideo)
fbf1134e 119)
9567011b
C
120
121videosRouter.get('/:id/description',
a2431b7d 122 asyncMiddleware(videosGetValidator),
9567011b
C
123 asyncMiddleware(getVideoDescription)
124)
65fcc311 125videosRouter.get('/:id',
6e46de09 126 optionalAuthenticate,
09209296 127 asyncMiddleware(videosCustomGetValidator('only-video-with-rights')),
8d427346 128 asyncMiddleware(checkVideoFollowConstraints),
09209296 129 asyncMiddleware(getVideo)
fbf1134e 130)
1f3e9fec
C
131videosRouter.post('/:id/views',
132 asyncMiddleware(videosGetValidator),
133 asyncMiddleware(viewVideo)
134)
198b205c 135
65fcc311
C
136videosRouter.delete('/:id',
137 authenticate,
a2431b7d 138 asyncMiddleware(videosRemoveValidator),
90d4bb81 139 asyncRetryTransactionMiddleware(removeVideo)
fbf1134e 140)
198b205c 141
9f10b292 142// ---------------------------------------------------------------------------
c45f7f84 143
65fcc311
C
144export {
145 videosRouter
146}
c45f7f84 147
9f10b292 148// ---------------------------------------------------------------------------
c45f7f84 149
556ddc31 150function listVideoCategories (req: express.Request, res: express.Response) {
65fcc311 151 res.json(VIDEO_CATEGORIES)
6e07c3de
C
152}
153
556ddc31 154function listVideoLicences (req: express.Request, res: express.Response) {
65fcc311 155 res.json(VIDEO_LICENCES)
6f0c39e2
C
156}
157
556ddc31 158function listVideoLanguages (req: express.Request, res: express.Response) {
65fcc311 159 res.json(VIDEO_LANGUAGES)
3092476e
C
160}
161
fd45e8f4
C
162function listVideoPrivacies (req: express.Request, res: express.Response) {
163 res.json(VIDEO_PRIVACIES)
164}
165
90d4bb81 166async function addVideo (req: express.Request, res: express.Response) {
8b917537
C
167 // Processing the video could be long
168 // Set timeout to 10 minutes
169 req.setTimeout(1000 * 60 * 10, () => {
170 logger.error('Upload video has timed out.')
171 return res.sendStatus(408)
172 })
173
90d4bb81 174 const videoPhysicalFile = req.files['videofile'][0]
556ddc31 175 const videoInfo: VideoCreate = req.body
9f10b292 176
e11f68a3
C
177 // Prepare data so we don't block the transaction
178 const videoData = {
179 name: videoInfo.name,
180 remote: false,
e11f68a3
C
181 category: videoInfo.category,
182 licence: videoInfo.licence,
183 language: videoInfo.language,
2186386c 184 commentsEnabled: videoInfo.commentsEnabled || false,
7f2cfe3a 185 downloadEnabled: videoInfo.downloadEnabled || true,
2186386c
C
186 waitTranscoding: videoInfo.waitTranscoding || false,
187 state: CONFIG.TRANSCODING.ENABLED ? VideoState.TO_TRANSCODE : VideoState.PUBLISHED,
188 nsfw: videoInfo.nsfw || false,
e11f68a3 189 description: videoInfo.description,
2422c46b 190 support: videoInfo.support,
e11f68a3
C
191 privacy: videoInfo.privacy,
192 duration: videoPhysicalFile['duration'], // duration was added by a previous middleware
1e74f19a 193 channelId: res.locals.videoChannel.id,
194 originallyPublishedAt: videoInfo.originallyPublishedAt
e11f68a3 195 }
3fd3ab2d 196 const video = new VideoModel(videoData)
2186386c 197 video.url = getVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object
eb080476 198
2186386c 199 // Build the file object
056aa7f2 200 const { videoFileResolution } = await getVideoFileResolution(videoPhysicalFile.path)
3a6f351b
C
201 const fps = await getVideoFileFPS(videoPhysicalFile.path)
202
e11f68a3
C
203 const videoFileData = {
204 extname: extname(videoPhysicalFile.filename),
056aa7f2 205 resolution: videoFileResolution,
3a6f351b
C
206 size: videoPhysicalFile.size,
207 fps
e11f68a3 208 }
3fd3ab2d 209 const videoFile = new VideoFileModel(videoFileData)
2186386c
C
210
211 // Move physical file
e11f68a3 212 const videoDir = CONFIG.STORAGE.VIDEOS_DIR
e11f68a3 213 const destination = join(videoDir, video.getVideoFilename(videoFile))
14e2014a 214 await move(videoPhysicalFile.path, destination)
e3a682a8
C
215 // This is important in case if there is another attempt in the retry process
216 videoPhysicalFile.filename = video.getVideoFilename(videoFile)
82815eb6 217 videoPhysicalFile.path = destination
ac81d1a0
C
218
219 // Process thumbnail or create it from the video
220 const thumbnailField = req.files['thumbnailfile']
221 if (thumbnailField) {
222 const thumbnailPhysicalFile = thumbnailField[0]
223 await processImage(thumbnailPhysicalFile, join(CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName()), THUMBNAILS_SIZE)
224 } else {
225 await video.createThumbnail(videoFile)
226 }
93e1258c 227
ac81d1a0
C
228 // Process preview or create it from the video
229 const previewField = req.files['previewfile']
230 if (previewField) {
231 const previewPhysicalFile = previewField[0]
232 await processImage(previewPhysicalFile, join(CONFIG.STORAGE.PREVIEWS_DIR, video.getPreviewName()), PREVIEWS_SIZE)
233 } else {
234 await video.createPreview(videoFile)
235 }
eb080476 236
2186386c 237 // Create the torrent file
ac81d1a0 238 await video.createTorrentAndSetInfoHash(videoFile)
eb080476 239
94a5ff8a 240 const videoCreated = await sequelizeTypescript.transaction(async t => {
e11f68a3 241 const sequelizeOptions = { transaction: t }
eb080476 242
eb080476
C
243 const videoCreated = await video.save(sequelizeOptions)
244 // Do not forget to add video channel information to the created video
245 videoCreated.VideoChannel = res.locals.videoChannel
7920c273 246
eb080476 247 videoFile.videoId = video.id
eb080476 248 await videoFile.save(sequelizeOptions)
e11f68a3
C
249
250 video.VideoFiles = [ videoFile ]
93e1258c 251
2baea0c7 252 // Create tags
2efd32f6 253 if (videoInfo.tags !== undefined) {
3fd3ab2d 254 const tagInstances = await TagModel.findOrCreateTags(videoInfo.tags, t)
eb080476 255
3fd3ab2d 256 await video.$set('Tags', tagInstances, sequelizeOptions)
eb080476
C
257 video.Tags = tagInstances
258 }
259
2baea0c7
C
260 // Schedule an update in the future?
261 if (videoInfo.scheduleUpdate) {
262 await ScheduleVideoUpdateModel.create({
263 videoId: video.id,
264 updateAt: videoInfo.scheduleUpdate.updateAt,
265 privacy: videoInfo.scheduleUpdate.privacy || null
266 }, { transaction: t })
267 }
268
2186386c 269 await federateVideoIfNeeded(video, true, t)
eb080476 270
993cef4b 271 auditLogger.create(getAuditIdFromRes(res), new VideoAuditView(videoCreated.toFormattedDetailsJSON()))
cadb46d8
C
272 logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoCreated.uuid)
273
274 return videoCreated
275 })
94a5ff8a 276
e8d246d5
C
277 Notifier.Instance.notifyOnNewVideo(videoCreated)
278
2186386c 279 if (video.state === VideoState.TO_TRANSCODE) {
94a5ff8a
C
280 // Put uuid because we don't have id auto incremented for now
281 const dataInput = {
0c948c16
C
282 videoUUID: videoCreated.uuid,
283 isNewVideo: true
94a5ff8a
C
284 }
285
286 await JobQueue.Instance.createJob({ type: 'video-file', payload: dataInput })
287 }
288
90d4bb81
C
289 return res.json({
290 video: {
291 id: videoCreated.id,
292 uuid: videoCreated.uuid
293 }
294 }).end()
ed04d94f
C
295}
296
eb080476 297async function updateVideo (req: express.Request, res: express.Response) {
3fd3ab2d 298 const videoInstance: VideoModel = res.locals.video
7f4e7c36 299 const videoFieldsSave = videoInstance.toJSON()
80e36cd9 300 const oldVideoAuditView = new VideoAuditView(videoInstance.toFormattedDetailsJSON())
556ddc31 301 const videoInfoToUpdate: VideoUpdate = req.body
fd45e8f4 302 const wasPrivateVideo = videoInstance.privacy === VideoPrivacy.PRIVATE
cef534ed 303 const wasUnlistedVideo = videoInstance.privacy === VideoPrivacy.UNLISTED
7b1f49de 304
ac81d1a0
C
305 // Process thumbnail or create it from the video
306 if (req.files && req.files['thumbnailfile']) {
307 const thumbnailPhysicalFile = req.files['thumbnailfile'][0]
308 await processImage(thumbnailPhysicalFile, join(CONFIG.STORAGE.THUMBNAILS_DIR, videoInstance.getThumbnailName()), THUMBNAILS_SIZE)
309 }
310
311 // Process preview or create it from the video
312 if (req.files && req.files['previewfile']) {
313 const previewPhysicalFile = req.files['previewfile'][0]
314 await processImage(previewPhysicalFile, join(CONFIG.STORAGE.PREVIEWS_DIR, videoInstance.getPreviewName()), PREVIEWS_SIZE)
315 }
316
eb080476 317 try {
e8d246d5
C
318 const videoInstanceUpdated = await sequelizeTypescript.transaction(async t => {
319 const sequelizeOptions = { transaction: t }
0f320037 320 const oldVideoChannel = videoInstance.VideoChannel
7b1f49de 321
eb080476
C
322 if (videoInfoToUpdate.name !== undefined) videoInstance.set('name', videoInfoToUpdate.name)
323 if (videoInfoToUpdate.category !== undefined) videoInstance.set('category', videoInfoToUpdate.category)
324 if (videoInfoToUpdate.licence !== undefined) videoInstance.set('licence', videoInfoToUpdate.licence)
325 if (videoInfoToUpdate.language !== undefined) videoInstance.set('language', videoInfoToUpdate.language)
326 if (videoInfoToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfoToUpdate.nsfw)
2186386c 327 if (videoInfoToUpdate.waitTranscoding !== undefined) videoInstance.set('waitTranscoding', videoInfoToUpdate.waitTranscoding)
2422c46b 328 if (videoInfoToUpdate.support !== undefined) videoInstance.set('support', videoInfoToUpdate.support)
eb080476 329 if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description)
47564bbe 330 if (videoInfoToUpdate.commentsEnabled !== undefined) videoInstance.set('commentsEnabled', videoInfoToUpdate.commentsEnabled)
7f2cfe3a 331 if (videoInfoToUpdate.downloadEnabled !== undefined) videoInstance.set('downloadEnabled', videoInfoToUpdate.downloadEnabled)
b718fd22
C
332
333 if (videoInfoToUpdate.originallyPublishedAt !== undefined && videoInfoToUpdate.originallyPublishedAt !== null) {
1e74f19a 334 videoInstance.set('originallyPublishedAt', videoInfoToUpdate.originallyPublishedAt)
335 }
336
2922e048
JLB
337 if (videoInfoToUpdate.privacy !== undefined) {
338 const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10)
339 videoInstance.set('privacy', newPrivacy)
340
341 if (wasPrivateVideo === true && newPrivacy !== VideoPrivacy.PRIVATE) {
342 videoInstance.set('publishedAt', new Date())
343 }
344 }
7b1f49de 345
54141398 346 const videoInstanceUpdated = await videoInstance.save(sequelizeOptions)
7b1f49de 347
0f320037 348 // Video tags update?
2efd32f6 349 if (videoInfoToUpdate.tags !== undefined) {
3fd3ab2d 350 const tagInstances = await TagModel.findOrCreateTags(videoInfoToUpdate.tags, t)
7b1f49de 351
0f320037
C
352 await videoInstanceUpdated.$set('Tags', tagInstances, sequelizeOptions)
353 videoInstanceUpdated.Tags = tagInstances
eb080476 354 }
7920c273 355
0f320037
C
356 // Video channel update?
357 if (res.locals.videoChannel && videoInstanceUpdated.channelId !== res.locals.videoChannel.id) {
6200d8d9 358 await videoInstanceUpdated.$set('VideoChannel', res.locals.videoChannel, { transaction: t })
2186386c 359 videoInstanceUpdated.VideoChannel = res.locals.videoChannel
0f320037
C
360
361 if (wasPrivateVideo === false) await changeVideoChannelShare(videoInstanceUpdated, oldVideoChannel, t)
fd45e8f4
C
362 }
363
2baea0c7
C
364 // Schedule an update in the future?
365 if (videoInfoToUpdate.scheduleUpdate) {
366 await ScheduleVideoUpdateModel.upsert({
367 videoId: videoInstanceUpdated.id,
368 updateAt: videoInfoToUpdate.scheduleUpdate.updateAt,
369 privacy: videoInfoToUpdate.scheduleUpdate.privacy || null
370 }, { transaction: t })
e94fc297
C
371 } else if (videoInfoToUpdate.scheduleUpdate === null) {
372 await ScheduleVideoUpdateModel.deleteByVideoId(videoInstanceUpdated.id, t)
2baea0c7
C
373 }
374
2186386c 375 const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE
5abb9fbb
C
376
377 // Don't send update if the video was unfederated
378 if (!videoInstanceUpdated.VideoBlacklist || videoInstanceUpdated.VideoBlacklist.unfederated === false) {
379 await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t)
380 }
6fcd19ba 381
80e36cd9 382 auditLogger.update(
993cef4b 383 getAuditIdFromRes(res),
80e36cd9
AB
384 new VideoAuditView(videoInstanceUpdated.toFormattedDetailsJSON()),
385 oldVideoAuditView
386 )
387 logger.info('Video with name %s and uuid %s updated.', videoInstance.name, videoInstance.uuid)
e8d246d5
C
388
389 return videoInstanceUpdated
80e36cd9 390 })
e8d246d5
C
391
392 if (wasUnlistedVideo || wasPrivateVideo) {
393 Notifier.Instance.notifyOnNewVideo(videoInstanceUpdated)
394 }
eb080476 395 } catch (err) {
6fcd19ba
C
396 // Force fields we want to update
397 // If the transaction is retried, sequelize will think the object has not changed
398 // So it will skip the SQL request, even if the last one was ROLLBACKed!
eb080476 399 resetSequelizeInstance(videoInstance, videoFieldsSave)
6fcd19ba
C
400
401 throw err
eb080476 402 }
90d4bb81
C
403
404 return res.type('json').status(204).end()
9f10b292 405}
8c308c2b 406
09209296
C
407async function getVideo (req: express.Request, res: express.Response) {
408 // We need more attributes
409 const userId: number = res.locals.oauth ? res.locals.oauth.token.User.id : null
410 const video: VideoModel = await VideoModel.loadForGetAPI(res.locals.video.id, undefined, userId)
1f3e9fec 411
09209296
C
412 if (video.isOutdated()) {
413 JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: video.url } })
414 .catch(err => logger.error('Cannot create AP refresher job for video %s.', video.url, { err }))
04b8c3fb
C
415 }
416
09209296 417 return res.json(video.toFormattedDetailsJSON())
1f3e9fec
C
418}
419
420async function viewVideo (req: express.Request, res: express.Response) {
818f7987 421 const videoInstance = res.locals.video
9e167724 422
490b595a 423 const ip = req.ip
0f6acda1 424 const exists = await Redis.Instance.doesVideoIPViewExist(ip, videoInstance.uuid)
b5c0e955
C
425 if (exists) {
426 logger.debug('View for ip %s and video %s already exists.', ip, videoInstance.uuid)
427 return res.status(204).end()
428 }
429
6b616860
C
430 await Promise.all([
431 Redis.Instance.addVideoView(videoInstance.id),
432 Redis.Instance.setIPVideoView(ip, videoInstance.uuid)
433 ])
b5c0e955 434
a2377d15 435 const serverActor = await getServerActor()
1e7eb25f 436 await sendView(serverActor, videoInstance, undefined)
9e167724 437
1f3e9fec 438 return res.status(204).end()
9f10b292 439}
8c308c2b 440
9567011b
C
441async function getVideoDescription (req: express.Request, res: express.Response) {
442 const videoInstance = res.locals.video
443 let description = ''
444
445 if (videoInstance.isOwned()) {
446 description = videoInstance.description
447 } else {
571389d4 448 description = await fetchRemoteVideoDescription(videoInstance)
9567011b
C
449 }
450
451 return res.json({ description })
452}
453
04b8c3fb 454async function listVideos (req: express.Request, res: express.Response) {
48dce1c9
C
455 const resultList = await VideoModel.listForApi({
456 start: req.query.start,
457 count: req.query.count,
458 sort: req.query.sort,
06a05d5f 459 includeLocalVideos: true,
d525fc39
C
460 categoryOneOf: req.query.categoryOneOf,
461 licenceOneOf: req.query.licenceOneOf,
462 languageOneOf: req.query.languageOneOf,
463 tagsOneOf: req.query.tagsOneOf,
464 tagsAllOf: req.query.tagsAllOf,
465 nsfw: buildNSFWFilter(res, req.query.nsfw),
48dce1c9 466 filter: req.query.filter as VideoFilter,
6e46de09 467 withFiles: false,
7ad9b984 468 user: res.locals.oauth ? res.locals.oauth.token.User : undefined
48dce1c9 469 })
eb080476
C
470
471 return res.json(getFormattedObjects(resultList.data, resultList.total))
9f10b292 472}
c45f7f84 473
eb080476 474async function removeVideo (req: express.Request, res: express.Response) {
3fd3ab2d 475 const videoInstance: VideoModel = res.locals.video
91f6f169 476
3fd3ab2d 477 await sequelizeTypescript.transaction(async t => {
eb080476 478 await videoInstance.destroy({ transaction: t })
91f6f169 479 })
eb080476 480
993cef4b 481 auditLogger.delete(getAuditIdFromRes(res), new VideoAuditView(videoInstance.toFormattedDetailsJSON()))
eb080476 482 logger.info('Video with name %s and uuid %s deleted.', videoInstance.name, videoInstance.uuid)
90d4bb81
C
483
484 return res.type('json').status(204).end()
9f10b292 485}