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 {
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.get('/:id',
optionalAuthenticate,
- asyncMiddleware(videosGetValidator),
+ asyncMiddleware(videosCustomGetValidator('only-video-with-rights')),
asyncMiddleware(checkVideoFollowConstraints),
- getVideo
+ asyncMiddleware(getVideo)
)
videosRouter.post('/:id/views',
asyncMiddleware(videosGetValidator),
// 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)
- if (videoInstance.isOutdated()) {
- JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', videoUrl: videoInstance.url } })
- .catch(err => logger.error('Cannot create AP refresher job for video %s.', videoInstance.url, { err }))
+ 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(videoInstance.toFormattedDetailsJSON())
+ return res.json(video.toFormattedDetailsJSON())
}
async function viewVideo (req: express.Request, res: express.Response) {
])
const serverActor = await getServerActor()
-
- // Send the event to the origin server
- // If we own the video, we'll send an update event when we'll process the views (in our job queue)
- if (videoInstance.isOwned() === false) {
- await sendCreateView(serverActor, videoInstance, undefined)
- }
+ await sendCreateView(serverActor, videoInstance, undefined)
return res.status(204).end()
}