Server: add updatedAt attribute to videos

pull/30/head
Chocobozzz 2016-12-30 11:45:00 +01:00
parent 3d118fb501
commit 79066fdf33
6 changed files with 26 additions and 5 deletions

View File

@ -98,7 +98,8 @@ function addRemoteVideo (videoToCreateData, fromPod, finalCallback) {
description: videoToCreateData.description,
authorId: author.id,
duration: videoToCreateData.duration,
createdAt: videoToCreateData.createdAt
createdAt: videoToCreateData.createdAt,
updatedAt: videoToCreateData.updatedAt
}
const video = db.Video.build(videoData)
@ -190,6 +191,7 @@ function updateRemoteVideo (videoAttributesToUpdate, fromPod, finalCallback) {
videoInstance.set('infoHash', videoAttributesToUpdate.infoHash)
videoInstance.set('duration', videoAttributesToUpdate.duration)
videoInstance.set('createdAt', videoAttributesToUpdate.createdAt)
videoInstance.set('updatedAt', videoAttributesToUpdate.updatedAt)
videoInstance.set('extname', videoAttributesToUpdate.extname)
videoInstance.save(options).asCallback(function (err) {

View File

@ -28,6 +28,7 @@ function isEachRemoteVideosValid (requests) {
isRequestTypeAddValid(request.type) &&
isVideoAuthorValid(video.author) &&
isVideoDateValid(video.createdAt) &&
isVideoDateValid(video.updatedAt) &&
isVideoDescriptionValid(video.description) &&
isVideoDurationValid(video.duration) &&
isVideoInfoHashValid(video.infoHash) &&
@ -40,6 +41,7 @@ function isEachRemoteVideosValid (requests) {
(
isRequestTypeUpdateValid(request.type) &&
isVideoDateValid(video.createdAt) &&
isVideoDateValid(video.updatedAt) &&
isVideoDescriptionValid(video.description) &&
isVideoDurationValid(video.duration) &&
isVideoInfoHashValid(video.infoHash) &&

View File

@ -20,7 +20,6 @@ const customVideosValidators = require('../helpers/custom-validators').videos
// ---------------------------------------------------------------------------
module.exports = function (sequelize, DataTypes) {
// TODO: add indexes on searchable columns
const Video = sequelize.define('Video',
{
id: {
@ -329,7 +328,8 @@ function toFormatedJSON () {
duration: this.duration,
tags: map(this.Tags, 'name'),
thumbnailPath: constants.STATIC_PATHS.THUMBNAILS + '/' + this.getThumbnailName(),
createdAt: this.createdAt
createdAt: this.createdAt,
updatedAt: this.updatedAt
}
return json
@ -356,6 +356,7 @@ function toAddRemoteJSON (callback) {
thumbnailData: thumbnailData.toString('binary'),
tags: map(self.Tags, 'name'),
createdAt: self.createdAt,
updatedAt: self.updatedAt,
extname: self.extname
}
@ -373,6 +374,7 @@ function toUpdateRemoteJSON (callback) {
duration: this.duration,
tags: map(this.Tags, 'name'),
createdAt: this.createdAt,
updatedAt: this.updatedAt,
extname: this.extname
}

View File

@ -105,6 +105,7 @@ describe('Test multiple pods', function () {
expect(video.duration).to.equal(10)
expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ])
expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
expect(video.author).to.equal('root')
if (server.url !== 'http://localhost:9001') {
@ -167,6 +168,7 @@ describe('Test multiple pods', function () {
expect(video.duration).to.equal(5)
expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
expect(video.author).to.equal('root')
if (server.url !== 'http://localhost:9002') {
@ -247,6 +249,7 @@ describe('Test multiple pods', function () {
expect(video1.tags).to.deep.equal([ 'tag1p3' ])
expect(video1.author).to.equal('root')
expect(miscsUtils.dateIsValid(video1.createdAt)).to.be.true
expect(miscsUtils.dateIsValid(video1.updatedAt)).to.be.true
expect(video2.name).to.equal('my super name for pod 3-2')
expect(video2.description).to.equal('my super description for pod 3-2')
@ -256,6 +259,7 @@ describe('Test multiple pods', function () {
expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
expect(video2.author).to.equal('root')
expect(miscsUtils.dateIsValid(video2.createdAt)).to.be.true
expect(miscsUtils.dateIsValid(video2.updatedAt)).to.be.true
if (server.url !== 'http://localhost:9003') {
expect(video1.isLocal).to.be.false
@ -398,6 +402,7 @@ describe('Test multiple pods', function () {
expect(!!videoUpdated).to.be.true
expect(videoUpdated.description).to.equal('my super description updated')
expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
expect(miscsUtils.dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true
callback()
})

View File

@ -83,6 +83,7 @@ describe('Test a single pod', function () {
expect(video.isLocal).to.be.true
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
if (err) throw err
@ -117,6 +118,7 @@ describe('Test a single pod', function () {
expect(video.isLocal).to.be.true
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
if (err) throw err
@ -143,6 +145,7 @@ describe('Test a single pod', function () {
expect(video.isLocal).to.be.true
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
if (err) throw err
@ -170,6 +173,7 @@ describe('Test a single pod', function () {
// expect(video.isLocal).to.be.true
// expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
// expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
// expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
// videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
// if (err) throw err
@ -196,6 +200,7 @@ describe('Test a single pod', function () {
expect(video.isLocal).to.be.true
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
if (err) throw err
@ -522,6 +527,7 @@ describe('Test a single pod', function () {
expect(video.isLocal).to.be.true
expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
done()
})
@ -545,6 +551,7 @@ describe('Test a single pod', function () {
expect(video.isLocal).to.be.true
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
done()
})
@ -569,6 +576,7 @@ describe('Test a single pod', function () {
expect(video.isLocal).to.be.true
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
done()
})

View File

@ -6,12 +6,14 @@ const miscsUtils = {
// ---------------------- Export functions --------------------
function dateIsValid (dateString) {
function dateIsValid (dateString, interval) {
const dateToCheck = new Date(dateString)
const now = new Date()
// Check if the interval is more than 2 minutes
if (now - dateToCheck > 120000) return false
if (!interval) interval = 120000
if (now - dateToCheck > interval) return false
return true
}