import { getFormattedObjects, getServerActor } from '../../../helpers/utils'
import {
CONFIG,
- IMAGE_MIMETYPE_EXT,
+ MIMETYPES,
PREVIEWS_SIZE,
sequelizeTypescript,
THUMBNAILS_SIZE,
VIDEO_CATEGORIES,
VIDEO_LANGUAGES,
VIDEO_LICENCES,
- VIDEO_MIMETYPE_EXT,
VIDEO_PRIVACIES
} from '../../../initializers'
import {
asyncMiddleware,
asyncRetryTransactionMiddleware,
authenticate,
+ checkVideoFollowConstraints,
commonVideosFiltersValidator,
optionalAuthenticate,
paginationValidator,
setDefaultPagination,
setDefaultSort,
videosAddValidator,
+ videosCustomGetValidator,
videosGetValidator,
videosRemoveValidator,
videosSortValidator,
import { videoCaptionsRouter } from './captions'
import { videoImportsRouter } from './import'
import { resetSequelizeInstance } from '../../../helpers/database-utils'
-import { rename } from 'fs-extra'
+import { move } from 'fs-extra'
+import { watchingRouter } from './watching'
+import { Notifier } from '../../../lib/notifier'
const auditLogger = auditLoggerFactory('videos')
const videosRouter = express.Router()
const reqVideoFileAdd = createReqFiles(
[ 'videofile', 'thumbnailfile', 'previewfile' ],
- Object.assign({}, VIDEO_MIMETYPE_EXT, IMAGE_MIMETYPE_EXT),
+ Object.assign({}, MIMETYPES.VIDEO.MIMETYPE_EXT, MIMETYPES.IMAGE.MIMETYPE_EXT),
{
- videofile: CONFIG.STORAGE.VIDEOS_DIR,
- thumbnailfile: CONFIG.STORAGE.THUMBNAILS_DIR,
- previewfile: CONFIG.STORAGE.PREVIEWS_DIR
+ videofile: CONFIG.STORAGE.TMP_DIR,
+ thumbnailfile: CONFIG.STORAGE.TMP_DIR,
+ previewfile: CONFIG.STORAGE.TMP_DIR
}
)
const reqVideoFileUpdate = createReqFiles(
[ 'thumbnailfile', 'previewfile' ],
- IMAGE_MIMETYPE_EXT,
+ MIMETYPES.IMAGE.MIMETYPE_EXT,
{
- thumbnailfile: CONFIG.STORAGE.THUMBNAILS_DIR,
- previewfile: CONFIG.STORAGE.PREVIEWS_DIR
+ thumbnailfile: CONFIG.STORAGE.TMP_DIR,
+ previewfile: CONFIG.STORAGE.TMP_DIR
}
)
videosRouter.use('/', videoCaptionsRouter)
videosRouter.use('/', videoImportsRouter)
videosRouter.use('/', ownershipVideoRouter)
+videosRouter.use('/', watchingRouter)
videosRouter.get('/categories', listVideoCategories)
videosRouter.get('/licences', listVideoLicences)
asyncMiddleware(getVideoDescription)
)
videosRouter.get('/:id',
- asyncMiddleware(videosGetValidator),
- getVideo
+ optionalAuthenticate,
+ asyncMiddleware(videosCustomGetValidator('only-video-with-rights')),
+ asyncMiddleware(checkVideoFollowConstraints),
+ asyncMiddleware(getVideo)
)
videosRouter.post('/:id/views',
asyncMiddleware(videosGetValidator),
}
async function addVideo (req: express.Request, res: express.Response) {
+ // Processing the video could be long
+ // Set timeout to 10 minutes
+ req.setTimeout(1000 * 60 * 10, () => {
+ logger.error('Upload video has timed out.')
+ return res.sendStatus(408)
+ })
+
const videoPhysicalFile = req.files['videofile'][0]
const videoInfo: VideoCreate = req.body
// Move physical file
const videoDir = CONFIG.STORAGE.VIDEOS_DIR
const destination = join(videoDir, video.getVideoFilename(videoFile))
- await rename(videoPhysicalFile.path, destination)
+ await move(videoPhysicalFile.path, destination)
// This is important in case if there is another attempt in the retry process
videoPhysicalFile.filename = video.getVideoFilename(videoFile)
videoPhysicalFile.path = destination
return videoCreated
})
+ Notifier.Instance.notifyOnNewVideo(videoCreated)
+
if (video.state === VideoState.TO_TRANSCODE) {
// Put uuid because we don't have id auto incremented for now
const dataInput = {
const oldVideoAuditView = new VideoAuditView(videoInstance.toFormattedDetailsJSON())
const videoInfoToUpdate: VideoUpdate = req.body
const wasPrivateVideo = videoInstance.privacy === VideoPrivacy.PRIVATE
+ const wasUnlistedVideo = videoInstance.privacy === VideoPrivacy.UNLISTED
// Process thumbnail or create it from the video
if (req.files && req.files['thumbnailfile']) {
}
try {
- await sequelizeTypescript.transaction(async t => {
- const sequelizeOptions = {
- transaction: t
- }
+ const videoInstanceUpdated = await sequelizeTypescript.transaction(async t => {
+ const sequelizeOptions = { transaction: t }
const oldVideoChannel = videoInstance.VideoChannel
if (videoInfoToUpdate.name !== undefined) videoInstance.set('name', videoInfoToUpdate.name)
}
const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE
- await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t)
+
+ // Don't send update if the video was unfederated
+ if (!videoInstanceUpdated.VideoBlacklist || videoInstanceUpdated.VideoBlacklist.unfederated === false) {
+ await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t)
+ }
auditLogger.update(
getAuditIdFromRes(res),
oldVideoAuditView
)
logger.info('Video with name %s and uuid %s updated.', videoInstance.name, videoInstance.uuid)
+
+ return videoInstanceUpdated
})
+
+ if (wasUnlistedVideo || wasPrivateVideo) {
+ Notifier.Instance.notifyOnNewVideo(videoInstanceUpdated)
+ }
} catch (err) {
// Force fields we want to update
// If the transaction is retried, sequelize will think the object has not changed
return res.type('json').status(204).end()
}
-function getVideo (req: express.Request, res: express.Response) {
- const videoInstance = res.locals.video
+async function getVideo (req: express.Request, res: express.Response) {
+ // We need more attributes
+ const userId: number = res.locals.oauth ? res.locals.oauth.token.User.id : null
+ const video: VideoModel = await VideoModel.loadForGetAPI(res.locals.video.id, undefined, userId)
- return res.json(videoInstance.toFormattedDetailsJSON())
+ if (video.isOutdated()) {
+ JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: video.url } })
+ .catch(err => logger.error('Cannot create AP refresher job for video %s.', video.url, { err }))
+ }
+
+ return res.json(video.toFormattedDetailsJSON())
}
async function viewVideo (req: express.Request, res: express.Response) {
])
const serverActor = await getServerActor()
-
await sendCreateView(serverActor, videoInstance, undefined)
return res.status(204).end()
return res.json({ description })
}
-async function listVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
+async function listVideos (req: express.Request, res: express.Response) {
const resultList = await VideoModel.listForApi({
start: req.query.start,
count: req.query.count,
tagsAllOf: req.query.tagsAllOf,
nsfw: buildNSFWFilter(res, req.query.nsfw),
filter: req.query.filter as VideoFilter,
- withFiles: false
+ withFiles: false,
+ user: res.locals.oauth ? res.locals.oauth.token.User : undefined
})
return res.json(getFormattedObjects(resultList.data, resultList.total))