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