From: Chocobozzz Date: Fri, 30 Dec 2016 10:45:00 +0000 (+0100) Subject: Server: add updatedAt attribute to videos X-Git-Tag: v0.0.1-alpha~574^2~20 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=79066fdf33f79d2d41394f10881e2c226ca26b49;p=oweals%2Fpeertube.git Server: add updatedAt attribute to videos --- diff --git a/server/controllers/api/remote.js b/server/controllers/api/remote.js index 254ae56d5..a36c31c38 100644 --- a/server/controllers/api/remote.js +++ b/server/controllers/api/remote.js @@ -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) { diff --git a/server/helpers/custom-validators/videos.js b/server/helpers/custom-validators/videos.js index b76eec1b5..8448386d9 100644 --- a/server/helpers/custom-validators/videos.js +++ b/server/helpers/custom-validators/videos.js @@ -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) && diff --git a/server/models/video.js b/server/models/video.js index f51d08f06..3fe8368c7 100644 --- a/server/models/video.js +++ b/server/models/video.js @@ -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 } diff --git a/server/tests/api/multiple-pods.js b/server/tests/api/multiple-pods.js index 672187068..4442a7ff7 100644 --- a/server/tests/api/multiple-pods.js +++ b/server/tests/api/multiple-pods.js @@ -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() }) diff --git a/server/tests/api/single-pod.js b/server/tests/api/single-pod.js index 57146900d..29512dfc6 100644 --- a/server/tests/api/single-pod.js +++ b/server/tests/api/single-pod.js @@ -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() }) diff --git a/server/tests/utils/miscs.js b/server/tests/utils/miscs.js index 4ceff65df..c4b661496 100644 --- a/server/tests/utils/miscs.js +++ b/server/tests/utils/miscs.js @@ -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 }