fetchRemoteVideoDescription,
getVideoActivityPubUrl
} from '../../../lib/activitypub'
-import { sendCreateView } from '../../../lib/activitypub/send'
import { JobQueue } from '../../../lib/job-queue'
import { Redis } from '../../../lib/redis'
import {
setDefaultPagination,
setDefaultSort,
videosAddValidator,
+ videosCustomGetValidator,
videosGetValidator,
videosRemoveValidator,
videosSortValidator,
import { move } from 'fs-extra'
import { watchingRouter } from './watching'
import { Notifier } from '../../../lib/notifier'
+import { sendView } from '../../../lib/activitypub/send/send-view'
const auditLogger = auditLoggerFactory('videos')
const videosRouter = express.Router()
)
videosRouter.get('/:id',
optionalAuthenticate,
- asyncMiddleware(videosGetValidator),
+ asyncMiddleware(videosCustomGetValidator('only-video-with-rights')),
asyncMiddleware(checkVideoFollowConstraints),
- getVideo
+ asyncMiddleware(getVideo)
)
videosRouter.post('/:id/views',
asyncMiddleware(videosGetValidator),
licence: videoInfo.licence,
language: videoInfo.language,
commentsEnabled: videoInfo.commentsEnabled || false,
+ downloadEnabled: videoInfo.downloadEnabled || true,
waitTranscoding: videoInfo.waitTranscoding || false,
state: CONFIG.TRANSCODING.ENABLED ? VideoState.TO_TRANSCODE : VideoState.PUBLISHED,
nsfw: videoInfo.nsfw || false,
support: videoInfo.support,
privacy: videoInfo.privacy,
duration: videoPhysicalFile['duration'], // duration was added by a previous middleware
- channelId: res.locals.videoChannel.id
+ channelId: res.locals.videoChannel.id,
+ originallyPublishedAt: videoInfo.originallyPublishedAt
}
const video = new VideoModel(videoData)
video.url = getVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object
}
await federateVideoIfNeeded(video, true, t)
- Notifier.Instance.notifyOnNewVideo(video)
auditLogger.create(getAuditIdFromRes(res), new VideoAuditView(videoCreated.toFormattedDetailsJSON()))
logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoCreated.uuid)
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 = {
}
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)
if (videoInfoToUpdate.support !== undefined) videoInstance.set('support', videoInfoToUpdate.support)
if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description)
if (videoInfoToUpdate.commentsEnabled !== undefined) videoInstance.set('commentsEnabled', videoInfoToUpdate.commentsEnabled)
+ if (videoInfoToUpdate.downloadEnabled !== undefined) videoInstance.set('downloadEnabled', videoInfoToUpdate.downloadEnabled)
+
+ if (videoInfoToUpdate.originallyPublishedAt !== undefined && videoInfoToUpdate.originallyPublishedAt !== null) {
+ videoInstance.set('originallyPublishedAt', videoInfoToUpdate.originallyPublishedAt)
+ }
+
if (videoInfoToUpdate.privacy !== undefined) {
const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10)
videoInstance.set('privacy', newPrivacy)
}
const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE
- await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t)
- if (wasUnlistedVideo || wasPrivateVideo) {
- Notifier.Instance.notifyOnNewVideo(videoInstanceUpdated)
+ // Don't send update if the video was unfederated
+ if (!videoInstanceUpdated.VideoBlacklist || videoInstanceUpdated.VideoBlacklist.unfederated === false) {
+ await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t)
}
auditLogger.update(
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()
- await sendCreateView(serverActor, videoInstance, undefined)
+ await sendView(serverActor, videoInstance, undefined)
return res.status(204).end()
}