ActivityPub-federated video streaming platform using P2P directly in your web browser
Server: add updatedAt attribute to videos
Chocobozzz79066fdf33f7
diff --git a/server/controllers/api/remote.js b/server/controllers/api/remote.jsindex 254ae56d52..a36c31c38c 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.jsindex b76eec1b5b..8448386d94 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.jsindex f51d08f06f..3fe8368c76 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 columnsconst 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.jsindex 6721870682..4442a7ff76 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.trueexpect(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.trueexpect(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.trueexpect(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.trueif (server.url !== 'http://localhost:9003') {expect(video1.isLocal).to.be.false@@ -398,6 +402,7 @@ describe('Test multiple pods', function () {expect(!!videoUpdated).to.be.trueexpect(videoUpdated.description).to.equal('my super description updated')expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ])+ expect(miscsUtils.dateIsValid(videoUpdated.updatedAt, 20000)).to.be.truecallback()})diff --git a/server/tests/api/single-pod.js b/server/tests/api/single-pod.jsindex 57146900de..29512dfc6a 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.trueexpect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true+ expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.truevideosUtils.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.trueexpect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true+ expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.truevideosUtils.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.trueexpect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true+ expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.truevideosUtils.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.trueexpect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true+ expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.truevideosUtils.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.trueexpect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ])expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true+ expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.truedone()})@@ -545,6 +551,7 @@ describe('Test a single pod', function () {expect(video.isLocal).to.be.trueexpect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true+ expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.truedone()})@@ -569,6 +576,7 @@ describe('Test a single pod', function () {expect(video.isLocal).to.be.trueexpect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true+ expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.truedone()})diff --git a/server/tests/utils/miscs.js b/server/tests/utils/miscs.jsindex 4ceff65df5..c4b661496a 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 falsereturn true}