import { VideoCreate, VideoPrivacy, VideoUpdate } from '../../../../shared'
import { renamePromise } from '../../../helpers/core-utils'
import { retryTransactionWrapper } from '../../../helpers/database-utils'
-import { getVideoFileHeight } from '../../../helpers/ffmpeg-utils'
+import { getVideoFileResolution } from '../../../helpers/ffmpeg-utils'
import { processImage } from '../../../helpers/image-utils'
import { logger } from '../../../helpers/logger'
import { createReqFiles, getFormattedObjects, getServerActor, resetSequelizeInstance } from '../../../helpers/utils'
VIDEO_PRIVACIES
} from '../../../initializers'
import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServerAndChannel } from '../../../lib/activitypub'
-import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send'
+import { sendCreateVideo, sendCreateView, sendUpdateVideo } from '../../../lib/activitypub/send'
import { JobQueue } from '../../../lib/job-queue'
+import { Redis } from '../../../lib/redis'
import {
asyncMiddleware,
authenticate,
commentsEnabled: videoInfo.commentsEnabled,
nsfw: videoInfo.nsfw,
description: videoInfo.description,
+ support: videoInfo.support,
privacy: videoInfo.privacy,
duration: videoPhysicalFile['duration'], // duration was added by a previous middleware
channelId: res.locals.videoChannel.id
const video = new VideoModel(videoData)
video.url = getVideoActivityPubUrl(video)
- const videoFileHeight = await getVideoFileHeight(videoPhysicalFile.path)
+ const { videoFileResolution } = await getVideoFileResolution(videoPhysicalFile.path)
const videoFileData = {
extname: extname(videoPhysicalFile.filename),
- resolution: videoFileHeight,
+ resolution: videoFileResolution,
size: videoPhysicalFile.size
}
const videoFile = new VideoFileModel(videoFileData)
await renamePromise(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
// Process thumbnail or create it from the video
const thumbnailField = req.files['thumbnailfile']
if (videoInfoToUpdate.language !== undefined) videoInstance.set('language', videoInfoToUpdate.language)
if (videoInfoToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfoToUpdate.nsfw)
if (videoInfoToUpdate.privacy !== undefined) videoInstance.set('privacy', parseInt(videoInfoToUpdate.privacy.toString(), 10))
+ 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)
async function viewVideo (req: express.Request, res: express.Response) {
const videoInstance = res.locals.video
+ const ip = req.headers['x-real-ip'] as string || req.ip
+ const exists = await Redis.Instance.isViewExists(ip, videoInstance.uuid)
+ if (exists) {
+ logger.debug('View for ip %s and video %s already exists.', ip, videoInstance.uuid)
+ return res.status(204).end()
+ }
+
await videoInstance.increment('views')
+ await Redis.Instance.setView(ip, videoInstance.uuid)
+
const serverAccount = await getServerActor()
- if (videoInstance.isOwned()) {
- await sendCreateViewToVideoFollowers(serverAccount, videoInstance, undefined)
- } else {
- await sendCreateViewToOrigin(serverAccount, videoInstance, undefined)
- }
+ await sendCreateView(serverAccount, videoInstance, undefined)
return res.status(204).end()
}
}
async function listVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
- const resultList = await VideoModel.listForApi(req.query.start, req.query.count, req.query.sort)
+ const resultList = await VideoModel.listForApi(req.query.start, req.query.count, req.query.sort, req.query.filter)
return res.json(getFormattedObjects(resultList.data, resultList.total))
}